Skip to content

Instantly share code, notes, and snippets.

@gpbenton
Created October 4, 2020 17:31
Show Gist options
  • Save gpbenton/a7f8905071cbed99b41698054a6f84f6 to your computer and use it in GitHub Desktop.
Save gpbenton/a7f8905071cbed99b41698054a6f84f6 to your computer and use it in GitHub Desktop.
appdaemon app to control boiler
import hassapi as hass
import datetime
#
# App to represent the boiler. It turns on and off periodically
# at the same times every day.
# Args
# morning_on
# morning_off
# lunchtime_on
# lunchtime_off
# evening_on
# evening_off
#
class Boiler(hass.Hass):
def initialize(self):
try:
morning_on = self.parse_time(self.args["morning_on"])
self.log("Turning on at {}".format(morning_on));
self.run_daily(self.turnCHOn, morning_on,
constrain_input_boolean = "input_boolean.automatic_temperature")
self.run_daily(self.turnHotWaterOn, morning_on)
morning_off = self.parse_time(self.args["morning_off"])
self.log("Turning off at {}".format(morning_off));
self.run_daily(self.turnCHOff, morning_off,
constrain_input_boolean = "input_boolean.automatic_temperature")
self.run_daily(self.turnHotWaterOff, morning_off)
lunchtime_on = self.parse_time(self.args["lunchtime_on"])
self.log("Turning on at {}".format( lunchtime_on ));
self.run_daily(self.turnCHOn, lunchtime_on,
constrain_input_boolean = "input_boolean.automatic_temperature")
lunchtime_off = self.parse_time(self.args["lunchtime_off"])
self.log("Turning off at {}".format( lunchtime_off ));
self.run_daily(self.turnCHOff, lunchtime_off,
constrain_input_boolean = "input_boolean.automatic_temperature")
evening_on = self.parse_time(self.args["evening_on"])
self.log("Turning on at {}".format( evening_on ));
self.run_daily(self.turnCHOn, evening_on,
constrain_input_boolean = "input_boolean.automatic_temperature")
evening_off = self.parse_time(self.args["evening_off"])
self.log("Turning off at {}".format( evening_off ));
self.run_daily(self.turnCHOff, evening_off,
constrain_input_boolean = "input_boolean.automatic_temperature")
except KeyError as e:
self.log("Argument not found : {}".format(e), level="ERROR")
def turnCHOn(self, kwargs):
self.log("Turning CH On")
self.turn_on("switch.central_heating")
def turnCHOff(self, kwargs):
self.log("Turning CH Off")
self.turn_off("switch.central_heating")
def turnHotWaterOn(self, kwargs):
self.log("Turning Hot Water On")
self.turn_on("switch.water_heater")
def turnHotWaterOff(self, kwargs):
self.log("Turning Hot Water Off")
self.turn_off("switch.water_heater")
boiler:
module: boiler
class: Boiler
evening_off: '22:30:00'
evening_on: '17:30:00'
lunchtime_off: '13:15:00'
# lunchtime_off: '17:15:00'
lunchtime_on: '11:45:00'
morning_off: '07:45:00'
# morning_off: '11:45:00'
morning_on: '06:30:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment