How do i fix the problem i have ? its not showing the preice between 23:00 - 00:00
unit: €/kWh
extend_to: end
data_generator: >
and maybe also this:
card:
type: custom:apexcharts-card
graph_span: 24h
span:
start: day
offset: +0H
and this data generator:
- entity: sensor.nordpool_xxxxxxxx
data_generator: >
return entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(),
entity.attributes.raw_today[index]["value"]];
Small snippet- and add extend_to: end before data_generator
Hope this helps, JR
Can u please post your full card yaml? i cant get it to work with your Generator code
Sorry for the delayed answer. Here comes a more comprehensive answer.
#1 - Add a “Helper”
I use a dropdown heller that looks like this:
#2 - In configuration.yaml add:
sensor:
- platform: template
sensors:
nordpool_eo4_on_hours:
friendly_name: "Nordpool EO4 Configurable On"
unit_of_measurement: 'SEK/kWh'
value_template: >
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) }}
attribute_templates:
below_config_value_now: >
{% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'current_price') <=
average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) %}
True
{% else %}
False
{% endif %}
current_price: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'current_price') }}
today: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today') }}
tomorrow_valid: >
{{ state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') }}
tomorrow: >
{% if state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow_valid') %}
{{average((state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))-1],
(state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow') | sort(reverse=true))[int(states('input_select.poolpump_avstangd'))]) |
round(3) }}
{% else %}
[]
{% endif %}
#3 - My automation for “cheap” looks like this
Then you add one more for “expensive” where your use “above” instead of “below”.
HTH/Marcus
I once found a code that should be adding a last value duplicate to the array of today prices, but I never managed to make it work. Maybe someone smarter can help us.
Heres the code:
data_generator: |
var res = entity.attributes.raw_today.map((p, index) => {
return [new Date(p.start).getTime(), entity.attributes.raw_today[index]["value"]];
});
res.push([new Date().getTime(), entity.attributes.raw_today[entity.attributes.raw_today.length() - 1].value];
return res;
Thanks alot, again!
This was very easy to follow and well explained.
Works like a charm!
Cheers!
Hi.
I am a beginner. I would like to run an electric boiler for 3 hours every day at the cheapest price. But unfortunately I can’t figure it out myself and I haven’t found it either. Maybe someone could help how to do it - who knows, it might take a few minutes
Check out corvy code her
Is there an option to display prices in cents also?
There are a lot of things which should be simple, but are in fact tricky to get perfect. However, it is often not needed to get it perfect. Starting simple and improving where needed is often a good approach.
In your case, I would begin with starting the boiler when the price is at the lowest point of the day and run the boiler for the next 3 hours. This is not guaranteed to be the cheapest, but it’s not far of and relatively easy to implement.
I haven’t tested the code, but it might look something like this:
alias: Hot water
trigger:
- platform: state
entity_id:
- sensor.nordpool
condition:
- condition: template
value_template: {{ states('sensor.nordpool') | float == state_attr('sensor.nordpool', 'min') | float }}
action:
- type: turn_on
- entity_id: switch.hot_water
- delay:
hours: 3
- type: turn_off
- entity_id: switch.hot_water
A binary template sensor based on the nordpool sensor:
---
platform: template
sensors:
cheapest_3_hours:
value_template: >-
{% set l=state_attr('sensor.nordpool', 'raw_today')|sort(attribute='value') %}
{{ (now() >= l[0].start and now() <= l[0].end)
or (now() >= l[1].start and now() <= l[1].end)
or (now() >= l[2].start and now() <= l[2].end) }}
The sensor is ON the cheapest 3 hours every day. This can be used for automations etc.
That’s some nice HAbracadabra
The sensor works very well. Now a new problem. How do I can use it as trigger. No suitable state can be found in the web interface. I canmot. Or you have to write it manually in yaml. I feel very stupid. I have still been able to get other things working without help.
There is no such thing as a stupid question. This is the area where home assistant is not as intuitive it is appears at first glance. I’m barely getting a grasp on this kind of stuff myself.
I think because it is a sensor instead of a binary_sensor, you need to put the state in as a string in the exact right format.
I think this should work:
trigger:
- platform: state
entity_id:
- sensor.energy_low
action:
- if:
- condition: state
entity_id: sensor.energy_low
state: 'False'
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.boiler
else:
- service: switch.turn_off
data: {}
target:
entity_id: switch.boiler
The Test button should tell you if you have done it right
No need to feel stupid, better to ask and learn!
You can run automations against the entitiy binary_sensor.cheapest_3_hours
whenever its on
or off
.
An example automation:
---
alias: boiler_powersaver
id: boiler_powersaver
trigger:
- platform: state
entity_id: binary_sensor.cheapest_3_hours
action:
- choose:
- conditions:
- condition: state
entity_id: binary_sensor.cheapest_3_hours
state: "on"
sequence:
- service: switch.turn_on
entity_id: switch.boiler
- conditions:
- condition: state
entity_id: binary_sensor.cheapest_3_hours
state: "off"
sequence:
- service: switch.turn_off
entity_id: switch.boiler
Built in the UI editor it would be something like this:
The link appears to be dead… ?
Now everything works as it should. Thank you for the help.
Don’t remember what that link was about, but currently nordpool integration that I am using is this one: custom-components/nordpool: nordpool sensor for ha. (github.com)
And graph card : RomRider/apexcharts-card: A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant (github.com)
type: custom:apexcharts-card
experimental:
color_threshold: true
graph_span: 1d
span:
start: day
series:
- entity: sensor.nordpool_kwh_lv_eur_2_095_0
data_generator: |
return entity.attributes.raw_today.map((entry) => {
return [new Date(entry.start), entry.value];
});
type: column
float_precision: 2
show:
extremas: true
color_threshold:
- value: 0
color: blue
- value: 0.1
color: green
- value: 0.15
color: darkorange
- value: 0.2
color: red
- value: 0.25
color: darkred
- value: 0.3
color: black
now:
show: true
color: '#ff0000'
yaxis:
- min: 0
decimals: 2