Tibber - Schedul prices upcoming 24 hours prices!

Thank you for the update

Sure, no Problem.

i use the following sensors for these dashboards:
Tibber-Rest-API-Sensors
Tibber-Template-Sensors (via Configuration.yaml)
Tibber-Template-Sensors (via UI)

image
Column 1
Column 2
Column 3

image
Column 1
Column 2
Column 3

If there´s a missing sensor, please tell me. That are a lot of sensors on this two views :slight_smile:

6 Likes

Hi,

I wanted to ask what logic you use to charge your battery when the solar forecast is bad and the price range at Tibber is high?

…in order to then charge the battery at a certain speed at the most favorable time.

I´ve created a template-switch with the following code to tell my system if it should charge from grid or not:

{% set min_price = state_attr("sensor.electricity_price_wester_esch_26b","min_price") | float(default=0) %}
{% set max_price = state_attr("sensor.electricity_price_wester_esch_26b","max_price") | float(default=0) %}
{% set price = states("sensor.electricity_price_wester_esch_26b") | float(default=0) %}
{% set price_range = max_price - min_price %}
{% set price_above_min = price - min_price %}
{% set price_below_max = max_price - price %}
{% set price_level = (price_above_min / price_range) * 100 %}
{% set price_difference_to_max = (price_below_max / price_range) * 100 %}
{% set price_min_tomorrow = (states("sensor.template_tibber_price_min_tomorrow") | float(default=0.3) * 1.2) | float(default=0) %}

{% set house_power = states("sensor.senec_house_power") | int(default=0) %}
{% set solar_power = states("sensor.senec_solar_generated_power") | int(default=0) %}

{% set solar_energy_expected = states("sensor.solar_restproduktion_heute") | float(default=0) %}
{% set charge_from_grid_below_expected_energy = states("input_number.laden_bei_restproduktion_unter") | float(default=0) %}

{% if solar_power < house_power and price_difference_to_max > 50 and solar_energy_expected < charge_from_grid_below_expected_energy and price < price_min_tomorrow %}
  true
{% else %}
  false
{% endif %}

The logic behind this is:

IF i get less power from solar then my house uses (so no energy would be fed into battery)
AND on a scale from min_today_price to max_to_price the current price is more then 50% away from the max_price
AND the expected solar energy for today is below an input_number-value (for me: 15 kWh)
AND the current price is lower then the lowest price tomorrow

With an automation i control my “load from grid”-switch for my battery. Sadly i have no option to control the speed that the battery charges with.

1 Like

Mh…wasn´t happy with the sensor. Did some changes. Here is the updated code (i will have to see, if that works better for me)

{% set min_price = state_attr("sensor.electricity_price_wester_esch_26b","min_price") | float(default=0) %}
{% set max_price = state_attr("sensor.electricity_price_wester_esch_26b","max_price") | float(default=0) %}
{% set price = states("sensor.electricity_price_wester_esch_26b") | float(default=0) %}
{% set price_range = max_price - min_price %}
{% set price_above_min = price - min_price %}
{% set price_below_max = max_price - price %}
{% set price_level = (price_above_min / price_range) * 100 %}
{% set price_difference_to_max = (price_below_max / price_range) * 100 %}
{% set price_min_tomorrow = states("sensor.template_tibber_price_min_tomorrow") | float(default=0) + 0.05 %}

{% set house_power = states("sensor.senec_house_power") | int(default=0) %}
{% set solar_power = states("sensor.senec_solar_generated_power") | int(default=0) %}

{% set solar_energy_expected = states("sensor.solar_restproduktion_heute") | float(default=0) %}
{% set charge_from_grid_below_expected_energy = states("input_number.laden_bei_restproduktion_unter") | float(default=0) %}

{% set battery_state = states("sensor.senec_system_state") %}

{% if solar_power < house_power and price_difference_to_max > 50 and solar_energy_expected < charge_from_grid_below_expected_energy and price <= (min_price + 0.02) and price < price_min_tomorrow and battery_state != "AKKU VOLL" %}
  true
{% else %}
  false
{% endif %}
1 Like

Thank you for your feedback, that helps me a lot :slight_smile:

Because in my case I “work” with a small balcony power plant, I have to act a little differently :wink:

For this I would like to determine the number of hours in which the price is above a certain limit

But I’m not really making any progress with the code. Does anyone have an idea about this?

Well, I already have the max value…

{{ ((state_attr('sensor.tibber_prices', 'today') | map(attribute='total') | max | default(0.0)) * 100) | float | round(2) }}

EDIT1:
Ok, counting prices over x value in future time works: :slight_smile:

  {{ ((state_attr('sensor.tibber_prices', 'today') | selectattr('startsAt', 'ge', now().strftime('%Y-%m-%dT%H:00:00.000+02:00')) | selectattr('total', 'ge', 0.30) | map(attribute='total') | list | count )) }}
1 Like

Maybe this is the right thing for your needs => GitHub - TheFes/cheapest-energy-hours: Jinja macro to find the cheapest energy prices

After you´ve installed that via Hacs, you will need to setup a trigger-template-sensor like this

template:
  - trigger:
      - platform: time_pattern
        hours: "/1"
      - platform: homeassistant
        event: start
    action:
      - service: tibber.get_prices
        data:
          start: "{{ (today_at() - timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S') }}"
          end: "{{ (today_at() + timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S') }}"
        response_variable: prices
    sensor:
      - unique_id: tibber_cheap_energy_hours
        name: tibber_cheap_energy_hours
        state: "{{ prices.prices.values() | first | selectattr('start_time', '<=', now()) | map(attribute='price') | list | last }}"
        attributes:
          prices: >
            {% set ns = namespace(prices=[]) %}
            {% for i in prices.prices.values() | first %}
              {% set n = dict(start_time = i.start_time.isoformat(), price = i.price) %}
              {% set ns.prices = ns.prices + [n] %}
            {% endfor %}
            {{ ns.prices }}

and could then use the templates to get the best hours to charge from grid - for expample like this

{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{% set output = cheapest_energy_hours(sensor='sensor.tibber_cheap_energy_hours', hours=2.25, start='12:00', end=today_at('19:00') + timedelta(days=1), look_ahead=true) %}
{{ output }}

i haven´t really looked much into this, but it seems very useful.

1 Like

Become an error in the template editor :frowning:

TypeError: '>' not supported between instances of 'str' and 'datetime.datetime'

I don´t get this error in my instance. Maybe you could take a look at Issues · TheFes/cheapest-energy-hours · GitHub ?

image

My solution seems to work fine for me. It charged my battery from 02:00 to 05:00 while the price was (relativly) cheap before the peak in the morning. :slight_smile:

2 Likes

Now it works with

  {% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
  {% set output = cheapest_energy_hours (sensor='sensor.tibber_cheap_energy_hours', hours=2.25, start='12:00', end=today_at('19:00') + timedelta(days=1), look_ahead=true) %}
  {{ output }}

this result

2024-10-22T21:45:00+02:00

Looks good, can you share Apex-Code :wink:
image

Sure. Here it is :slight_smile:

type: custom:apexcharts-card
card_mod:
  style: |
    #state__value > #state {
      font-size: 1.2em !important;
    }
    .apexcharts-tooltip-series-group {
      padding-top: 0px !important;
      padding-bottom: 0px !important;
      margin-top: 0px !important;
      margin-bottom: 0px !important;
      display: none;
      text-align: left;
      justify-content: left;
      align-items: center;
    }
    #header {
        padding: 1rem !important;
    }  
experimental:
  color_threshold: true
apex_config:
  grid:
    show: true
    borderColor: "#E0E0E0"
  chart:
    height: 375px
    offsetY: 0
  legend:
    show: true
  tooltip:
    enabled: true
    followCursor: false
    x:
      show: true
    fixed:
      enabled: false
header:
  show: true
  show_states: true
  colorize_states: true
  standard_format: false
graph_span: 48h
now:
  show: true
  color: 9E9E9E
  label: jetzt
span:
  end: day
  offset: +12h
yaxis:
  - id: Preis
    apex_config:
      tickAmount: 10
      forceNiceScale: true
      decimalsInFloat: 0
  - id: Netzladen
    min: 0
    max: 100
    show: false
series:
  - entity: sensor.tibber_prices
    yaxis_id: Preis
    show:
      in_header: before_now
      name_in_header: true
      header_color_threshold: true
      legend_value: false
    name: Preis
    color_threshold:
      - value: 0
        color: lime
      - value: 15
        color: green
      - value: 20
        color: Khaki
      - value: 25
        color: Gold
      - value: 30
        color: darkorange
      - value: 35
        color: orangered
      - value: 40
        color: red
    type: line
    curve: stepline
    extend_to: false
    stroke_width: 2
    float_precision: 2
    data_generator: |
      const noon = new Date()
      noon.setHours(0, 0, 0, 0)
      const prices = entity.attributes.today.concat(entity.attributes.tomorrow);
      const data = [];
      for(let i = 0; i < prices.length; i++) {
        data.push([noon.getTime() + i * 1000 * 3600, prices[i].total * 100])
      }
      return data;
  - entity: sensor.tibber_prices
    transform: return x * 100
    name: Preis je kWh
    yaxis_id: Preis
    show:
      in_header: false
      name_in_header: false
      header_color_threshold: false
      legend_value: false
      in_legend: false
    color_threshold:
      - value: 0
        color: lime
      - value: 15
        color: green
      - value: 20
        color: Khaki
      - value: 25
        color: Gold
      - value: 30
        color: darkorange
      - value: 35
        color: orangered
      - value: 40
        color: red
    type: line
    curve: stepline
    extend_to: false
    stroke_width: 2
    float_precision: 2
  - entity: binary_sensor.akku_aus_dem_netz_laden
    color: var(--energy-grid-consumption-color)
    yaxis_id: Netzladen
    name: Netzladen
    transform: "return x === 'on' ? 100 : 0;"
    type: area
    curve: stepline
    stroke_width: 0
    opacity: 0.3
    extend_to: now
    show:
      in_header: false
      legend_value: false
  - entity: sensor.senec_battery_charge_percent
    color: teal
    name: Speicher
    yaxis_id: Netzladen
    type: area
    curve: stepline
    stroke_width: 1
    opacity: 0.1
    show:
      legend_value: false
    extend_to: now

1 Like

Thanks for the code :slight_smile:

I also built something similar :wink:
image

1 Like

Hi Ingo, wow that is perfect but one Question what cards you are using? It doesn’t look like that for me? everything is mixed up.

This ist only apex Charts with minimalist Theme. Can you Show me a picture of your Card?

How i can show tibber prices from last day(s)?
image

Here my APEX-Code :wink:

type: custom:apexcharts-card
header:
  show: true
  title: Preis & Batterie
  show_states: true
  colorize_states: true
now:
  show: true
  label: ""
graph_span: 48h
span:
  end: day
  offset: "-24"
apex_config:
  dataLabels:
    enabled: true
    distributed: true
  yaxis:
    - id: Tibber
      opposite: false
      decimalsInFloat: 0
      max: 50
      min: 0
      tickAmount: 5
    - id: Batterie
      opposite: true
      decimalsInFloat: 0
      max: 100
      min: 0
      tickAmount: 5
    - id: kWh
      opposite: true
      decimalsInFloat: 0
      max: 1000
      min: 1
      tickAmount: 1
series:
  - entity: sensor.tibber_prices
    name: Tibber
    yaxis_id: Tibber
    show:
      in_header: before_now
      name_in_header: false
      legend_value: false
      in_chart: true
      in_brush: true
    color_threshold:
      - value: 0
        color: 4DD0E1
      - value: 10
        color: 26A69A
      - value: 15
        color: 4CAF50
      - value: 20
        color: 7CB342
      - value: 25
        color: FBC02D
      - value: 30
        color: EF6C00
      - value: 40
        color: B71C1C
    type: line
    curve: stepline
    extend_to: false
    stroke_width: 1
    float_precision: 2
    data_generator: |
      const noon = new Date()
      noon.setHours(0, 0, 0, 0)
      const prices = entity.attributes.today.concat(entity.attributes.tomorrow);
      const data = [];
      for(let i = 0 ; i < prices.length; i++) {
        data.push([noon.getTime() + i * 1000 * 3600, prices[i].total * 100])
      }
      return data;
  - entity: sensor.delta_2_max_battery_level
    name: Batterie
    yaxis_id: Batterie
    stroke_width: 1
    float_precision: 0
    extend_to: false
    show:
      legend_value: false
      in_header: true
    group_by:
      duration: 15m
      func: avg
  - entity: sensor.tasmota_bkw_bat_in_energy_power
    name: Laden
    yaxis_id: kWh
    type: area
    stroke_width: 1
    float_precision: 0
    extend_to: false
    show:
      legend_value: false
      in_header: false
    group_by:
      duration: 1m
      func: avg
  - entity: sensor.tasmota_bkw_mwr_out_energy_power
    name: Einspeisung
    yaxis_id: kWh
    type: area
    stroke_width: 1
    float_precision: 0
    extend_to: false
    show:
      legend_value: false
      in_header: false
    group_by:
      duration: 15m
      func: avg
  - entity: sensor.solarproduktion_gesamt_akt
    name: Solar
    yaxis_id: kWh
    type: area
    stroke_width: 1
    float_precision: 0
    extend_to: false
    show:
      legend_value: false
      in_header: false
    group_by:
      duration: 15m
      func: avg
1 Like

Hello Ingo, these sensors are missing
or where do I get them?

  • sensor.electricity_generation_stand
  • sensor.electricity_generation_previously
  • sensor.tibber_stand_zahler_einspeisung
  • sensor.einspeisegeuhr_im_current_jahr
  • sensor.tibber_stand_payer_reference
  • sensor.power consumption_kwh_previously
  • sensor.template_tibber_consumption_year
  • sensor.template_tibber_cost_year
  • sensor.template_tibber_consumption_per_month
  • sensor.template_tibber_kosten_je_kwh_jahr_ohne_grundgebuhr
  • sensor.template_tibber_kosten_je_kwh_jahr
  • sensor.tibber_monthly_consumption
  • sensor.tibber_api_kosten_aktueller_monat

Greetings Alex

Does nobody have an idea where one can display the prices from the past (a few days ago) and those of the future in a curve?

With a bit of fiddling and trail and error, I was able to realise the suggestion presented here for myself and would like to start by thanking you for it. Strangely, however, I can’t get any historical values for my Tibber price. Does anyone have any ideas?

Hi Ingo,

first thank you much sharing your awesome Tibber Card with Storage charging evaluation. Exactly what i need!

Could you please please update your first post from 01.2024 to the actual code changes? Also for me as a beginner it woud be great to get some more information at which path in homeassistant the Code fragments must be added.

Thanks a lot in advance!

1 Like