Tibber sensor for future price (tomorrow)

I got it to work a little better after deleting alla files and downloaded it again.

But now I dont get any image. Wonder if it could be related to that i tries to show a image which is formatted like this “prices_Lusseröd 219.png” with swedish character and spaces…

hello @Danielhiversen

I would like to intergrate Tibber’s forecast prices in my Apex chart. I understand that forecast prices are not available as part of the Tibber integration. Could this be incorporated in the same way it was done for the electricity prices of Amber?

It looks like the forecast prices were implemented as attributes which can then be displayed in Apex charts.

That is not an acceptable solution for an official integration in Home Assistant.
Currently, Home Assistant does not have any good way to handle future values.

OK, I guess it was accepted for Amber since it is a custom integration. I hope there will be a way to handle this in the future, with the incorporation of the energy dashboard forecast value for electricity is definitely something to look at.

Hey! great work with this integration! Is there any way to get the max and min values for the next few hours?

Great work!
How do I add the consumption from my sensor in this camera-entity?

I have this in my config to accommodate this need:

binary_sensor:
  - platform: template
    sensors:
      nordpool_cheapest_4_hours:
        value_template: >-
          {% set l=state_attr('sensor.nordpool_kwh_oslo_nok_2_10_025', '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) }}
      nordpool_cheapest_8_hours:
        value_template: >-
          {% set l=state_attr('sensor.nordpool_kwh_oslo_nok_2_10_025', '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)
            or (now() >= l[4].start and now() <= l[4].end)
            or (now() >= l[5].start and now() <= l[5].end)
            or (now() >= l[6].start and now() <= l[6].end)
            or (now() >= l[7].start and now() <= l[7].end) }}
      nordpool_cheapest_12_hours:
        value_template: >-
          {% set l=state_attr('sensor.nordpool_kwh_oslo_nok_2_10_025', '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)
            or (now() >= l[4].start and now() <= l[4].end)
            or (now() >= l[5].start and now() <= l[5].end)
            or (now() >= l[6].start and now() <= l[6].end)
            or (now() >= l[7].start and now() <= l[7].end)
            or (now() >= l[8].start and now() <= l[8].end)
            or (now() >= l[9].start and now() <= l[9].end)
            or (now() >= l[10].start and now() <= l[10].end)
            or (now() >= l[11].start and now() <= l[11].end) }}

This gives me a binary_sensor for the hours I am looking for. For instance I automate some of the heating in the house based on the 12 cheapest hours. Hope this helps!

Note, you need to install the nordpool custom component: GitHub - custom-components/nordpool: nordpool sensor for ha.

5 Likes

Awesome! I was not aware of the nordpool integration. I wish I had this before december :slight_smile:

1 Like

Hello corvy!

I really like your solution for using Nordpool to fetch the cheapest hours.
I have added this binary_sensor to my own configuration.

There is one problem though.
First I get status ‘off’ for all three sensors, but after a short while (about 1minute max) these turn to status unavailable. The nordpool-integration is running and reporting data correctly though.

Any suggestion for this behaviour?

Home assistant version 2021.12.10

Nice , Works great, lets see tomorrow if the price is right ( for south Sweden region ) :slight_smile: , current price looks as “default_sensor” … But i wondered how you got your “Consumption” into it, as i can see it in the app ( with 1 day relay ) , but maybe you have, your own device attached to the Grid-Provider ?

Not sure mate, I would suggest checking logs and config. This setup works just fine :blush:

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!

1 Like

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:
NorpolBadge

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)

1 Like

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)
8 Likes

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);
1 Like

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.