Skip to content

Instantly share code, notes, and snippets.

@ArrEssJay
Created June 29, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArrEssJay/e3b78ea73f52d60f94f5829b983e3a18 to your computer and use it in GitHub Desktop.
Save ArrEssJay/e3b78ea73f52d60f94f5829b983e3a18 to your computer and use it in GitHub Desktop.
HA PyScript Load Control
@state_trigger("sensor.scheduled_heating_state", state_check_now=True)
@service
def price_load_control():
"""Turn OFF or ON water heater by price signal (obey overrides)"""
if state.get("input_select.water_heating_mode") == "auto":
scheduled_state = sensor.scheduled_heating_state
log.warning(f"Load control state: {scheduled_state}")
if scheduled_state == '0':
switch.turn_off(entity_id = "switch.storage_heater")
log.warning(f"Load control triggered water heater OFF")
elif scheduled_state == '1':
switch.turn_on(entity_id = "switch.storage_heater")
log.warning(f"Load control triggered water heater ON")
else:
log.error(f"Unknown water heater state {scheduled_state}")
else:
log.warning(f"Load control: Not in auto mode - ignoring request")
pass # Do nothing in other modes
@state_trigger("input_select.water_heating_mode", state_check_now=True)
@service
def water_heating_mode_handler():
"""Water Heater mode handler"""
mode = input_select.water_heating_mode
if mode == "auto":
log.warning(f"Heating Mode - Water heater mode set to AUTO")
price_load_control()
elif mode == "on":
switch.turn_on(entity_id = "switch.storage_heater")
log.warning(f"Heating Mode - Override triggered water heater ON")
elif mode == "off":
switch.turn_off(entity_id = "switch.storage_heater")
log.warning(f"Heating Mode - Override triggered water heater OFF")
else:
log.error(f"Unknown water heater mode {mode}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment