Calculate my current electricity costs from my Tibber

Hello everyone,

I would like to calculate my current electricity costs from my Tibber tariff using a function.

I thought I could perform an action on this because the sensor.accumulated_consumption_current_hour value changes.
However, I would then need the last value before the change and the electricity price of the last hour for the calculation.

Do you perhaps have an idea how one could represent such a calculation/function?
Or does such a function already exist?

Best regards

Hello,

It looks like I have found a simple solution for calculating electricity prices, the Tariffs. :grinning:

However, as a comparison, I would like to compare the price of a second electricity provider, but without these two providers being added together in the energy dashboard.

Is there a solution for this?

Hello,

I have another question. For my alternative electricity provider, I would like to switch the electricity price between main and off-peak tariffs.

For this I have created two helpers. One that gives me a switch for off-peak hours (10 p.m. - 6 a.m.) and one in which I can then write the corresponding electricity price.

The switchover in the automation should then look like this:

alias: Strompreis Stadtwerke Tag/Nacht Umschaltung
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.nachtstrom_aktiv
condition: []
action:
  - if:
      - condition: state
        entity_id: binary_sensor.nachtstrom_aktiv
        state: "on"
    then:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke
      data:
        state: "0.33"
    else:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke
      data:
        state: "0.35"
mode: single

Unfortunately, the code doesn’t seem to be correct, because the variable “input_numer.strompreis_stadtwerk” is not described in this way and an error message appears.

extra keys not allowed @ data[‘state’]


Does anyone have an idea how I can solve the problem in code?

Greetings

Ok, then I’ll continue my conversation with myself… :rofl:

This code with static values works:

alias: Strompreis Stadtwerke Tag/Nacht Umschaltung
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.nachtstrom_aktiv
condition: []
action:
  - if:
      - condition: state
        entity_id: binary_sensor.nachtstrom_aktiv
        state: "on"
    then:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke_akt
      data:
        value: "0.3271"
    else:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke_akt
      data:
        value: "0.3521"
mode: single

and this code with “value helpers” also:

alias: HA - Strompreis SWS Tag/Nacht Umschaltung
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.nachtstrom_aktiv
condition: []
action:
  - if:
      - condition: state
        entity_id: binary_sensor.nachtstrom_aktiv
        state: "on"
    then:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke_akt
      data:
        value: "{{ states('input_number.strompreis_stadtwerke_nt') | float(0) }}"
    else:
      service: input_number.set_value
      target:
        entity_id: input_number.strompreis_stadtwerke_akt
      data:
        value: "{{ states('input_number.strompreis_stadtwerke_ht') | float(0) }}"
mode: single

It would be nice if you could display the two meters separately in the Energy Dashboard and the consumption and price would not be added together.

Hello,

I liked a new entity named “verbrauch_h_akt_tibber”
create and describe it with the value from the sensor "sensor.accumulated_consumption_current_hour_tibber’'.
I entered the following into the configurations.yaml, but unfortunately the new entity does not appear.

template:
  - sensor:
      - name: "verbrauch_h_akt_tibber"
        value: '{{ state(''sensor.accumulated_consumption_current_hour_tibber'') }}'

Does anyone have an idea why this could be or what I’m doing wrong?

Ok, now it works :grinning:

The problem was a failure to restart HA, probably because it was the first template I created.

template:
  - sensor:
      - name: "Verbrauch Tibber"
        unique_id: "verbrauch_tibber"
        unit_of_measurement: "kWh"
        device_class: "energy"
        state_class: "total_increasing"
        state: >
            {{ states('sensor.accumulated_consumption_current_hour_tibber') }}
      
      - name: "Verbrauch SW"
        unique_id: "verbrauch_sw"
        unit_of_measurement: "kWh"
        device_class: "energy"
        state_class: "total_increasing"
        state: >
            {{ states('sensor.accumulated_consumption_current_hour_tibber') }}

Hello everyone,

I would like to calculate the current difference/savings between the two providers using the two entities “sensor.verbrauch_tibber_ht_nt_cost” and “sensor.verbrauch_sw_ht_nt_cost” .
This also works wonderfully with the code shown.

However, I have the problem that after restarting HA, the two entities are set to zero and the difference value is therefore lost.

Is there another way to display the current electricity costs from the energy dashboard?

- name: "Ersparnis Tibber vs. SW"
        unique_id: "strom_diff_cost"
        unit_of_measurement: "€"
        state: >
            {{ float(states('sensor.verbrauch_tibber_ht_nt_cost')) - float(states('sensor.verbrauch_sw_ht_nt_cost')) }}