Closed jtfidje closed 3 years ago
I haven't found a way to show a future graph. Let me know if you find a way to do this. Maybe is possible to use the mini graph card. It wasn’t possible last time I tried.
@AivarJ that will show the price the last 48 hours. They want to show the prices today and tomorrow as a graph.
I have tried a few different ways to graph the 24h today & tomorrow values, but without success. Motsly because the tomorrow prices are updated at about 12:45. This means that the tomorrow values is not up to date betwen midnight and 12:45.
If someone manages to export two full "static" charts that starts with hour 00 and does not update during the day, I am interested.
Currently I have a chart showing the last 24 hours, and another chart for the following 12 hours. I managed to get a forecast by a template sensor that fetch the value from now().hour + 12 hours.
By using 12 hours it is easy to interpret when hovering the chart. For example when the bar is updated at 5:00 pm, hovering it will show the price at 5:00 am.
This is the result.
Below is the sensors configuration:
sensor:
- platform: nordpool
VAT: False
currency: "SEK"
price_in_cents: True
# low_price = hour_price < average * low_price_cutoff
low_price_cutoff: 0.95
region: "SE3"
precision: 2
price_type: kWh
- platform: template
sensors:
hour:
friendly_name: "Hour"
entity_id: sensor.time
value_template: "{{ now().hour }}"
- platform: template
sensors:
nordpool_12h:
entity_id: sensor.nordpool_kwh_se3_sek_2_095_0
friendly_name: "Nordpool 12h"
icon_template: mdi:cash
unit_of_measurement: "öre/kWh"
value_template: >-
{% if states('sensor.hour') | int == 00 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[12] }}
{% elif states('sensor.hour') | int == 01 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[13] }}
{% elif states('sensor.hour') | int == 02 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[14] }}
{% elif states('sensor.hour') | int == 03 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[15] }}
{% elif states('sensor.hour') | int == 04 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[16] }}
{% elif states('sensor.hour') | int == 05 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[17] }}
{% elif states('sensor.hour') | int == 06 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[18] }}
{% elif states('sensor.hour') | int == 07 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[19] }}
{% elif states('sensor.hour') | int == 08 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[20] }}
{% elif states('sensor.hour') | int == 09 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[21] }}
{% elif states('sensor.hour') | int == 10 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[22] }}
{% elif states('sensor.hour') | int == 11 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.today[23] }}
{% elif states('sensor.hour') | int == 12 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[0] }}
{% elif states('sensor.hour') | int == 13 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[1] }}
{% elif states('sensor.hour') | int == 14 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[2] }}
{% elif states('sensor.hour') | int == 15 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[3] }}
{% elif states('sensor.hour') | int == 16 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[4] }}
{% elif states('sensor.hour') | int == 17 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[5] }}
{% elif states('sensor.hour') | int == 18 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[6] }}
{% elif states('sensor.hour') | int == 19 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[7] }}
{% elif states('sensor.hour') | int == 20 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[8] }}
{% elif states('sensor.hour') | int == 21 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[9] }}
{% elif states('sensor.hour') | int == 22 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[10] }}
{% elif states('sensor.hour') | int == 23 %}
{{ states.sensor.nordpool_kwh_se3_sek_2_095_0.attributes.tomorrow[11] }}
{% endif %}
The only caveat is that when the hour is 12 the tomorrow[0] value is fething an outdated value (the price at midnight, which is most cases is very close to the real value.
Below is the lovelace configuration (custom:mini-graph-card):
aggregate_func: first
decimals: 0
entities:
- entity: sensor.nordpool_kwh_se3_sek_2_095_0
name: Nordpool spotpris
group_by: hour
hour24: true
hours_to_show: 24
labels: true
line_color: '#a9d6d5'
lower_bound: 0
show:
graph: bar
labels: true
icon_adaptive_color: true
type: 'custom:mini-graph-card'
unit: öre/kWh
aggregate_func: first
decimals: 0
entities:
- entity: sensor.nordpool_12h
name: Nordpool 12h
group_by: hour
hour24: false
hours_to_show: 12
line_color: '#d4d4d4'
lower_bound: 0
points_per_hour: 1
show:
graph: bar
icon_adaptive_color: true
labels: true
type: 'custom:mini-graph-card'
The sensor.hour might have have to be customized to show 24 hours for the 12 hour am/pm users.
I hope someone find this useful!
Using the above sensors we could combine two 12 hour charts which is close to what @jtfidje wants.
aggregate_func: first
decimals: 0
entities:
- entity: sensor.nordpool_kwh_se3_sek_2_095_0
name: last 12h
color: '#99d995'
- entity: sensor.nordpool_12h
name: forecast 12h
color: '#dcdcdc'
group_by: hour
hour24: true
hours_to_show: 12
labels: true
lower_bound: 0
show:
graph: bar
name: false
icon: false
labels: true
type: 'custom:mini-graph-card'
unit: öre/kWh
Is there something changed in Hass or is there something fishy in my sensor config? The next 12h forecast don't work.
lovelace.yaml:
aggregate_func: first
decimals: 2
entities:
- color: '#FF0000'
entity: sensor.nordpool_kwh_ee_eur_2_10_02
name: last 12h
- color: '#1E90FF'
entity: sensor.nordpool_12h
name: next 12h
group_by: hour
hour24: true
hours_to_show: 24
labels: true
lower_bound: 0
show:
graph: bar
icon: false
labels: true
name: false
type: 'custom:mini-graph-card'
unit: c/kWh
sensors.yaml
- platform: nordpool
region: "EE"
VAT: True
currency: "EUR"
precision: 2
price_type: kWh
price_in_cents: True
friendly_name: "Electricity Prices"
- platform: template
sensors:
hour:
friendly_name: "Hour"
entity_id: sensor.time
value_template: "{{ now().hour }}"
- platform: template
sensors:
nordpool_12h:
entity_id: sensor.nordpool_kwh_ee_eur_2_10_02
friendly_name: "Nordpool 12h"
icon_template: mdi:cash
unit_of_measurement: "c/kWh"
value_template: >-
{% if states('sensor.hour') | int == 00 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[12] }}
{% elif states('sensor.hour') | int == 01 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[13] }}
{% elif states('sensor.hour') | int == 02 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[14] }}
{% elif states('sensor.hour') | int == 03 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[15] }}
{% elif states('sensor.hour') | int == 04 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[16] }}
{% elif states('sensor.hour') | int == 05 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[17] }}
{% elif states('sensor.hour') | int == 06 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[18] }}
{% elif states('sensor.hour') | int == 07 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[19] }}
{% elif states('sensor.hour') | int == 08 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[20] }}
{% elif states('sensor.hour') | int == 09 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[21] }}
{% elif states('sensor.hour') | int == 10 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[22] }}
{% elif states('sensor.hour') | int == 11 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.today[23] }}
{% elif states('sensor.hour') | int == 12 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[0] }}
{% elif states('sensor.hour') | int == 13 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[1] }}
{% elif states('sensor.hour') | int == 14 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[2] }}
{% elif states('sensor.hour') | int == 15 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[3] }}
{% elif states('sensor.hour') | int == 16 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[4] }}
{% elif states('sensor.hour') | int == 17 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[5] }}
{% elif states('sensor.hour') | int == 18 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[6] }}
{% elif states('sensor.hour') | int == 19 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[7] }}
{% elif states('sensor.hour') | int == 20 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[8] }}
{% elif states('sensor.hour') | int == 21 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[9] }}
{% elif states('sensor.hour') | int == 22 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[10] }}
{% elif states('sensor.hour') | int == 23 %}
{{ states.sensor.nordpool_kwh_ee_eur_2_10_02.attributes.tomorrow[11] }}
{% endif %}
What’s wrong? Check the attributes for the sensor.
"hours_to_show" in lovelace.yaml should be 12 instead of 24 to view correctly.
@Hellowlol 12h forecast don't work, (blue bars) showing random numbers from attributes. @rs443 thanks, I was just testing and forgot to change it back to 12 :)
Look at the pictures, now there is only a max price:
I know ever little about Lovelace, but looking et the raw attribute values it seems to be correct. The energy price today graph looks awesome. Mind sharing the Lovelace for that one?
It's the same mini-graph-card that @AivarJ shared, with little modifications.
aggregate_func: last
animate: true
color_thresholds:
- color: '#FF0000'
value: 4.5
- color: '#DAA520'
value: 3.5
- color: '#008000'
value: 2
- color: '#1E90FF'
value: 1
color_thresholds_transition: false
decimals: 2
entities:
- sensor.nordpool_kwh_ee_eur_2_10_02
hour24: true
hours_to_show: 48
name: Energy prices today
points_per_hour: 1
show:
average: true
fill: true
icon_adaptive_color: true
labels: true
name_adaptive_color: true
type: 'custom:mini-graph-card'
update_interval: false
There is a warning on Hass templating page:
Maybe that's why I can't get it to work as it should, what's wrong with the last line, I can't figure it out:
@stosoorok
Maybe this works?:
{{ state_attr('sensor.nordpool_kwh_ee_eur_2_10_02', 'today')[0] }}
Works great, thanks @rs443
Been trying all of those codes and all of them give me a flat line in the graph. Anyone who can point exactly where and how to put it? sensor.hour seems to only update on restart of home assistant? my sensor.nordpool_12h only contains 1 value.
This is my configuration.yaml:
sensor:
- platform: nordpool
VAT: False
currency: "SEK"
price_in_cents: True
# low_price = hour_price < average * low_price_cutoff
low_price_cutoff: 0.95
region: "SE4"
precision: 2
price_type: kWh
- platform: template
sensors:
hour:
friendly_name: "Hour"
entity_id: sensor.time
value_template: "{{ now().hour }}"
- platform: template
sensors:
nordpool_12h:
entity_id: sensor.nordpool_kwh_se4_sek_2_095_0
friendly_name: "Nordpool 12h"
icon_template: mdi:cash
unit_of_measurement: "öre/kWh"
value_template: >-
{% if states('sensor.hour') | int == 00 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[12] }}
{% elif states('sensor.hour') | int == 01 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[13] }}
{% elif states('sensor.hour') | int == 02 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[14] }}
{% elif states('sensor.hour') | int == 03 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[15] }}
{% elif states('sensor.hour') | int == 04 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[16] }}
{% elif states('sensor.hour') | int == 05 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[17] }}
{% elif states('sensor.hour') | int == 06 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[18] }}
{% elif states('sensor.hour') | int == 07 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[19] }}
{% elif states('sensor.hour') | int == 08 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[20] }}
{% elif states('sensor.hour') | int == 09 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[21] }}
{% elif states('sensor.hour') | int == 10 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[22] }}
{% elif states('sensor.hour') | int == 11 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.today[23] }}
{% elif states('sensor.hour') | int == 12 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[0] }}
{% elif states('sensor.hour') | int == 13 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[1] }}
{% elif states('sensor.hour') | int == 14 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[2] }}
{% elif states('sensor.hour') | int == 15 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[3] }}
{% elif states('sensor.hour') | int == 16 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[4] }}
{% elif states('sensor.hour') | int == 17 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[5] }}
{% elif states('sensor.hour') | int == 18 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[6] }}
{% elif states('sensor.hour') | int == 19 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[7] }}
{% elif states('sensor.hour') | int == 20 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[8] }}
{% elif states('sensor.hour') | int == 21 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[9] }}
{% elif states('sensor.hour') | int == 22 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[10] }}
{% elif states('sensor.hour') | int == 23 %}
{{ states.sensor.nordpool_kwh_se4_sek_2_095_0.attributes.tomorrow[11] }}
{% endif %}
And this is my lovelace:
aggregate_func: first
animate: true
color_thresholds:
- color: '#FF0000'
value: 100
- color: '#DAA520'
value: 50
- color: '#008000'
value: 30
- color: '#1E90FF'
value: 15
color_thresholds_transition: false
decimals: 0
entities:
- sensor.nordpool_12h
hour24: true
hours_to_show: 12
name: Energy prices today
points_per_hour: 1
show:
average: false
fill: true
icon_adaptive_color: true
labels: true
name_adaptive_color: true
type: 'custom:mini-graph-card'
update_interval: false
It just plots what it has in the past since it only contains 1 value (the one added when I last restarted HA)
@rs443
Maybe this works?:
{{ state_attr('sensor.nordpool_kwh_ee_eur_2_10_02', 'today')[0] }}
Kan du vara sjyst att posta din uppdaterade yaml här? Testa flera olika templates men alla visar samma state. Vad missar jag ?
@Hellowlol I think it's possible to get a graph of all 48 price values into a lovelace-card by using the mini graph card. Just make template sensors for each hour as shown in the lovelace_example section or by using the python script. Then make the mini graph card in a preferred place in your lovelace configuration (I assume you're using lovelace yaml-mode, and don't mind the style bit at the end, it's just for my own visualization of the lovelace card):
- type: custom:mini-graph-card
entities:
- entity: sensor.nordpool_kwh_krsand_nok_2_095_025
color: '#03a9f4'
show_graph: false
show_state: true
state_adaptive_color: true
- entity: sensor.nordpool_today_hr_00_01
name: Today hour 1
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_01_02
name: Today hour 2
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_02_03
name: Today hour 3
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_03_04
name: Today hour 4
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_04_05
name: Today hour 5
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_05_06
name: Today hour 6
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_06_07
name: Today hour 7
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_07_08
name: Today hour 8
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_08_09
name: Today hour 9
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_09_10
name: Today hour 10
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_10_11
name: Today hour 11
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_11_12
name: Today hour 12
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_12_13
name: Today hour 13
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_13_14
name: Today hour 14
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_14_15
name: Today hour 15
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_15_16
name: Today hour 16
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_16_17
name: Today hour 17
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_17_18
name: Today hour 18
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_18_19
name: Today hour 19
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_19_20
name: Today hour 20
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_20_21
name: Today hour 21
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_21_22
name: Today hour 22
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_22_23
name: Today hour 23
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_23_24
name: Today hour 24
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_00_01
name: Tomorrow hour 1
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_01_02
name: Tomorrow hour 2
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_02_03
name: Tomorrow hour 3
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_03_04
name: Tomorrow hour 4
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_04_05
name: Tomorrow hour 5
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_05_06
name: Tomorrow hour 6
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_06_07
name: Tomorrow hour 7
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_07_08
name: Tomorrow hour 8
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_08_09
name: Tomorrow hour 9
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_09_10
name: Tomorrow hour 10
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_10_11
name: Tomorrow hour 11
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_11_12
name: Tomorrow hour 12
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_12_13
name: Tomorrow hour 13
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_13_14
name: Tomorrow hour 14
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_14_15
name: Tomorrow hour 15
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_15_16
name: Tomorrow hour 16
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_16_17
name: Tomorrow hour 17
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_17_18
name: Tomorrow hour 18
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_18_19
name: Tomorrow hour 19
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_19_20
name: Tomorrow hour 20
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_20_21
name: Tomorrow hour 21
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_21_22
name: Tomorrow hour 22
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_22_23
name: Tomorrow hour 23
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_23_24
name: Tomorrow hour 24
color: '#ff9800'
show_legend: false
name: Energyprice current, today, tomorrow
group_by: hour
hours_to_show: 1
hour24: true
icon: mdi:cash-multiple
show:
graph: bar
labels: true
style: |
ha-card {
background: rgba(250,250,250,0.9);
border-radius: 15px;
box-shadow: -6px -6px 6px 0 rgba(255,255,255,.5),6px 6px 6px 0 rgba(0,0,0,.03);
--paper-item-icon-color: rgba(75,75,75,0.8);
}
.card-content {
padding-top: 0px;
padding-left: 10px;
padding-bottom: 0px;
}
Unfortunately from midnight until 13:00 the card will look like:
When Nordpool announces the prices for tomorrow the card will look as the first one again.
@Hellowlol I think it's possible to get a graph of all 48 price values into a lovelace-card by using the mini graph card. Just make template sensors for each hour as shown in the lovelace_example section or by using the python script. Then make the mini graph card in a preferred place in your lovelace configuration (I assume you're using lovelace yaml-mode, and don't mind the style bit at the end, it's just for my own visualization of the lovelace card):
When Nordpool announces the prices for tomorrow the card will look as the first one again.
This looks great!!
Just one thing:
I set up template values and graph just like this but if i hover over one bar/price the time for it always shows as the current hour, the price shows correctly however. Any idea why?
Yes, I know why. It's because you have to set hours_to_show: 1
to get this view. And because of that, any price you hover over is valid every hour the hole day. There is no way to tell the mini-graph-card that for instance entity: sensor.nordpool_today_hr_23_24
is only valid today from 23:00:00 to 00:00:00. Hopefully that make some sense...
Ok, i understand. Thanks for clearing that up
So.. I'm a beginner to HA.. Can't figure out what is wrong.. I used the script @jnrksv added here.. I had to remove the "-" before type: custom:mini-graph-card to get it to work though..
Looks like this now:
and here is the code im using... Is the entities wrong for each hour? It that why they are not showing up?
- entity: sensor.nordpool_today_hr_00_01
type: 'custom:mini-graph-card'
entities:
- entity: sensor.nordpool_kwh_se3_sek_3_08_025
color: '#03a9f4'
show_graph: false
show_state: true
state_adaptive_color: true
- entity: sensor.nordpool_today_hr_00_01
name: Today hour 1
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_01_02
name: Today hour 2
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_02_03
name: Today hour 3
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_03_04
name: Today hour 4
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_04_05
name: Today hour 5
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_05_06
name: Today hour 6
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_06_07
name: Today hour 7
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_07_08
name: Today hour 8
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_08_09
name: Today hour 9
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_09_10
name: Today hour 10
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_10_11
name: Today hour 11
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_11_12
name: Today hour 12
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_12_13
name: Today hour 13
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_13_14
name: Today hour 14
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_14_15
name: Today hour 15
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_15_16
name: Today hour 16
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_16_17
name: Today hour 17
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_17_18
name: Today hour 18
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_18_19
name: Today hour 19
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_19_20
name: Today hour 20
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_20_21
name: Today hour 21
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_21_22
name: Today hour 22
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_22_23
name: Today hour 23
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_today_hr_23_24
name: Today hour 24
color: '#03a9f4'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_00_01
name: Tomorrow hour 1
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_01_02
name: Tomorrow hour 2
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_02_03
name: Tomorrow hour 3
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_03_04
name: Tomorrow hour 4
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_04_05
name: Tomorrow hour 5
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_05_06
name: Tomorrow hour 6
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_06_07
name: Tomorrow hour 7
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_07_08
name: Tomorrow hour 8
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_08_09
name: Tomorrow hour 9
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_09_10
name: Tomorrow hour 10
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_10_11
name: Tomorrow hour 11
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_11_12
name: Tomorrow hour 12
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_12_13
name: Tomorrow hour 13
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_13_14
name: Tomorrow hour 14
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_14_15
name: Tomorrow hour 15
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_15_16
name: Tomorrow hour 16
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_16_17
name: Tomorrow hour 17
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_17_18
name: Tomorrow hour 18
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_18_19
name: Tomorrow hour 19
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_19_20
name: Tomorrow hour 20
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_20_21
name: Tomorrow hour 21
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_21_22
name: Tomorrow hour 22
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_22_23
name: Tomorrow hour 23
color: '#ff9800'
show_legend: false
- entity: sensor.nordpool_tomorrow_hr_23_24
name: Tomorrow hour 24
color: '#ff9800'
show_legend: false
name: 'Energyprice current, today, tomorrow'
group_by: hour
hours_to_show: 1
hour24: true
icon: 'mdi:cash-multiple'
show:
graph: bar
labels: true
style: |
ha-card {
background: rgba(250,250,250,0.9);
border-radius: 15px;
box-shadow: -6px -6px 6px 0 rgba(255,255,255,.5),6px 6px 6px 0 rgba(0,0,0,.03);
--paper-item-icon-color: rgba(75,75,75,0.8);
}
.card-content {
padding-top: 0px;
padding-left: 10px;
padding-bottom: 0px;
}
Do you have any sensors named sensor.nordpool_tomorrow_hr_23_24 etc? Remember the hour value sensors has to be created.
Do you have any sensors named sensor.nordpool_tomorrow_hr_23_24 etc? Remember the hour value sensors has to be created.
ohh.. I have not .. Thanks for pointing that out! I guess that should go into configuration.yaml ? .. I have no idea how it should look like though. I saw a sample in this thread but think that one did not work?
@Meph79 You can make the "hour value sensors" as described in the lovelace_example section. And, yes, it's correct that it should go into the configuration.yaml. In fact, you have two choices. Either define every sensor directly in the configuration.yaml file like:
sensor:
- platform: template
sensors:
nordpool_today_hr_00_01:
friendly_name: "Today hour 1"
icon_template: mdi:cash
unit_of_measurement: "SEK"
value_template: "{{ states.sensor.nordpool_kwh_se3_sek_3_08_025.attributes.today[0] }}"
nordpool_today_hr_01_02:
friendly_name: "Today hour 2"
icon_template: mdi:cash
unit_of_measurement: "SEK"
value_template: "{{ states.sensor.nordpool_kwh_se3_sek_3_08_025.attributes.today[1] }}"
And so on for all the 48 hours.
Or you can put all sensors in a separated file named sensors.yaml and point to this file in the configuration.yaml like:
sensor: !include sensors.yaml
This way is well documented in the Home Assistant documentation Spitting up the configuration. I hope this points you in the right direction.
Closing this as multiple ways to handle this has been posted. We should update the lovelace example with @jnrksv code example and image.
I hope this points you in the right direction.
Yes thank you. I thought the link erlier in this thread was to home assistant examples of setting up lovelace scripts.. I already had that page open so i did not click that link.. I should have... hehe.. I had to add entity_id: for every entry, noticed it would not work otherwise i took a look at the locelace_example... Also wanna integrate that table that is over there :)
Thanks for your help!
I will attach the sensors.yaml as an zipped file here to help out ppl.
You pointed me in the right direction.. After 3 reboots i got it to work.. This is what it looks like when placed in sensors.yaml:
- platform: template
sensors:
nordpool_today_hr_00_01:
entity_id: sensor.nordpool_kwh_se3_sek_3_08_025
friendly_name: "Today hour 1"
icon_template: mdi:cash
unit_of_measurement: "SEK"
value_template: "{{ states.sensor.nordpool_kwh_se3_sek_3_08_025.attributes.today[0] }}"
nordpool_today_hr_01_02:
entity_id: sensor.nordpool_kwh_se3_sek_3_08_025
friendly_name: "Today hour 2"
icon_template: mdi:cash
unit_of_measurement: "SEK"
value_template: "{{ states.sensor.nordpool_kwh_se3_sek_3_08_025.attributes.today[1] }}"
and so on...
That shouldn't be needed. Anyway I'm glad you got it working. :)
Is it possible to make a marker on the graph that shows the current price by what the time is?
No, I don't think so. In the example above, we are limited to what is possible to achieve using the mini-graph-card. And reading the mini-graph-card documentation I can't see that it should be possible. To achieve what you want, someone has to make a dedicated "lovelace-nordpool-card".
Okei, thank for the quick response. Hope someone with knowledge can do that :) hehe
I've found a very simple and beautiful solution, using the very nice apexcharts-card plugin. No additional sensors or huge lists for data extraction needed. (It seems almost like apexcharts-card was made for this nordpool plugin!)
type: 'custom:apexcharts-card'
graph_span: 24h
header:
title: Strømpriser i dag
show: true
span:
start: day
now:
show: true
label: Nå
series:
- entity: sensor.nordpool_kwh_oslo_nok
type: column
data_generator: |
return entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
});
Also, for showing tomorrow. That should probably have a check to see if the tomorrow_valid attribute is set.
type: 'custom:apexcharts-card'
graph_span: 1d
header:
title: Strømpriser i morgen (kr/kWh)
show: true
span:
start: day
offset: +1d
series:
- entity: sensor.nordpool_kwh_oslo_nok
type: column
data_generator: |
return entity.attributes.raw_tomorrow.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]];
});
The two graphs can very possibly be combined, by offsetting one of the data sets.
The apexcharts-card works really nice for me to but only on the phone app. In the browser it says "Custom element doesn't exist: apexchart-card." Until just now when I did the clear cash and restart Firefox thing...
This isnt the correct place. Try open in another browser in icognito mode and open a issue in the apex varda github page
Thanks for a nice find to @mabahj I just added little tuning to apexcharts-card:
type: 'custom:apexcharts-card'
experimental:
color_threshold: true
graph_span: 24h
header:
title: Electricity Price Today
show: true
span:
start: day
now:
show: true
label: Now
series:
- entity: sensor.your_nordpool_sensor_here
type: column
data_generator: |
return entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
});
color_threshold:
- value: 0
color: green
opacity: 1
- value: 4
color: yellow
- value: 8
color: red
Thanks for a nice find to @mabahj I just added little tuning to apexcharts-card:
type: 'custom:apexcharts-card' experimental: color_threshold: true graph_span: 24h header: title: Electricity Price Today show: true span: start: day now: show: true label: Now series: - entity: sensor.your_nordpool_sensor_here type: column data_generator: | return entity.attributes.raw_today.map((start, index) => { return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]]; }); color_threshold: - value: 0 color: green opacity: 1 - value: 4 color: yellow - value: 8 color: red
Nice, thanks! Do you know how to att the colors on tomorrows card? i cant get it to work. if u ave please show code :)
Do you know how to att the colors on tomorrows card? i cant get it to work. if u ave please show code :)
Just change the data_generator 'raw_today' to 'raw_tomorrow'.
My Card Configuration. Hopefully it helps.
Hi, I tried it but I got errors.
/// apexcharts-card version 1.10.0-dev.6 /// value.all_series_config is not a ChartCardAllSeriesExternalConfig; value.all_series_config.color_threshold[1] is not a ChartCardColorThreshold; value.all_series_config.color_threshold[1].color is not a string
Displayed error tells where the problem is :-) ` color_threshold:
I've found a very simple and beautiful solution, using the very nice apexcharts-card plugin. No additional sensors or huge lists for data extraction needed. (It seems almost like apexcharts-card was made for this nordpool plugin!)
type: 'custom:apexcharts-card' graph_span: 24h header: title: Strømpriser i dag show: true span: start: day now: show: true label: Nå series: - entity: sensor.nordpool_kwh_oslo_nok type: column data_generator: | return entity.attributes.raw_today.map((start, index) => { return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]]; });
Also, for showing tomorrow. That should probably have a check to see if the tomorrow_valid attribute is set.
type: 'custom:apexcharts-card' graph_span: 1d header: title: Strømpriser i morgen (kr/kWh) show: true span: start: day offset: +1d series: - entity: sensor.nordpool_kwh_oslo_nok type: column data_generator: | return entity.attributes.raw_tomorrow.map((start, index) => { return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]]; });
The two graphs can very possibly be combined, by offsetting one of the data sets.
Thank you very much for this!
And just for people who do not know how to hide if tomorrows values are not valid, this is my configuration for the tomorrow card:
- type: conditional
conditions:
- entity: sensor.nordpool_kwh_dk1_dkk_3_10_025.attributes.tomorrow_valid
state: 'true'
card:
type: 'custom:apexcharts-card'
graph_span: 1d
header:
title: Strømpriser i morgen (kr/kWh)
show: true
span:
start: day
offset: +1d
series:
- entity: sensor.nordpool_kwh_dk1_dkk_3_10_025
type: column
data_generator: |
return entity.attributes.raw_tomorrow.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]];
});
My Card Configuration. Hopefully it helps.
Nice chart!
Is it possible to remove the gap between today and tomorrow?
Here's another one that shows the complete next 24 hours, including tomorrow's values when available, combined into one graph. No gaps or anything like that. Possible downside for some may be that parts of the graph is empty until the data for that time span ("tomorrow") is available, but that works for me - the prices for that time span is not set and therefore the graph shows no prices.
type: custom:apexcharts-card
graph_span: 24h
experimental:
color_threshold: true
header:
title: Prices next 24h (kr/kWh)
show: true
apex_config:
yaxis:
min: 0
hours_12: false
span:
start: hour
offset: '-2h'
now:
show: true
label: Nå
series:
- entity: sensor.nordpool_kwh_oslo_nok
type: column
data_generator: |
return (entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
})).concat(entity.attributes.raw_tomorrow.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]];
}));
color_threshold:
- value: 0
color: green
- value: 1
color: orange
- value: 2
color: red
- value: 3
color: darkred
- value: 4
color: black
Thanks, but I already have a similar chart. I would like to have the chart in https://github.com/custom-components/nordpool/issues/19#issuecomment-846621429 but without the gap.
@mabahj - thanks, your data_generator works fine.
Thanks, but I already have a similar chart. I would like to have the chart in #19 (comment) but without the gap.
You can fill the cap when you change series.extend_to_end to true and use data_generator what @mabahj shared few days ago.
How extend_to_end changes the behavior of the graph.
extend_to_end: false and no tomorrow prices (2 day graph)
extend_to_end: true and no tomorrow prices (2 day graph)
2 day graph and tomorrow prices
I also added also current price field in header.
@AivarJ: Thanks a lot!
My Card Configuration. Hopefully it helps.
In case the gap between 11 PM and midnight bugs you, add a "zero" element at midnight to "today" by replacing the "Current day" data generator with:
var a = entity.attributes.raw_today.map((start, index) => {
return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
});
var b = [a[a.length - 1][0] + 3600000, 0];
a.push( b );
return a;
Looks great!
Just heads up - since ApexCharts update to 2.0.0, the extend_to_end
does not work any more, for this chart code in apexcharts >= 2.0.0 extend_to: now
should be used instead.
I'm trying my best here, but I only get an error on the templates.
Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/components/hassio/init.py", line 693, in async_handle_core_service raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'integer') for dictionary value @ data['sensors']['nordpool_12h']['value_template']. Got "{% if states('sensor.hour') | int == 00 %}\n {{ states.sensor.nordpool_kwh_bergen_nok_2_095_0.attributes.today[12] }}\n{% elif states('sensor.hour') | int == 01 %}\n {{ states.sensor.nordpool_kwh_bergen_nok_2_095_0.attributes.today[13] }}\n{% elif states('sensor.hour') | int == 02 %}\n {{ states.sensor.nordpool_kwh_bergen_nok_2_095_0.attributes.today[14] }}\n{% elif states('sensor.hour') | int == 03 %}\n {{ states.sensor.nordpool_kwh_bergen_nok_2_095_0.attributes.today[15] }}\n{% elif st.... (See ?, line ?).
EDIT: I fixed it by removing all the 0 before single digit hours.
In case the gap between 11 PM and midnight bugs you, add a "zero" element at midnight to "today" by replacing the "Current day" data generator with:
var a = entity.attributes.raw_today.map((start, index) => { return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]]; }); var b = [a[a.length - 1][0] + 3600000, 0]; a.push( b ); return a;
Just a minor improvement for those wishing to remove the gap between the two sections. Instead of adding a datapoint at '0' i added a datapoint with the same value as 23:00: var a = entity.attributes.raw_today.map((start, index) => { return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]]; });
var b = [a[a.length - 1][0] + 3600000, a[a.length - 1][1]]; a.push( b ); return a;
This may very well be my own negligence, but is it possible to get a graph in HA with all 48 price values ( todays price and tomorrows price )? I've tried to use th
create_template.py
script, but can't really figure out how to merge all the sensors. If I try and add all the sensors in aHistory Graph
they show up as individual points ( which I guess is expected ), and if I try to add an entity with the entityID (sensor.[entity_ID]
) that was used with the script it shows up as a completely flat graph with value0
.