From 1e995536bb4d2bc0ab9de7b0af08d17abf401df1 Mon Sep 17 00:00:00 2001 From: Bas Dado Date: Thu, 23 May 2024 23:32:34 +0200 Subject: [PATCH] [WIP] Started working on the boiler control service --- boilercontrol.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 boilercontrol.py 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