commit 1e995536bb4d2bc0ab9de7b0af08d17abf401df1 Author: Bas Dado Date: Thu May 23 23:32:34 2024 +0200 [WIP] Started working on the boiler control service diff --git a/boilercontrol.py b/boilercontrol.py new file mode 100644 index 0000000..b24386e --- /dev/null +++ b/boilercontrol.py @@ -0,0 +1,28 @@ +import hassapi as hass +import datetime + +# +# Boiler Controller. Tries to optimize when to power (heat up) the boiler with respect to the hourly (dynamic) electricity prices +# +# Args: +# + + +class BoilerControl(hass.Hass): + def initialize(self): + self.log("Initializing boiler control") + + self.boiler_switch = self.args['boiler_switch'] + self.price_sensor = self.args['price_sensor'] + + self.determine_cheapest_hours() + + self.run_daily(self.determine_cheapest_hours, datetime.time(0, 1, 0)) + + def determine_cheapest_hours(self): + + # Get the prices for the current day + prices = self.get_state(self.price_sensor, attribute="raw_today") + + for price in prices: + self.log("Price: " + str(price["value"]) + " at " + datetime.datetime.fromisoformat(price["start"]).strftime("%H:%M")) \ No newline at end of file