Home Assistant integration for dynamically controlling air conditioning based on real-time electricity prices from Nordpool.
Functionality has been implemented using a combination of Home Assistant's automation features and its Python Scripts integration. Please follow the steps below to set up the full solution:
-
Clone Repository: Clone this repository to the
python_scripts
directory under your Home Assistant's configuration directory.git clone https://github.com/marko-tuononen/ha-ac-control /path/to/homeassistant/config/python_scripts
-
Define Input Booleans: In your
configuration.yaml
, define input booleans for each hour to represent whether the AC should run during that hour tomorrow. Separate sets for today (cooling_hour_0
tocooling_hour_23
) and tomorrow (cooling_hour_tomorrow_0
tocooling_hour_tomorrow_23
). See example fromexamples/configuration.yaml
. -
Create Automations: Create automations in your
automations.yaml
file. See example fromexamples/automation.yaml
.-
Run the Python Script (cooling_hours.py): Create an automation that runs the Python script at 6 PM every day to prepare the schedule for the next day. The Python script calculates the cooling hours for the next day and updates the corresponding input booleans.
-
Transfer Booleans at Midnight: Create an automation that transfers the input booleans from the next day to the current day around midnight.
-
Control the AC: Create an automation that checks the input booleans each hour to decide whether to turn the AC on or off.
-
This setup ensures that your automation follows the correct input booleans for the appropriate day, allowing for more accurate and timely control of your AC based on electricity prices.
Note! The following dependencies have been used in the examples.
You can run unit tests to ensure the functionality of the Python Script (cooling.hours.py):
python -m unittest