Home Assistant: Automating calendar event creation and running devices when the energy price drops below a certain point

As you may know, I’m using local calendar these days to run specific automations when the electricity price is the cheapest on each day. However, this time I want to heat my outdoor hot tub when ever the electricity price drops below certain point. And for that, I want to use the same local calendar as with the other electricity schedules. (Ps. If you haven’t read the previous article yet, I’d suggest to do that first since this is kind of continuation on that).

In more details, this automation is going to fill the local calendar for the next day with heating schedules to fully heat my hot tub after the electricity prices are received. In fact, I’m just going to play with high / low range of the Balboa spa to toggle between 20°C (low) and 37°C (high) during the cheap hours, but that’s not the main point of this automation.

The biggest change regarding the previous advanced cheapest hours automation is that this time the calendar entries might not be sequential. However, I don’t want to have separate entries of each hour on the calendar either if the prices happens to be sequential. That would cause some odd behaviour of the devices if in the same second the automation triggers off and on again. So I just got to join the sequential entries with each other before actually adding them to calendar.

Hopefully a picture will explain the situation a bit more, so here it goes. In the picture below you can see my heating schedule of the hot tub for today and tomorrow!

Note: This solution might be a bit overkill, since you could just easily check the current price of nord pool sensor and act regarding that state. However, I would like to have a general overview of my electricity schedules through the calendar, so that’s why a bit over-engineering the whole system 🙂

Creating the calendar

Ok, I’m not going to repeat the same things as in previous posts, so you can check out the local calendar creation from previous Advanced Cheapest Hours article 🙂

Installing the package

Pre-requisites for this package to work is to have Nord Pool integration installed. You can look for integration installation guide from the original cheapest hours article or directly from Nord Pool integration GitHub page. Once that is done, continue reading..

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_price_limit: !include cheap_hours_limit_price.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 🙂

Configuring the package

Once the package is in place, it’s only about to configure your own preferences of it.

In this package there are only few configurable entries:

  • price_limit: limit price when to create the calendar entry
  • sensor: your nordpool sensor id
  • grace_period: how long grace time we add if the hour is last of the day. We can’t merge the events between two days so in this case, we want to add a little delay so the off- and on-entries are not triggered at the same time. e.g. the last hour entry would be something like 23:00-23:55.

Those entries can all be found under the first template sensor, just below ‘attributes’!

And one final and most important configuration required: what is being done when the calendar event triggers! Under the automation “id: ‘Energy: Cheap hours schedule entry'” there are couple of #CHANGE-ME tags where you can change your own actions what ever you like to do with the automation!

When these changes are done, the entries should appear to your ‘electricity‘ calendar once the next day prices are published on the Nord Pool integration!

Conclusion

A bit overkill maybe, but I like to keep my schedules under a calendar so I can have a quick look of the upcoming energy schedules! So far this automation has been working a bit more than a week with zero issues, hopefully it will continue that way as well.

I might still need to do some tweaking with the grace period. I could just keep the automation running during the grace period and not to turn off the device if next period starts just after the grace time.

Anyhow, in my opinion, this is a good start to go forward with energy optimisations and maybe the next step could be (finally) to enable non-sequential cheapest hours using relative energy price of each day 🙂


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

17 Replies to “Home Assistant: Automating calendar event creation and running devices when the energy price drops below a certain point”

  1. Hi Toni,
    I´ve been waiting for this automation, I Really wanna thank you for the Advanced integration that right now is controlling my heatfloor, Waterboiler, wash-, dish- and dryer-maschines.
    So great!

    Just one question about this integration and the value “price_limit”, what does it mean? is it CENT (in sweden öre) or what is it for value?

    1. Hi Thomas!

      Thanks for the very nice feedback!

      The price_limit uses the same unit you have configured in the Nord Pool integration. So if in Sweden, you most probably have it as öre or krona.
      Check your current Nord Pool integration price to ensure the proper unit 🙂

      E.g. The current price right now I have (in Finland) is 5.839c/kwh (including 24% VAT), so the price limit would be used as c/kwh (including 24% vat).

  2. Hi Toni,
    Big fan of your work!

    I am using this new “Cheep Hour Energy” to set something up for my father so that he can control his heat pump easily based on spot price.

    I just wanted to ask if it would be possible to change the “price_limit” from a helper of the type “input_number.pris_grans” on the fly from the dashboard?

    I am not comfortable with my father editing yaml files and reloading 😀

    1. Hi Tomas and thanks for the positive feedback! Really appreciate that 🙂

      Most certainly you can set the price limit through input_number as well.. like this:
      price_limit: "{{ states('input_number.test_slider') }}"

      Just remember that if the calendar events are already made for the next day, changing the price_limit won’t update already created events and will become effective the next day.

  3. Hi Toni,
    Your package worked great for couple of days, but today (1st of November) it “refuses” to fill cheap hours to calendar.

    I was wondering could the change of month cause this? Is automation it still working for you today?

    1. Hi!

      Not working today, some issues with Nord Pool integration it seems, since I have not been able to get tomorrow prices through nord pool at all today.

      We’ll have to wait and see if the Nord Pool integration starts working again properly *fingers crossed*..

      1. Thanks for the quick answer, and also for the great package!

        Let’s hope that the Nord Pool integration starts working again soon.

    2. Reloading the Nord Pool seems to have solved me the issue now (about 20minutes ago it did not help, so I guess the Nord Pool API is back in business).

      Ps. I also have an automation reload the Nord Pool at 18:00 every day automatically in case of error situations like this.

      1. You are right, it started to work again.
        (And also that Nord Pool reloading automation every day is a good idea.)

        Thank you again!

  4. Hi Tony
    I am grateful user of your HOME ASSISTANT: ADVANCED NORD POOL CHEAPEST HOURS AUTOMATION WITH LOCAL CALENDAR SUPPORT. It works fine. Now I am highly tempted to implement your new creation to my HA system. Just one question (I am not very bright in codereading) – this is separate automation which uses same Eletricity calendar and must be installed as such or it replaces Cheapest hours automation and contains all it’s functionality?

    1. Hi!

      It does not replace the cheapest hours automation, but uses only the same ‘electricity’ local calendar. So if you have the ‘advanced cheapest hours automation’ already working, you should be good to go with this automation as well.

      e.g. the schedule events from this automation and advanced cheapest hours automation are all marked into the same local calendar.

      1. Hi again
        Can you describe more detailed how I should configure configuration.yaml to have both automations running? Where should I copy code from your page? Or if I download cheap_hours_limit_price.yaml, how to add it to current setup.
        I am running “headless” system.

        at the moment it is :

        homeassistant:
        packages:
        cheapest_hours: !include advanced_cheapest_hours.yaml

        1. Just rename the second cheapest hours defination and you should be good to go. Like this:

          homeassistant:
          packages:
          cheapest_hours: !include advanced_cheapest_hours.yaml
          cheapest_hours_price_limit: !include cheap_hours_limit_price.yaml

  5. Hi Tony
    I desperately need your assistance. Thanks to you, at the moment I am runig two “Cheapest price” automations, based on Nordpool data. But because they are based on market prices not including local additional costs, sometimes it is hard to decide when price is “cheapest”.
    My Nordpool sensor is installed using UI, so I have no way to modify it.
    To move forward, I want to modify my sensor, so it returns prices with additional costs (price we are paying). I am going to add to configuration.yaml these lines, but have no idea if it will work. Can you help me?

    sensors:
    – platform: nordpool
    region: “LT”
    currency: “EUR”
    VAT: True
    precision: 3
    price_in_cents: false
    price_type: kWh

    # Template to specify additional cost to be added to the tariff.
    # The template price is in EUR, DKK, NOK or SEK (not in cents).
    # For example: “{{ current_price * 0.19 + 0.023 | float}}”
    additional_costs: “{% set s = {
    “hourly_fixed_cost”: 0.0175,
    “night_extra”: 0.04719,
    “day_extra”: 0.07865,
    “cert”: -0.00938 }%}
    {% if now().weekday >= 5 %}
    {{ s.night_extra + s.hourly_fixed_cost + s.cert | float }}
    {% else %}
    {% if now().hour >= 7 and now().hour < 23 %}
    {{ s.day_extra + s.hourly_fixed_cost + s.cert | float }}
    {% else %}
    {{ s.night_extra + s.hourly_fixed_cost + s.cert | float }}
    {% endif %}
    {% endif %}"

    1. Hi!

      It looks fine, but unfortunately I’m not using the additional_costs myself at all so can’t be sure if it works.
      To get a better answer I’d suggest to ask this question directly at the Nordpool GitHub page..

      1. ..oh and when moving nordpool from ui to configuration.yaml, remember to remove the old integration from the UI before adding a new one at the configuration.

Leave a Reply

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