Need some help with the energy dashboard

Hi folks,

I have a small problem and I’m unable to solve it

I count the time a boolean sensor is on

sensor:
  - platform: history_stats
    name: "Brenndauer Tag"
    unique_id: zsb_heizungsbrenner
    entity_id: binary_sensor.heizungsbrenner
    state: "on"
    type: time
    start: "{{ today_at('00:00') }}"
    end: "{{ now() }}"
  - platform: history_stats
    name: "Speicherladung Tag"
    entity_id: binary_sensor.speicherladung
    state: "on"
    type: time
    start: "{{ today_at('00:00') }}"
    end: "{{ now() }}"

with this time I calculate an enery meter

template:
    -sensor:
      - name: "Gasverbrauch"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ (states('sensor.brenndauer_tag')|float(0) - states('sensor.speicherladung_tag')|float(0)) * 4.95 }}"
      - name: "Gasverbrauch Speicherladung"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.speicherladung_tag')|float(0) * 14.84 }}"


Now I’d think everything is allright, but the Energy Dashboard shows sometimes other things I expect:

image

What went wrong?

regards
BJ70

You are basically counting Time ( The 2 first Templates )
Then You take brenndaur-tag ( time ) - speicherladung-tag ( time ) * 4.95 ( For some unknown reasons ! )
With this result ( int ) you give it a unit-of messurement: Kwh ( And call this device-class: energy, total iincreasing )

But what you have is still just Time( and int)
So what you see in the “final” graph, is TIME * 4.95 and TIME * 14.84

And for some reason you call this kWh

But where is/comes the spend Wattage into the picture ?

the factors 4.95 and 14.84 are the values in kilowatt my heater uses in the seperate modes (4,95 kW heating, 14,84 kW loading)

time is calculated in hours, so the multiplikation results kWh

So you mean that your heater is using full throttle 4.95kW vs14.84kW every hour/minute/seconds ?
Don’t you have a sensor which actually shows how much Wattage it currently use ?
Where do you get these 2 numbers from ? the spec. of your Device ?

Judging by the 2 first pictures:
At 12 feb
Brenndauer-tag about 7
speicherladung-tag about 1.1

7,2-1.1* 4.95 = roughly 30 ( im not sure why you subtract here )

speicherladung_tag’)|float(0) * 14.84

1,1* 14.84 = roughly 16

Could be the last high column, but what is it you mean ?

PS: Above calculation i assume is for a whole day ! , why you have the other results ( Hourly ) in your graph i also don’t know !

yes

yes

manual

Ok, Good Luck

bad luck for me because that was what I asked for

No you didn’t, you did not specify anything, and still don’t
However, You add 2 Daily “Sums” to your current hourly default energy-sensor(gas-sensor)

How to help us help you - or How to ask a good question.

but that didn’t answer the question why there are runaway-values in the dashboard.

However, I think it has something to do with rebooting my HA

hmmmm, just wait for your next total_increase (daily) sums you keep adding several times a day, then you’ll figure out it’s not only when you restart

Try adding availability templates to your energy template sensors:

template:
    -sensor:
      - name: "Gasverbrauch"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ (states('sensor.brenndauer_tag')|float(0) - states('sensor.speicherladung_tag')|float(0)) * 4.95 }}"
        availability: "{{ has_value('sensor.brenndauer_tag') and has_value('sensor.speicherladung_tag') }}"
      - name: "Gasverbrauch Speicherladung"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.speicherladung_tag')|float(0) * 14.84 }}"
        availability: "{{ has_value('sensor.speicherladung_tag') }}"

During home assistant start up the source sensors may not be available before the template sensors and the float(0) filters will render the state values with your specified default of 0.

This will stuff the energy dashboard right up. The availability templates should prevent this occurring.

some value → 0 → some value: add the entire value to the energy used.
some value → unavailable → some value: do nothing.

I don’t see any evidence of this in your history graphs but you may not have shown the times this occurred.

BTW this 3rd party integration may be an easier way to do it:

Look at his first time-sensor, and his sum-up sensor, which he then adds to his energy-dashboard ( not sure if it’s as another source, or as individual device )
He don’t seems to understand that people needs to know what his is doing and why
Seems like he sums up all ( in total-increasing ) and adds to the default-source, at un-given times ( in first pictures days ago, twice ), and his sum keep increasing ( for obvious reasons )

Looks like they are multiplying the time the device is on by the energy used per unit time. Which is fine.

1 Like

the addition of availability had no effect.

I’ll give powercalc a try

I think these 2 pictures pretty mush says it all, and as you say Tom’s advice didn’t solve your issue, and you haven’t presented anything that looks like a solution, i suggest you remove the “Solved” tag, as others unaware might try to follow your example, not knowing what they are doing, either
28e42587fa41786d92d76657440689f9e60ebc2b_2_690x366
b44da99bf67315745cdb8321482b456d3624f8de_2_690x357

Part of Tom’s answer was to suggest to use powercalc, which works for them.

1 Like

This is inappropriate. You could’ve replied without the personal attack.

Yes, PowerCalc is absolute the best and easiest way

I was just trying to show/explain for OP “what went wrong” , before suggesting anything. , i was very “confused” weather he really understood, and what his purpose was.
Turned out he did really have a power-sensor, not sure why he didn’t use that, and the way he answered turn me off.