Home Assistant: Advanced Nord Pool Cheapest Hours automation (non-sequential)

I guess there are people that have been waiting for this extension of cheapest hours automation for a while now and it’s finally here: non-sequential version cheapest hours package!

This article is continuation to Home Assistant: Sequential cheapest hours automation so I’d really suggest to read that one first. This article also points to it in couple of sections.

Features of the package

The automation I’m presenting here finds the cheapest hours from Nord Pool sensor and creates local calendar entries on cheapest hours. This Home Assistant package also acts upon cheapest hours calendar events and performs action when cheapest hours event is started. And this is the non-sequential version that can create multiple entries on a day!

Here’s the list this automation package implements (feature list):

  • Calculate number of cheapest hours when Nord Pool spot prices are received
  • Support for two days (today + tomorrow)
  • Rather easy to configure
  • Once prices are received from the Nord Pool, calendar events are created
  • Possible sequential hours are merged with each other
  • Devices(s) will start when ‘cheapest hours’ -calendar event begins
  • Device(s) will stop when ‘cheapest hours’ -calendar event is over
  • If prices are not fetched by 23:15, create a static cheapest hours event (sequential) from configured start time and end after number of hours specified. This will provide us a failsafe that no critical devices are being left out of electricity (e.g. water boiler).

Pre-requisites

This is where I’m going to refer previous cheapest hours articles.

If you have not used the advanced cheapest hours package earlier, you should start by creating a local calendar for Home Assistant and integrating Nord Pool into Home Assistant.

Once these steps are done, continue forward.

Setting up the package

Advanced cheapest hours package can be found from my Cheapest hours GitHub page, so download it and copy it on your Home Assistant ‘config‘ folder.

After copied, find the homeassistant: -block from your configurations.yaml file and add the package include on it. If you don’t have homeassistant: -block, just copy the whole block in any root level of configuration.yaml file:

homeassistant:
  packages:
    cheapest_hours: !include advanced_cheapest_hours_non_sequential.yaml

More details about Home Assistant packages can be found from here. Or if in doubt, leave a comment on the comment field and I’ll try to help you out 🙂

Configuration

As usual in my creations, I’ve added #CHANGE-ME comments to places where you need to configure your own data. In the main template sensor configurations there are following entries that needs configuration:

# Amount of cheapest hours in search
number_of_hours: 4
# Search starting hour
first_hour: 21
# Search ending hour
last_hour: 08
# Is the first_hour today (true / false). If false, first_hour needs to be before last_hour.
starting_today: true
# Nord pool sensor id. Check it ouf from your integrations page!
sensor: sensor.nordpool_kwh_fi_eur_3_10_024 
# If nordpool fetch fails, starting time to make the calendar entry
fail_safe_starting: '00:00' 

Along with the main configuration, there are few several places to make changes in the code. Most of them are ‘sensorId‘ values that should refer to the template sensor defined earlier. No need to change these unless you are actually making multiple separate automations or just want to change the names.

However, there’s one crucial thing to change, the actions what actually need to be done when the cheapest hours starts. So, do what-ever-you-like at this point:

then:
# CHANGE-ME: Actions to do when cheap hour starts
  - service: input_boolean.turn_on
    entity_id: input_boolean.test_switch
else:
# CHANGE-ME: Actions to do when cheap hour ends
  - service: input_boolean.turn_off
    entity_id: input_boolean.test_switch

Creating multiple automations

Ok, so you might want to have multiple automations for different amount of hours or different configurations? At that point, you need to do these steps:

  1. Make a copy the template sensor at the beginning and set unique_id + name to something suitable
  2. Create copy of first automation (cheapest_hours_non_sequential_calendar_trigger) and rename + make proper actions to do what-ever-you-like. Also change the sensorId to refer your newly created template sensor.
  3. Change cheapest_hours_non_sequential_set_sequence automation to contain another sensorId (name as you like) and create another action to call script.cheapest_hours_create_multi_calendar with this new data
  4. Change cheapest_hours_non_sequential_failsafe to contain another sensorId as in previous step and create another failsafe action to call script.cheapest_hours_create_multi_calendar with this new data

That’s it, you should be able to create multiple action by doing those steps. I will be adding an example to the GitHub with multiple entries some rainy day.

What’s coming up next…

One step closer to save energy. However, using configuring multiple entries and automations can be time consuming and so far my cheapest hours automations differs from each others more or less. I’m planning to implement a v2 version of all of these that contain some common code so that those scripts + helpers could be used between each other.

And for more, a web configuration utility is on my TODO list as well. Wouldn’t hold my breath for it soon though, it might take some time to implement a full web app for building these with my spare time.


Did you find this guide helpful? You can keep the blog going by bidding me a coffee!

One Reply to “Home Assistant: Advanced Nord Pool Cheapest Hours automation (non-sequential)”

Leave a Reply

Your email address will not be published. Required fields are marked *