Calculate the highest energyprice/day in automation

Hi all.
I am new to HA yaml coding and cant understand to solve this. I thought is was easy but after 3 days i give up.
I use the Nordpool dayly energy prices integration where every hours price are updated, sensor.nordpool_kwh_se3_sek_1_10_025. I can se it and it changes every hour so no problem.

I want to control a switch that turn on my boiler every time the price is lower than 100.
I found different examples that i tried but cant get it to work. This is my automation.

alias: "NordPool get electricity hourly price"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.nordpool_kwh_se3_sek_1_10_025
condition:
  - condition: template
    value_template: >-
      {{ states('nordpool_kwh_se3_sek_1_10_025') | float ==
      state_attr('nordpool_kwh_se3_sek_1_10_025', '<100') | float }}
action:
  - type: turn_on
    device_id: a29e9a6f797a46f38604728dab121a17
    entity_id: switch.switch_boiler
    domain: switch
mode: single

Screenshot 2023-01-14 at 00.41.03|601x499

alias: "Boiler on when price low"
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.nordpool_kwh_se3_sek_1_10_025
    below: 100
action:
  - service: switch.turn_on
    target:
      entity_id: switch.switch_boiler
mode: single

How do you want to automate turning it off?

it can be as simple as turning it off if the price goes above 100, and/or you can turn it off after being on for a certain time.

Also what do you want to happen if the price does not go below 100 Sek?

Thanks a lot.
Is it that simple?
So now i made my automation as you suggested, whats gonna happend now? So far nothing.
I asume that the trigger only react to a change frome the sensor so i have to wait until sensor.nordpool_kwh_se3_sek_1_10_025 thange the value, is that correct?

I have been doing some C++ som years ago so Yaml is quite different, the indent in yaml is my biggest enemy at the moment.

Best regards an thank you for helping me.
Ole

The sensor must change from above 100 to below 100. You can add more triggers if the sensor is already below 100 when you reload the automaton or if it went below 100 while you were restarting home assistant.

alias: "Boiler on when price low"
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.nordpool_kwh_se3_sek_1_10_025
    below: 100
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: numeric_state # for the home assistant start and automation reload triggers
    entity_id: sensor.nordpool_kwh_se3_sek_1_10_025
    below: 100
action:
  - service: switch.turn_on
    target:
      entity_id: switch.switch_boiler
mode: single

Don’t forget my other questions though.

1 Like

I am not shure what i will do whith the integration actually. I have 20.000 sqaremeters land with 5 buildings. A 10.6 kw solar system and a 2kw windmill and a lot of electric things.
Today i have a fixed price for electric. I pay about 1SEK/kw when i buy and i got 2SEK when i sell.

So i am trying to sell as much as i can when i produce from sun and wind and try use as few watts as possible during that time. In the evening when the sun goes down and there is no wind you can say i buy my own electricity for half the price. so its a really good deal for now.

So far it has been sucsessfull today i mainly controll it with some arduinos and i has not get any electric bill for 3 years. Arduino is hard to integrate in HA so now i ongoing switching to ESP32 sensors with integratet Wifi.

So far so good by in May i have to renew my accout at Telgeenergi the Electric company and i suppose they dont give me the same 3 year deal. So i will try to balance the electric consumpion in the moste effective way no matter of the agreement i get from the Electric company. But i asume i got a freerunning price as many other.

Your question abourt how to control with automation, sensor, on/off, price etc. i dont know yet. Lets say boiler can be switched on off easily, but dishwasher, washingmachine and some other equipment can not, they have to run their ful time. So at the moment i making a scedule and priority list so i can do automation from that base.

Aha…
So if i restart HA the it will trigger the Automation?

Why do i need a condition, what do it do?

condition:

  • condition: numeric_state # for the home assistant start and automation reload triggers
    entity_id: sensor.nordpool_kwh_se3_sek_1_10_025
    below: 100

In case the automation was triggered by the restart or reload triggers

Ok, then i understand. Thanks for taking your time. Hope i can help you sometime.

Ole