Home Assistant: Nord Pool cheapest hours with AIO Energy Management

I’ve already done couple of iterations of finding Nord Pool cheapest hours every day using Home Assistant templated sensors and bunch of helpers and automations. It can really get complicated when using multiple sensors and copy-pasting the automations. Not to even mention about changes in the code for updates! But, the help is now here: I’ve done a huge revamp of the cheapest hours system and everything is now much easier to configure and maintain. Behold the AIO Energy Management integration!

But, before continuing let’s go back a bit.. During early summer I started finding a way for my solar energy to be used along with Nord Pool. Trying to decide when to use solar and when to use grid energy. Things got really out of hands and the automation came out as a mess. Then it hit me: I’ll write a Home Assistant custom component as an integration, so I can write everything with Python and re-use code without making tons of copy-pasting from an automation to another. The work is now done for the Nord Pool part, but solar management is still to be implemented. Now it’s a good time to make the first MVP release..

What is AIO Energy Management?

AIO Energy Management is a custom component for Home Assistant that currently supports finding cheapest or most expensive hours for energy using Nord Pool prices, so mostly targeted for nordic European people using Home Assistant! It’s meant to replace my old creation of cheapest hours and cheapest hours with calendar.

Why it’s called All-In-One Energy Management, if it’s just using Nord Pool you might ask? Well, this integration is planned to become a solution handling all my energy management needs including solar power and later also include other regions of electric stock market*. A long way to go for actually becoming AIO solution, but hopefully I’ll get there someday..

*Need to support for your regions electric stock market? Write an issue to my GitHub repository or write a comment below and lets see what can be done..

Setting up the integration

Definitely the best way to install AIO Energy Management is to use HACS. Using HACS will provide you automatic installation and providing updates. On updates your job is only to check for possibly breaking changes and press the update button.

To install using HACS either press ‘Open HACS repository on Home Assistant‘ -button below or manually setup the custom repository.

Automatic setup:

Manual Setup:

  • Go to `HACS` -> `Integrations`
  • Select `` from upper right corner
  • Select `Custom repositories`
  • Add `https://github.com/kotope/aio_energy_management` and select Category as `Integration`
  • Search for `AIO Energy Management` and select it
  • Press `Download`
  • Restart Home Assistant

Using Nord Pool cheapest hours binary sensor

The first released component of AIO Energy Management is the Nord Pool cheapest hours sensor. This sensor will provide a binary_sensor type that will turn ‘on’ when the cheapest hour is active and ‘off’ when not making it easy for automations to make proper device actions (see ‘automations’ section for more details).

To use the Nord Pool cheapest hours binary sensor, a Nord Pool integration must be installed and configured first. To do that, check installation instruction from the Nord Pool integration GitHub.

The cheapest hours configuration has all the same features as earlier version of the automation: finding number of hours from a specified time frame, getting the expensive hours and of course a failsafe functionality in case of data fetch failure.

All the configuration is done through configuration.yaml and no config flow is supported at the moment. The table shown below presents all the configuration parameters to make the cheapest hours sensor to suit best for your needs!

configurationmandatorydescription
nordpool_entityyesEntity id of the nord pool integration sensor. Look this from your nord pool integration!
unique_idyesUnique id of this entity
nameyesFriendly name of the sensor. Is the one shown on UI and marked on energy management calendar if in use.
number_of_hoursyesNumber of cheapest hours to seek. This can either be a number between 24-1 or dynamic entity_id. If entity_id is given, the value will be read from that entity when locking in the next cheapest hours sequences.
first_houryesStarting hour (0-23)
last_houryesEnding hour (0-23)
starting_todayyesTrue if the look up should be started on today. Note that if set to true, the starting hour must be after nord pool price publish (about 14.00 CET).
False if only tomorrow prices should be looked for.
sequentialyesTrue if required to find sequential cheapest hours. False if multiple slots are ok.
failsafe_starting_hournoFailsafe starting if nord pool price data can’t be received by external reason.
Setting for example to 22, the binary_sensor value will be set as ‘on’ at 22.00 if no electric prices are received by that time.
inversednoWant to find the most expensive hours? Set to true!
Configuration parameters of AIO Energy Management Nord Pool cheapest hours sensor

Ok, the parameters are now introduced.. here’s a full example that can be set into configuration.yaml. The following example has two sensors: one for cheapest and one for most expensive hours. Note that the example of expensive hours uses a helper input_number entity to get dynamic number of hours to seek.

aio_energy_management:
  cheapest_hours:
    - nordpool_entity: sensor.nordpool
      unique_id: my_cheapest_hours_sensor
      name: My Cheapest Hours
      first_hour: 21
      last_hour: 12
      starting_today: true
      number_of_hours: 3
      sequential: False
      failsafe_starting_hour: 22
    - nordpool_entity: sensor.nordpool
      unique_id: my_expensive_hours_sensor
      name: My Expensive Hours
      first_hour: 20
      last_hour: 16
      starting_today: true
      number_of_hours: 2
      sequential: False
      inversed: true

Once the configuration is in place, just restart your Home Assistant and enjoy the newly created sensor(s)! The sensors can be easily found from settings -> devices & services -> entity -tab. Just look for ‘AIO Energy Management‘ integration 🙂

AIO Energy Management Calendar

AIO Energy Management can create you a calendar to present all upcoming energy management events, like upcoming cheapest hours or expensive hours slot. The calendar is purely optional, but it can be used to trigger an automation as in with my old template/helper/automation based implementation.

To configure calendar to be used, just setup ‘calendar’ slot in the ‘aio_energy_management’ configuration section and add ‘unique_id’ and ‘name’ as parameters. Everything else is done automatically, just enable and restart Home Assistant!

Once restarted, go to Home Assistant -> Calendar and you should see a newly created calendar with the name you gave during configuration!

Example configuration below:

aio_energy_management:
    calendar:
      name: My Energy Management Calendar
      unique_id: my_energy_management_calendar

NOTE: Cheapest hours sensor failsafe is not marked on the calendar!

Automations

Then the most interesting one, how can I do the automations based on the cheapest hours? Well, it’s almost too easy with AIO Energy Management Cheapest Hours component: just set the automation to follow ‘on‘ and ‘off‘ states of the binary_sensor!

Here’s an example aution of using triggers ids to check for ‘on’ and ‘off’ states of the binary_sensor to toggle dummy input_boolean helper. This way everything can just use a single automation! Of course it’s possible to create one for ‘on‘ and one for ‘off‘ states, it’s up to you really which way you prefer, just follow the binary_sensor status 🙂

alias: Cheapest hours turn on switch
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.my_cheapest_hours
    from: "off"
    to: "on"
    id: turn_on
  - platform: state
    entity_id:
      - binary_sensor.my_cheapest_hours
    from: "on"
    to: "off"
    id: turn_off
condition: []
action:
  - if:
      - condition: trigger
        id:
          - turn_on
    then:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.test_toggle
    else:
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.test_toggle
mode: single

Technical details of cheapest hours sensor

If you have no interest about internal and advanced functionality you can just skip this section. But if you want to make some more complicated automations on some specific occasions, you might find this information useful.

The logic of Nord Pool cheapest hours is quite simple: As soon as the Nord Pool data is received from Nord Pool sensor, the data is stored into Home Assistant. The sensor attributes described below might come handy:

Expiration: The data stored contains expiration time that will tell us when we are ready to get new Nord Pool data as we don’t want to make the decision if already on a cheapest hours. The expiration is set just after last_hour.

Updated_at: This value is being set as the time we got the data from Nord Pool. This attribute can be followed on an automation, if we want to trigger some actions when the cheapest hours list is ready.

Failsafe_active: This value will be set to true when we are running on failsafe. Failsafe will be run at given failsafe_starting_hour, if the data expiration has been passed and no new Nord Pool data has been received, Might be useful if we want to do something different when on failsafe..

Active_number_of_hours: this presents the actual value used to get amount of hours. Is either the same value as set on number_of_hours or received from entity if entity_id is used on configuration. This is updated right after data is received from the nord pool sensor and values are calculated! Entity value changes afrer calculations won’t change this!

List: Actual list data of cheapest hours! Might become useful if you want to export the cheapest hours to some external device itself rather than letting Home Assistant to control it.

What next…

Cheapest and expensive hours is now up and running with a failsafe support! However, the work continues. There’s a lot to be done for the cheapest hours implementation and especially with all the other features like solar energy calculations!

Here’s few things you might be seeing in very near future:

  • Trigger time.. if you want to wait for some other input before locking in the cheapest hours. Currently the cheapest hours slot is locked as soon as the energy prices are published by Nord Pool!
  • Multi state sensor. Want to avoid high prices and prioritise the low prices? A sensor with ‘low’, ‘normal’ and ‘high’ should do the trick
  • Use of solar forecast integration to make entries of the best solar hours!

And in a long run .. mixing up solar forecast and Nord Pool cheapest hours to get the best out of all!

Anything else? Need a support for another electric stock market or other new fancy feature? GitHub contributions are always welcome and please leave a comment below if you are looking for something specific!


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

23 Replies to “Home Assistant: Nord Pool cheapest hours with AIO Energy Management”

    1. Hi!

      But you can see the correct calendar?
      Does your binary_sensor attributes contain ‘list’-attribute with values?

      You could also enable debug logging by adding following line(s) to the configuration.yaml to see what’s going on:
      logger:
      default: warning
      logs:
      custom_components.aio_energy_management: debug

      1. Hi!
        I do have the calendar (literally copy-pasted all your settings). I have the “My Energy Management” calendar and I also have one of your previous blog posts, the “electricity” calendar. I also have the “Cheapest hours energy” under the “electricity” calendar, not in “My Energy Management” calendar, which does not make sense to me but ok. In Settings > services > entities I have the My Cheapest Hours (binary_sensor.my_cheapest_hours) and the My Expensive Hours (binary_sensor.my_expensive_hours) BUT they have a mark of red circle and “not provided” status. Does this all make sense?

        Also, couldnt run debugger, said Failed to restart Home Assistant
        Invalid domain custom_components.aio_energy_management, but I just downloaded and reinstalled it, did everything from top to bottom in this blog post.

        Thank you for your effort in resolving it 🙂

        1. Hi!

          Just realised that maybe the guide is not 100% clear on the configuration part. calendar and cheapest_hours sensors need to both be in the same block under aio_energy_management and there should not be aio_energy_management component defined twice. Could this be the case on your issue?

          Here’s an example of the config I’m using myself.
          aio_energy_management:
          calendar:
          unique_id: energy_management_calendar
          name: Energy Management Calendar
          cheapest_hours:
          - nordpool_entity: sensor.nordpool_kwh_fi_eur_3_10_024
          unique_id: my_cheapest_hours
          name: My Cheapest Hours
          first_hour: 21
          last_hour: 12
          starting_today: true
          number_of_hours: 3
          sequential: false
          failsafe_starting_hour: 1
          - nordpool_entity: sensor.nordpool_kwh_fi_eur_3_10_024
          unique_id: my_expensive_hours
          name: Expensive Hours
          first_hour: 0
          last_hour: 22
          starting_today: false
          number_of_hours: 2
          sequential: false
          failsafe_starting_hour: 1
          inversed: true

          If you wish, you could send me your configuration.yaml to creatingsmarthome (at) gmail.com and I’ll have a look. 🙂

  1. Nice work! Im going to try out this one. Is there a possibility to add multiple time ranges in to on sensor? like 00-06 and 12-18 and seek one hour in both ranges?

    And does the upcoming 15min market effect on to this? Would love to see adjustable span to optimize heat pumps etc for enought long periods to heat up dhw ie.

    1. Yes it’s possible to add another time range of course, just add another entity into configuration like the expensive hours in the example.

      15min market is still quite far away, but of course when it’s released from Nord pool this will support it at the time. Would be a breaking change though 🙂

      1. Yeah I did it that way but all automation requires both entities now. Testing out it with DHW currently which only requires two cycles in a day.

        Does the automation fetch all hours after reciving new spot prices from Nord pool or before first hour?

        1. This integration (aio energy management) calculates all data as soon as Nord pool prices have been fetched.
          Only exception is if the last_hour is set after price publishing. In that case, the new prices will be calculated once last_hour has passed. Called “expiration” in attributes.

          I’m currently improving the functionality by adding an optional ‘trigger_time’ so you can specify a time after the prices should be calculated. This feature is not yet ready though.

          1. Oh I see. I think thats why it didnt work on the first cycle. Additional trigger time or even a force button would be nice if you upgrade the sensors itll require full cycle before it starts to work.

  2. Hello,
    First – thanks 🙂

    I have installed everything and it works – but I cannot see the “my_expensive_hours” – sensor under entities.
    I only have the cheapest_hour -sensor.
    Not sure what you mean with “Note that the example of expensive hours uses a helper input_number entity to get dynamic number of hours to seek.”
    Do I need to create that helper for it to work?

    I have used your configuration examples in configuration.

    1. Hi!

      You can also add integer value instead of an entity. Similar to cheapest hours example (number_of_hours: 3)
      If you wish to use dynamic value from a helper, you need to create that helper yourself of course.

    1. Hi!

      I’ve checked that out briefly, but it feels quite complicated.
      Though eventually my integration could end up to be as complex as well, since the logic is not straight forward in all the cases.. but let see 😀

  3. Hello Toni, thanks for the good explanation. It is working fine for me now. In my calendar i see the cheapest and expensive hours. It is just not clear to me how i can set my waterboiler to make use of this so that it can heat at the cheapest hour.

    1. Hi!

      You should just turn on the waterheater when cheapest hours binary_sensor changes it state to ‘on’ and vice versa.

      Create a new automation and the example configuration below that controls the input_boolean.
      I guess you have a switch entity to control the water heater so change your data to match the example 🙂

      AIO Energy Management cheapest hours example action

      Let me know if you need more help. You can also mail me at creatingsmarthome (at) gmail.com.

  4. I used your scripts before but this seems much better, but cannot get it to work.

    Im apparently doing something wrong. But I only copied your config and changed to another nordpool entity (swedish kronor). And get this error.

    Any idea what could be wrong?

    2024-08-28 20:29:29.985 DEBUG (MainThread) [custom_components.aio_energy_management.coordinator] Query data from store for my_cheapest_hours
    2024-08-28 20:29:29.985 DEBUG (MainThread) [custom_components.aio_energy_management.nordpool_binary_sensor] No stored value found for my_cheapest_hours or value is expired. Request new data from nord pool integration
    2024-08-28 20:29:29.986 ERROR (MainThread) [custom_components.aio_energy_management.math] Invalid configuration for non-sequential cheapest hours sensor
    2024-08-28 20:29:29.986 DEBUG (MainThread) [custom_components.aio_energy_management.nordpool_binary_sensor] No valid data found. Check failsafe

    1. Hi Joel!

      If you’ve copied the example as is, you should define helper for input_number.my_input_number used on my_expensive_hours.
      The example uses dynamic hours for this specific entity 🙂

      You can replace input_number.my_input_number with some static number as well.

      If you still have problem after this change, you can mail your configuration me to creatingsmarthome (at) gmail.com and I canhave a look if there’s something odd in there

  5. at what time does the new nordpool data comes in? after Expiration ie 21 if thats my last hour?

    1. Hi!

      Yes, current versio fills new data after expiration, if Nord pool data is available. If not available yet, then right after data is published.

      Next version will have the new data set as soon as it is published.

Leave a Reply

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