sonite
(Sonite)
October 11, 2024, 8:34pm
1
Hi everyone,
I’d like to set up my switch to turn on when electricity prices are low. I know this might be a basic question, but please bear with me. I’ll be honest—I’m not a big fan of YAML or templates, but it seems like I might not have a choice.
I have a Shelly switch connected to Home Assistant (HA) and the Nordpool integration. I’m using a YAML template to better format the entity Nordpool2, which I then display via Apex Charts to show four different price tiers. The logic I’m using is based on quartiles: I want the switch to be active during the Q1 and Q2 quartiles (lower prices) and avoid Q3 and Q4 (higher prices).
Is there a way to achieve this without using a template in YAML? -In a later stage I want to add some smart logic with timers, like if it have been sunny the last 5 minuts and the production is above X kW start, as well have a timer if it have been cloudy more than 5 min turn off.
As far as I know, there isn’t currently a stand-alone integration that can do what you are asking, so you will need to use Templating in order to perform the necessary calculations.
You may want to check out the Cheapest Energy Hours Macro . It can be installed using HACS and works with the Nordpool integration’s sensor as default. Once installed, the macro can be used in the Template Helpers. So, depending on what you are trying to do, you may not need to do any YAML configuration.
1 Like
I use simple automation with nordpool entity, works well
Is it something like that you are after?
2 Likes
Neshco
(Nenad Spasovic)
October 14, 2024, 5:57pm
4
This is simple and nice, but, it appeat that after recent update, that entity is not available anymore. Have you noticed that?
1 Like
Uhm, that one is for Sweden region 3, I still have it at v0.14
Have you created for your region?
I lost mine at 0.15 too, reverted back to 0.14.
2 Likes
Neshco
(Nenad Spasovic)
October 15, 2024, 5:10am
7
Patrick-Ohlson:
Uhm, that one is for Sweden region 3, I still have it at v0.14
Have you created for your region?
Sure, NO1 Oslo region, it worked until yesterday update 0.15
Have you tried to update?
Nope, I don’t see the update yet actually
So, it’s a bug/change in 0.15 then, now I won’t update
It’s a cornerstone addon, coz winter is coming:eyes:
sonite
(Sonite)
October 15, 2024, 3:06pm
9
Thanks to both @Didgeridrew and @Patrick-Ohlson . I don’t really like how I solved part of my issue, but here we go:
I added the following code to my template.yaml and created an automation:
- sensor:
#### NordPool Dynamic Quantiles
- name: "Q1 Nordpool quantile"
unique_id: fffe9476-2349-4d81-a5ff-e5f31d22f89a
icon: mdi:cash
unit_of_measurement: "öre/kWh"
state: "{{
state_attr('sensor.nordpool_energy_prices','q1')
}}"
- name: "Q2 Nordpool quantile"
unique_id: fffe9476-2349-4d81-a5ff-e5f31d22f89b
icon: mdi:cash
unit_of_measurement: "öre/kWh"
state: "{{
state_attr('sensor.nordpool_energy_prices','q2')
}}"
- name: "Q3 Nordpool quantile"
unique_id: fffe9476-2349-4d81-a5ff-e5f31d22f89c
icon: mdi:cash
unit_of_measurement: "öre/kWh"
state: "{{
state_attr('sensor.nordpool_energy_prices','q3')
}}"
- name: "Q4 Nordpool quantile"
unique_id: fffe9476-2349-4d81-a5ff-e5f31d22f89d
icon: mdi:cash
unit_of_measurement: "öre/kWh"
state: "{{
state_attr('sensor.nordpool_energy_prices','q4')
}}"
1 Like
sonite
(Sonite)
October 15, 2024, 3:17pm
10
Woops, that is always true, need to add comparison for the current hour
If you update (I have NO1 Oslo region on 0.14) you need to delete the integration and install it again, then select the NO1 region (not Oslo). Then you will get a sensor.
1 Like
Neshco
(Nenad Spasovic)
October 15, 2024, 7:53pm
12
I have tried to revert, picked some full backup from few days before, but my ApexChart does not work anymore, very strange. And yes, I have changed it to NO1, but no luck, its same.
So:
Update to 0.15,
Remove integration
Install integration
I will give it a try, thanks.
The sensor name changes. Either update your charts or rename the sensor to the old name.
1 Like
Neshco
(Nenad Spasovic)
October 15, 2024, 8:17pm
14
Done that, all fine now. Thanks for help!
sonite
(Sonite)
October 15, 2024, 8:43pm
15
In the automation, I used the following code. I just hope it won’t trigger too much during sunny hours.
alias: Manage Floor Heating Based on Energy Prices and Solar Production
description: >
Turn on floor heating when prices are low (Q1), turn off during
overproduction, and turn off if no overproduction and not in Q1.
triggers:
- trigger: numeric_state
entity_id:
- sensor.ams_ec5d_po
above: sensor.ams_ec5d_p
- trigger: time_pattern
minutes: "1"
conditions: []
actions:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.ams_ec5d_po
above: sensor.ams_ec5d_p
- condition: and
conditions:
- condition: device
type: is_off
device_id: bdb56bab5f9ef9d9e0d4210ec044185f
entity_id: 10aa6676e1da35cc7b7327853c5c5938
domain: switch
sequence:
- wait_for_trigger:
- type: power
device_id: 3e3801cbb6ef2ff27c589980468dfc13
entity_id: fe8147054e82cac21b29422113fe614d
domain: sensor
trigger: device
above: 500
timeout:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- type: turn_on
device_id: bdb56bab5f9ef9d9e0d4210ec044185f
entity_id: 10aa6676e1da35cc7b7327853c5c5938
domain: switch
- conditions:
- condition: numeric_state
entity_id: sensor.ams_ec5d_po
below: sensor.ams_ec5d_p
- condition: template
value_template: >
{{ states('sensor.nordpool_energy_prices') | float(0) >
state_attr('sensor.nordpool_energy_prices', 'q2') | float(0) }}
sequence:
- type: turn_off
device_id: bdb56bab5f9ef9d9e0d4210ec044185f
entity_id: 10aa6676e1da35cc7b7327853c5c5938
domain: switch
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- conditions:
- condition: numeric_state
entity_id: sensor.ams_ec5d_po
below: sensor.ams_ec5d_p
- condition: template
value_template: >
{{ states('sensor.nordpool_energy_prices') | float(0) <=
state_attr('sensor.nordpool_energy_prices', 'q2') | float(0) }}
sequence:
- type: turn_on
device_id: bdb56bab5f9ef9d9e0d4210ec044185f
entity_id: 10aa6676e1da35cc7b7327853c5c5938
domain: switch
mode: single
And the code in template.yaml for my Nordpool sensor:
q1: >
{% set trading_prices = (
states('input_number.additional_energy_costs') | float(0) +
states('input_number.elec_certificat') | float(0) +
states('input_number.trading_fees') | float(0)
) %}
{% set maxs = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','max') * 125) + trading_prices %}
{% set mins = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','min') * 125) + trading_prices %}
{{ (((maxs - mins) / 4 * 0) + mins) | round(2) }}
q2: >
{% set trading_prices = (
states('input_number.additional_energy_costs') | float(0) +
states('input_number.elec_certificat') | float(0) +
states('input_number.trading_fees') | float(0)
) %}
{% set maxs = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','max') * 125) + trading_prices %}
{% set mins = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','min') * 125) + trading_prices %}
{{ (((maxs - mins) / 4 * 1) + mins) | round(2) }}
q3: >
{% set trading_prices = (
states('input_number.additional_energy_costs') | float(0) +
states('input_number.elec_certificat') | float(0) +
states('input_number.trading_fees') | float(0)
) %}
{% set maxs = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','max') * 125) + trading_prices %}
{% set mins = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','min') * 125) + trading_prices %}
{{ (((maxs - mins) / 4 * 2) + mins) | round(2) }}
q4: >
{% set trading_prices = (
states('input_number.additional_energy_costs') | float(0) +
states('input_number.elec_certificat') | float(0) +
states('input_number.trading_fees') | float(0)
) %}
{% set maxs = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','max') * 125) + trading_prices %}
{% set mins = (state_attr('sensor.nordpool_kwh_se3_sek_4_10_0','min') * 125) + trading_prices %}
{{ (((maxs - mins) / 4 * 3) + mins) | round(2) }}
Thanks for the inspiration!
2 Likes