Home Assistant: Nord Pool cheapest hours package

In previous post Home Assistant: Nord Pool Spot prices and how to automate devices for cheapest hours I created an automation that uses Nord Pool Spot prices for automations, but the examples were not complete and I got lots of questions how to finalise and/or improve the code to do specific things like setting the end time.

In this post I’m going to tackle the installation issue and give a a full example (using packages) that can be easily copy-pasted to your own environment.

Using the cheapest hours package

Before continuing, please read the original post and setup the Nord Pool integration (and Apex charts if you wish) if you already haven’t!

I’m using packages throughout my whole Home Assistant instance. It groups each functionality to its own files instead of mixed amount with configuration.yaml, automation.yaml, etc.. So, just copy paste the nordpool_cheapest_hours.yaml from my GitHub repository to the Home Assistant config folder and set the following lines in the configuration.yaml:

homeassistant:
  packages:
    nordpool_cheapest_hours: !include nordpool_cheapest_hours.yaml

Of course you should also change the entities and modify the automation for your own purposes. That I cannot ready for you, look out the #CHANGE-ME tags from inside the nordpool_cheapest_hours.yaml

After that just restart your Home Assistant and everything should be ready and cheapest hours automation be running properly!

If in doubt or having issues, feel free to leave a comment!

Tip: you can also move your Nord Pool integration configurations to the package file to keep the configuration.yaml more clear.

11 Replies to “Home Assistant: Nord Pool cheapest hours package”

  1. Perfekt….thanks !
    A question is it possible to connect for an example numberOfSequentialHours to a input_number on a card?
    Thanks again

    1. Yep, easily. Like this:

      # Just a dummy input_number for the testing...
      input_number:
      test_number:
      name: Number of cheapest sequential hours
      initial: 3
      min: 1
      max: 24
      step: 1

      Then just add the value from the number to the template sensor:
      {%- set numberOfSequentialHours = states('input_number.test_number') | int -%}

      1. Hi
        Thanks !
        It also works with helpers.
        Helpers is better because they retain the value, as you mentioned i earlier post
        Thanks

  2. Hi,

    Thaks for the great code. What I have used to start and stop automations, like water boiler, is a template sensor that compares the time to the times that your code have set. With that extra sensor it is easy to start and stop automation by the sensor state.

    template:

    – sensor:
    – name: cheapest sequential 5 hours
    state: >-
    {%set start = state_attr(‘input_datetime.device_start_time’,’hour’) %}
    {% set end = state_attr(‘input_datetime.device_end_time’,’hour’) %}
    {% if now().hour >= start and now().hour < end %}
    True
    {% else %}
    False
    {% endif %}

  3. Hi!
    I am having a problem with this code. But I’m pretty sure i’ve done something wrong, because the device it is currently controlling is neither turning off nor on. Have i done something wrong, and if so then what?

    The code in question:

    # CHANGE-ME: Do anything you like when the start / Stop triggers hit..
    # Start the device for cheapest hours
    – id: ‘1663399614858’
    alias: Turn on device for cheapest hours
    description: ”
    trigger:
    – platform: time
    at: input_datetime.device_start_time
    condition: []
    action:
    – service: input_boolean.turn_on
    entity_id: switch.shelly_shplg_s_4022d882e9b0
    mode: single
    # Stop the device after cheapest hours
    – id: ‘1663399614818’
    alias: Turn off device after cheapest hours
    description: ”
    trigger:
    – platform: time
    at: input_datetime.device_end_time
    condition: []
    action:
    – service: input_boolean.turn_off
    entity_id: switch.shelly_shplg_s_4022d882e9b0
    mode: single

    1. Hi!

      input_boolean.turn_on -> switch.turn_on
      input_boolean.turn_off -> switch.turn_off

      Change those since you are using a switch 🙂

  4. Can someone help me change this package to where it calculates the X most expensive hours instead? I need it to turn off my heat pump during price peaks…

    Thanks alot!

  5. Hi,

    When I load your packages HomeAssistant goes into safe mode.

    This is what I did.
    Added these lines at the end of configuration.yaml

    homeassistant:
    packages:
    nordpool_cheapest_hours: !include nordpool_cheapest_hours.yaml

    Serached and replaced all entries of your sensor-id in nordpool_cheapest_hours.yaml

    CHANGE-ME: change entity to your own sensor in the block below (TWO ENTRIES): sensor.nordpool_kwh_se4_sek_3_10_025

    {%- if state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'tomorrow_valid') == true -%}

    {%- set ns.counter = ns.counter + state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'tomorrow')[j] -%}

    I am pretty sure I did something wrong as I am not a programmer.

    Would appreciate info on what I did wrong.

    Thanks

    1. Could you send me your modified package to creatingsmarthome (at) gmail.com and I will see if I can spot the error?

Leave a Reply

Your email address will not be published.