def get_solar_output(): # log_flask("INFO", "Device ID: {}".format(context.System.device.supportedInterfaces.Display)) total_current_solar_production = read_database( "power_solar", "total_current_solar_production") total_current_power_import = read_database("power_solar", "total_current_power_import") screen = has_screen() if screen: solar_pic = 'https://localhost/alexa/solar_output.jpg' msg = render_template('solar_output', solar=total_current_solar_production, power_import=total_current_power_import) return statement(msg).display_render( template='BodyTemplate3', title='Solar Plant Output', background_image_url=solar_pic, text= '<font size="5"><b>Solar Production: {0} Watts<br/>Watts from APS: {1} ' 'Watts</b></font>'.format(total_current_solar_production, total_current_power_import), format='RichText') else: return statement( 'Our solar system is currently producing %s watts ... and we are importing %s watts from A P S' % (total_current_solar_production, total_current_power_import))
def stop_filling_pool(): screen = has_screen() is_pool_filling = read_database("filling_status", "pool_is_filling") if is_pool_filling: gallons_current_fill = read_database("filling_gallons", "gallons_current_fill") pool_fill_total_time = read_database("filling_time", "pool_fill_total_time") msg = render_template('stop_filling', gallons_current_fill=gallons_current_fill, pool_fill_total_time=pool_fill_total_time) pool_fill_valve("ALEXA_CLOSE") if screen: pool_pic = 'https://localhost/alexa/pool_control_2.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_pic, text= '<font size="5"><b>Filling Stopped. We added {} gallons in {} minutes.</b></font>' .format(gallons_current_fill, pool_fill_total_time), format='RichText') else: return statement(msg) else: msg = render_template('pool_not_filling') if screen: pool_pic = 'https://localhost/alexa/pool_control_2.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_pic, text= '<font size="5"><b>Your pool is not currently being filled!</b></font>', format='RichText') else: return statement(msg)
def toggle_email(): email = read_database("notification_methods", "email") if email: update_database("notification_methods", "email", False) else: update_database("notification_methods", "email", True) return redirect(url_for('pool_control'))
def toggle_sms(): sms = read_database("notification_methods", "sms") if sms: update_database("notification_methods", "sms", False) else: update_database("notification_methods", "sms", True) return redirect(url_for('pool_control'))
def toggle_pushbullet(): pushbullet = read_database("notification_methods", "pushbullet") if pushbullet: update_database("notification_methods", "pushbullet", False) else: update_database("notification_methods", "pushbullet", True) return redirect(url_for('pool_control'))
def toggle_debug(): debug = read_database("logging", "console") if debug: update_database("logging", "console", False) else: update_database("logging", "console", True) return redirect(url_for('pool_control'))
def get_pool_temp(): pool_current_temp = read_database("system_status", "pool_current_temp") return statement('Your Pool Temperature is: %s degrees' % pool_current_temp).simple_card( title='Pool Temperature', content='Your pool temperature is %s' % pool_current_temp)
def toggle_reset(): system_reset_required = read_database("reset_status", "system_reset_required") if system_reset_required: update_database("reset_status", "system_reset_required", False) else: update_database("reset_status", "system_reset_required", True) return redirect(url_for('pool_control'))
def manual_fill_button_push(gpio, level, tick): pool_manual_fill = read_database("filling_status", "pool_manual_fill") if not pool_manual_fill: pool_control_master_db.pool_fill_valve("MANUAL_OPEN") update_database("filling_status", "pool_manual_fill", True) else: pool_control_master_db.pool_fill_valve("MANUAL_CLOSE") update_database("filling_status", "pool_manual_fill", False)
def toggle_pool_autofill(): pool_autofill_active = read_database("system_status", "pool_autofill_active") if pool_autofill_active: update_database("system_status", "pool_autofill_active", False) else: update_database("system_status", "pool_autofill_active", True) return redirect(url_for('pool_control'))
def toggle_notifications_pool_database(): pool_database_notifications = read_database("notification_settings", "pool_database_notifications") if pool_database_notifications: update_database("notification_settings", "pool_database_notifications", False) else: update_database("notification_settings", "pool_database_notifications", True) return redirect(url_for('pool_control'))
def get_pool_stats(): pool_current_ph = read_database("pool_chemicals", "pool_current_ph") pool_current_orp = read_database("pool_chemicals", "pool_current_orp") pool_current_temp = int( float(read_database("system_status", "pool_current_temp"))) pool_level_percentage = read_database("pool_level", "pool_level_percentage") total_current_solar_production = read_database( "power_solar", "total_current_solar_production") total_current_power_import = read_database("power_solar", "total_current_power_import") screen = has_screen() msg = render_template('our_stats', temperature=pool_current_temp, ph=pool_current_ph, orp=pool_current_orp, level=pool_level_percentage, solar=total_current_solar_production, power_import=total_current_power_import) if screen: pool_pic = 'https://localhost/alexa/pool_control_2.jpg' return statement(msg).display_render( template='BodyTemplate3', background_image_url=pool_pic, text= '<font size="5"><b>Pool Temperature: {0}{1}F<br/>Pool PH: {2}<br/>Pool ORP: {3}<br/>Water Level: {4}%<br/>Solar Production: {5} Watts<br/>Watts from APS: {6} Watts</b></font>' .format(pool_current_temp, degree_sign, pool_current_ph, pool_current_orp, pool_level_percentage, total_current_solar_production, total_current_power_import), format='RichText') else: return statement(msg)
def get_current_gallons(): screen = has_screen() is_pool_filling = read_database("filling_status", "pool_is_filling") if is_pool_filling: gallons_current_fill = read_database("filling_gallons", "gallons_current_fill") pool_fill_total_time = read_database("filling_time", "pool_fill_total_time") msg = render_template('current_gallons', gallons_current_fill=gallons_current_fill, pool_fill_total_time=pool_fill_total_time) if screen: pool_filling_pic = 'https://localhost/alexa/pool_filling.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_filling_pic, text= '<font size="5"><b>We have added {} gallons over the last {} minutes.</b></font>' .format(gallons_current_fill, pool_fill_total_time), format='RichText') else: return statement(msg) else: gallons_last_fill = read_database("filling_gallons", "gallons_last_fill") msg = render_template('last_gallons', gallons_last_fill=gallons_last_fill) if screen: pool_pic = 'https://localhost/alexa/pool_control_2.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_pic, text= '<font size="5"><b>Pool is not currently filling.<br/> Last fill gallons: {}</b></font>' .format(gallons_last_fill), format='RichText') else: return statement(msg)
def answer(temperature): if isinstance(temperature, int): pool_current_temp = int( float(read_database("system_status", "pool_current_temp"))) if pool_current_temp < temperature: msg = render_template('too_cold', temperature=temperature, pool_current_temp=pool_current_temp) else: msg = render_template('just_right', temperature=temperature, pool_current_temp=pool_current_temp) return statement(msg) else: msg = render_template('unknown') return statement(msg)
def fill_pool(): screen = has_screen() sprinklers_running = get_sprinkler_status() pool_is_filling = read_database("filling_status", "pool_is_filling") if pool_is_filling: msg = render_template('pool_already_filling') if screen: pool_filling_pic = 'https://localhost/alexa/pool_filling.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_filling_pic, text= '<font size="5"><b>You pool is already filling!</b></font>', format='RichText') else: return statement(msg) if sprinklers_running: msg = render_template('sprinklers_running') if screen: sprinkler_pic = 'https://localhost/alexa/sprinklers_running.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=sprinkler_pic, text= '<font size="5"><b>Your sprinklers are Running!</b></font>', format='RichText') else: return statement(msg) else: msg = render_template( 'fill_pool', alexa_max_pool_fill_time=alexa_max_pool_fill_time) pool_fill_valve("ALEXA_OPEN") if screen: pool_filling_pic = 'https://localhost/alexa/pool_filling.jpg' return statement(msg).display_render( template='BodyTemplate6', background_image_url=pool_filling_pic, text= '<font size="5"><b>We will fill your pool for {} minutes!</b></font>' .format(alexa_max_pool_fill_time), format='RichText') else: return statement(msg)
def reset_now(): """Set the "system_reset_required" flag in our database: >>> reset_now() System Reset has been Requested system_reset_required flag is now set! Please restart your system. """ log("INFO", "System Reset Requested via system_reset.py") debug("System Reset has been Requested") system_reset_required = read_database("reset_status", "system_reset_required") if system_reset_required: print( "system_reset_required flag is now set! Please restart your system." ) else: update_database("reset_status", "system_reset_required", True) print( "system_reset_required flag is now set! Please restart your system." ) notify("pool_fill_control_reset_notifications", "System Reset Requested", "A system reset has been requested.")
def get_pool_ph(): pool_current_ph = read_database("pool_chemicals", "pool_current_ph") return statement('Your Pool P H is %s' % pool_current_ph)
def get_pool_orp(): pool_current_orp = read_database("pool_chemicals", "pool_current_orp") return statement('Your Pool Oxygen reduction potential is: %s' % pool_current_orp)
def pool_control(): filter_current_psi = read_database("system_status", "filter_current_psi") pool_current_ph = read_database("pool_chemicals", "pool_current_ph") pool_current_orp = read_database("pool_chemicals", "pool_current_orp") current_pool_watts = read_database("pump_status", "pump_watts") pool_current_temp = read_database("system_status", "pool_current_temp") pool_temp_batt_percentage = read_database("system_status", "pool_temp_batt_percentage") pool_level_batt_percentage = read_database("system_status", "pool_level_batt_percentage") garage_temp_batt_percentage = read_database("system_status", "attic_temp_batt_percentage") attic_temp_batt_percentage = read_database("system_status", "garage_temp_batt_percentage") pool_is_filling = read_database("filling_status", "pool_is_filling") pool_manual_fill = read_database("filling_status", "pool_manual_fill") alexa_manual_fill = read_database("filling_status", "alexa_manual_fill") pool_level_percentage = read_database("pool_level", "pool_level_percentage") pool_level_sensor_ok = read_database("sensor_status", "pool_level_sensor_ok") pool_temp_sensor_ok = read_database("sensor_status", "pool_level_sensor_ok") pool_temp_sensor_humidity = read_database("system_status", "pool_temp_sensor_humidity") acid_level_ok = read_database("acid_level", "acid_level_ok") pump_run_led = read_database("led_status", "pump_run_led") system_run_led = read_database("led_status", "system_run_led") system_error_led = read_database("led_status", "system_error_led") sprinkler_run_led = read_database("led_status", "sprinkler_run_led") current_military_time = read_database("system_status", "current_military_time") pool_fill_total_time = read_database("filling_time", "pool_fill_total_time") debug = read_database("logging", "console") logging = read_logging_config("logging_config", "logging", "LOGGING") pushbullet = read_database("notification_methods", "pushbullet") email = read_database("notification_methods", "email") gallons_current_fill = read_database("filling_gallons", "gallons_current_fill") gallons_last_fill = read_database("filling_gallons", "gallons_last_fill") total_system_gallons = read_database("filling_gallons", "gallons_stop") pump_gpm = read_database("pump_status", "pump_gpm") pump_rpm = read_database("pump_status", "pump_rpm") pump_control_active = read_database("pump_status", "pump_control_active") sms = read_database("notification_methods", "sms") total_current_power_utilization = read_database( "power_solar", "total_current_power_utilization") total_current_power_import = read_database("power_solar", "total_current_power_import") total_current_solar_production = read_database( "power_solar", "total_current_solar_production") pump_program_running = read_database("pump_status", "pump_program_running") pump_control_notifications = read_database("notification_settings", "pump_control_notifications") pump_control_software_notifications = read_database( "notification_settings", "pump_control_software_notifications") pool_fill_notifications = read_database("notification_settings", "pool_fill_notifications") pool_level_sensor_notifications = read_database( "notification_settings", "pool_level_sensor_notifications") pool_temp_sensor_notifications = read_database( "notification_settings", "pool_temp_sensor_notifications") pool_filter_psi_notifications = read_database( "notification_settings", "pool_filter_psi_notifications") pool_acid_level_notifications = read_database( "notification_settings", "pool_acid_level_notifications") pool_fill_control_reset_notifications = read_database( "notification_settings", "pool_fill_control_reset_notifications") pool_database_notifications = read_database("notification_settings", "pool_database_notifications") pool_autofill_active = read_database("system_status", "pool_autofill_active") pool_pump_error_notifications = read_database("notification_settings", "pump_error_notifications") system_reset_required = read_database("reset_status", "system_reset_required") pool_level_sensor_humidity = read_database("system_status", "pool_level_sensor_humidity") pool_last_fill_date = pool_control_master_db.get_last_fill_date() return render_template( "index_db.html", current_pool_watts=current_pool_watts, filter_current_psi=filter_current_psi, pool_current_temp=pool_current_temp, pool_current_ph=pool_current_ph, pool_current_orp=pool_current_orp, pool_temp_batt_percentage=pool_temp_batt_percentage, garage_temp_batt_percentage=garage_temp_batt_percentage, attic_temp_batt_percentage=attic_temp_batt_percentage, pool_temp_sensor_humidity=pool_temp_sensor_humidity, pool_is_filling=pool_is_filling, pool_manual_fill=pool_manual_fill, pool_level_percentage=pool_level_percentage, acid_level_ok=acid_level_ok, pump_run_led=pump_run_led, system_run_led=system_run_led, system_error_led=system_error_led, sprinkler_run_led=sprinkler_run_led, current_military_time=current_military_time, pool_fill_total_time=pool_fill_total_time, debug=debug, logging=logging, pushbullet=pushbullet, email=email, sms=sms, gallons_current_fill=gallons_current_fill, gallons_last_fill=gallons_last_fill, total_system_gallons=total_system_gallons, pump_gpm=pump_gpm, pump_rpm=pump_rpm, pump_control_active=pump_control_active, total_current_solar_production=total_current_solar_production, total_current_power_import=total_current_power_import, total_current_power_utilization=total_current_power_utilization, pump_program_running=pump_program_running, pump_control_notifications=pump_control_notifications, pump_control_software_notifications=pump_control_software_notifications, pool_fill_notifications=pool_fill_notifications, pool_level_sensor_notifications=pool_level_sensor_notifications, pool_temp_sensor_notifications=pool_temp_sensor_notifications, pool_filter_psi_notifications=pool_filter_psi_notifications, pool_acid_level_notifications=pool_acid_level_notifications, pool_fill_control_reset_notifications= pool_fill_control_reset_notifications, pool_pump_error_notifications=pool_pump_error_notifications, pool_database_notifications=pool_database_notifications, pool_autofill_active=pool_autofill_active, system_reset_required=system_reset_required, alexa_manual_fill=alexa_manual_fill, pool_last_fill_date=pool_last_fill_date, pool_level_sensor_ok=pool_level_sensor_ok, pool_temp_sensor_ok=pool_temp_sensor_ok, pool_level_sensor_humidity=pool_level_sensor_humidity, pool_level_batt_percentage=pool_level_batt_percentage)
def get_pool_level(): pool_level_percentage = read_database("pool_level", "pool_level_percentage") return statement('Your Pool water level is %s percent' % pool_level_percentage)