Not sure mate, I would suggest checking logs and config. This setup works just fine
great, almost what I was looking for. Since this is for heating, I’d prefer looking at say the coming few hours. I would want to heat after the cheapest hour, but not right before. Also, would be interesting to calculate the hours before midnight taking the hours after into account. Found this
but yours is a bit easier to understand. Thanks!
Appreciating you sharing your code. Trying to wrap my head around how to visualize this in the GUI. Any ideas how to make a diagram(time/price) or something similar for the 3 periods?
No, not sure about this. HA is not good at visualizing data for future…
I did this for displaying some information in the GUI:
Badge code:
badges:
- entity: binary_sensor.nordpool_kwh_cheapest_4_hours
card_mod: null
style: |
@keyframes pulse { 70% { opacity: 0; } }
:host {
--card-mod-icon-color: yellow;
animation: pulse 3s infinite;
display:
{% if is_state('binary_sensor.nordpool_kwh_cheapest_4_hours', 'off') %}
none;
{% endif %}
}
Sensor code:
- platform: template
sensors:
nordpool_kwh_cheapest_4_hours:
friendly_name: Strømpris
icon_template: >-
mdi:lightning-bolt
value_template: >-
{% set l=state_attr('sensor.nordpool_kwh_oslo', '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)
or (now() >= l[3].start and now() <= l[3].end) }}
attribute_templates:
cost1: >-
{% set l=state_attr('sensor.nordpool_kwh_oslo', 'raw_today')|sort(attribute='value') %}
{{l[0].value}} / {{l[0].start.strftime("%H:%M")}} - {{ l[0].end.strftime("%H:%M")}}
cost2: >-
{% set l=state_attr('sensor.nordpool_kwh_oslo', 'raw_today')|sort(attribute='value') %}
{{l[1].value}} / {{l[1].start.strftime("%H:%M")}} - {{ l[1].end.strftime("%H:%M")}}
cost3: >-
{% set l=state_attr('sensor.nordpool_kwh_oslo', 'raw_today')|sort(attribute='value') %}
{{l[2].value}} / {{l[2].start.strftime("%H:%M")}} - {{ l[2].end.strftime("%H:%M")}}
cost4: >-
{% set l=state_attr('sensor.nordpool_kwh_oslo', 'raw_today')|sort(attribute='value') %}
{{l[3].value}} / {{l[3].start.strftime("%H:%M")}} - {{ l[3].end.strftime("%H:%M")}}
The sensor status for displaying in the GUI is “on” (not “off”, - but had to get it to show in the GUI for gif making)
If anybody is interested in native HA solution using rest api, tibber sensor and apex charts, below is the code:
REST Sensor:
You need to replace [YOUR AUTH CODE FROM TIBBER DEVELOPER PROFILE] with your access token from tibber dev profile
- platform: rest
name: Tibber prices
resource: https://api.tibber.com/v1-beta/gql
method: POST
scan_interval: 60
payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { today { total startsAt } tomorrow { total startsAt }}}}}}" }'
json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
json_attributes:
- today
- tomorrow
value_template: Ok
headers:
Authorization: "**[YOUR AUTH CODE FROM TIBBER DEVELOPER PROFILE]**"
Content-Type: application/json
User-Agent: REST
Apex charts YAML
type: custom:apexcharts-card
apex_config:
chart:
height: 500px
header:
show: true
title: Energy stats
show_states: true
colorize_states: true
now:
show: true
color: white
label: NOW
hours_12: false
graph_span: 36h
span:
start: day
yaxis:
- id: kWh
decimals: 0
opposite: true
max: 500
apex_config:
tickAmount: 4
- id: EUR
series:
- entity: sensor.**[YOUR TIBBER ENERGY USAGE SENSOR]**
type: column
show:
extremas: true
name: Usage
stroke_width: 2
color: '#64511c'
opacity: 0.3
yaxis_id: kWh
group_by:
func: avg
duration: 15min
- entity: sensor.tibber_prices
stroke_width: 2
color: blue
curve: smooth
show:
legend_value: false
extremas: true
in_header: false
extend_to: now
yaxis_id: EUR
name: Predicted all
data_generator: |
return entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
- entity: sensor.**[YOUR TIBBER PRICE SENSOR]**
extend_to: now
show:
extremas: true
color: pink
stroke_width: 5
yaxis_id: EUR
name: price
- entity: sensor.**[YOUR TIBBER PRICE SENSOR]**
stroke_width: 2
show:
legend_value: false
extremas: true
curve: smooth
attribute: min_price
name: MIN
color: green
yaxis_id: EUR
type: line
group_by:
duration: 24hours
func: min
- entity: sensor.**[YOUR TIBBER PRICE SENSOR]**
stroke_width: 2
yaxis_id: EUR
name: AVG
attribute: avg_price
color: violet
curve: smooth
type: line
show:
legend_value: false
extremas: true
group_by:
duration: 24hours
func: avg
- entity: sensor.**[YOUR TIBBER PRICE SENSOR]**
attribute: max_price
stroke_width: 2
curve: smooth
show:
legend_value: false
extremas: true
name: MAX
color: red
yaxis_id: EUR
type: line
group_by:
duration: 24hours
func: max
You need to replace following sensors above:
- [YOUR TIBBER ENERGY USAGE SENSOR] - any sensor really showing your consumption
- [YOUR TIBBER PRICE SENSOR] - regular tibber sensor giving you the price (with mix, max, avg attributes)
Nice work! But mine only shows past prices not up coming. Any idea why?
It’s javascript code in data_generator that has not reachable code in it. It returns before it hits tomorrow data.
Try this:
data_generator: |
var a = entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
var b= entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return a.concat(b);
I like this solution. How would one make a similar entity that gives the average price and/or Future_Price_Level for the following hour, 3 hours, and 6 hours?
Price_Level is a Tibber value based on the trailing price average over the past 3 days but Future_Price_level should be the time price average of the time period (next 1, 3, or 6 hours) in comparison with the current day’s price (or following 24-hour average price if after 14:00).
The hope with this is to be able to make more intelligent heating automation that will produce heat based on the future price rather than relying only on the current price and Tibber’s Price_Level.
Cool!!!
This rest sensor worked as a charm.
Thank you very much for sharing.
I’m also interested on future price statistics to schedule my dishwasher, so I will invest some time on this and will share here when I get something.
This is working very well!
Thanks for sharing!
If you use Node-Red I can also suggest looking at this: https://powersaver.no/
I have recently started using this for my floor thermostats and waterheater and I can confirm it works very well. This can use data from Nordpool and Tibber. Just a suggestion
Also on the future pricing of power I have installed apexcharts from HACS (https://github.com/RomRider/apexcharts-card) and use this config to get the pricing for today and tomorrow:
type: custom:apexcharts-card
graph_span: 24h
experimental:
color_threshold: true
header:
title: Powerprice
show: true
apex_config:
yaxis:
min: 0
hours_12: false
span:
start: hour
offset: '-3h'
now:
show: true
label: Now
series:
- entity: sensor.nordpool_kwh_oslo_nok_2_10_025
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: var(--warning-color)
- value: 1
color: var(--warning-color)
- value: 3
color: var(--success-color)
- value: 5
color: var(--warning-color)
When the powerprice for tomorrow is not published the graphs are just empty (like in the image above). At around 13:00 the prices gets updated and will be added to the graph. I now prefer this over Tibbers own graph as its easier to compare the price from one day to another.
I had the same issue as @WattageGuy (here) and used the code that @KalleL suggested (here), that solved the issue with missing future price graph.
I also found out that MIN, AVG and MAX price calculation didn’t work correctly, it didn’t calculated on future prices. To fix that I used the REST sensor and the data_generator that @KalleL came up with. With that you get correctly calculated values for Min, Avg, and Max prices.
My chart:
Thank you @p1ranha for this chart, it’s very useful these days!
Thank you @KalleL for fixing data generator!
My final code:
type: custom:apexcharts-card
apex_config:
chart:
height: 600px
header:
show: true
title: Tibber El-pris
show_states: true
colorize_states: true
now:
show: true
color: white
label: NU
hours_12: false
graph_span: 36h
span:
start: day
yaxis:
- id: kW
decimals: 1
opposite: true
apex_config:
tickAmount: 6
- id: EUR
series:
- entity: sensor.total_anvand_effekt_nu
show:
legend_value: false
extremas: true
stroke_width: 5
curve: smooth
color: '#64511c'
opacity: 0.8
yaxis_id: kW
extend_to: now
type: column
group_by:
func: avg
duration: 30min
- entity: sensor.tibber_prices
stroke_width: 2
color: blue
curve: stepline
show:
legend_value: false
extremas: true
in_header: false
extend_to: now
yaxis_id: EUR
name: Elpriset
data_generator: |
var a = entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
var b= entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return a.concat(b);
- entity: sensor.electricity_price_xxxxxxxx
extend_to: now
show:
legend_value: false
extremas: true
curve: stepline
color: '#ffa500'
stroke_width: 5
yaxis_id: EUR
name: Pris nu
- entity: sensor.tibber_prices
stroke_width: 2
show:
legend_value: false
extremas: true
data_generator: |
var a = entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
var b= entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return a.concat(b);
curve: smooth
attribute: min_price
name: Minsta pris
color: green
yaxis_id: EUR
type: line
group_by:
duration: 36h
func: min
- entity: sensor.tibber_prices
stroke_width: 2
show:
legend_value: false
extremas: true
data_generator: |
var a = entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
var b= entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return a.concat(b);
curve: smooth
attribute: avg_price
name: Medel pris
color: violet
yaxis_id: EUR
type: line
group_by:
duration: 36h
func: avg
- entity: sensor.tibber_prices
stroke_width: 2
show:
legend_value: false
extremas: true
data_generator: |
var a = entity.attributes.today.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
var b= entity.attributes.tomorrow.map((entry) => {
return [new Date(entry.startsAt), entry.total];
});
return a.concat(b);
curve: smooth
attribute: max_price
name: Max pris
color: red
yaxis_id: EUR
type: line
group_by:
duration: 36h
func: max
That power saver node red node looks like a great idea but I would really like to try to get HA to be able to do this by creating an entity that gives the price level over the next 1-3 hours using the tibber price_level.
One could use this to set a NOT condition to prevent changing a control if the price will be lower during the chosen period. Or use it to change a control now if the price will rise after x hours.
Wow. This works great.
How can I set current price to header? It shows now last price of the series.
See the picture:
So, I’ve finally started working on this, but I’ve started a new topic to avoid confusion:
Hello, nice work. Thanks for the code.
I tried to build it for my setting. How do you make that the blue line is not visible on the left side of “now”?
My goal is to have the past line ending at “now” and the forecast line start at “now” . Do you know if this is possible? And how?
Thanks in advance.
Just tried your rest sensor out but it conflicts with the normal Tibber integration at start up and results in my HA takes 10min or so to fully load but the Tibber integration fails to initialize which leads to the Energy dashboard not working etc.
Do you have any idea what might be causing it?
Hi, they really don’t have anything in common, so the only thing I would suggest is to reduce refresh rate and see if next day it improves:
In the rest sensor change this:
scan_interval: 60
to maybe
scan_interval: 3600
which will make 1 query every 1 hour.