Energy dashboard: drop last-reset concept

I saw the last_reset is needed to make stuff function, but almost no integrations are using this and the whole concept is not needed als far as I’m seeing. Take a resetting counter:

counter:diff
0:NaN
10:10
15:5
2:-13 → it’s reset. Discard value, use 2 and generate timestamp

This is how influx (non negative derivative) or elastic/kibana (positive rate) do it as well. My kwh counters have been working perfectly for years without the need of such a topic.

Why bother with an extra topic where providers need to implement this exact same logic themselves?

Yes please remove this constraint that breaks many integrations.
Apparently it is not needed anyway.

Alternatively give the capability to add this attribute in template with a dummy value.
Currently the only work around that seems to work is to use of utility_meter integration

It’s already done. Add support for total and total_increasing sensor state classes by emontnemery · Pull Request #54523 · home-assistant/co

2 Likes

Wonderful :smile:

You seems to be very knowledgeable about sensor. May I ask you a few questions related to energy monitoring and long-term statistics?

I just read the “Sensor entity” documentation Sensor Entity | Home Assistant Developer Docs

It seems, if I understand correctly, that long-term statistics requires specific properties. One of them is that the state_class should be set to measurement. But apparently more are required for this work.

I am using a ESP device that it programmed with the telinfo device (Teleinformation from Linky electrical counter. — ESPHome). It read information transmitted by an electrical meter connected to the grid like total energy since installed, voltages (plural as I have three-phases), intensities, instantaneous power, etc.

As already said unfortunately the energy reading from this integration cannot be used directly and as a workaround, I use an utility_meter.

I was hoping to use the statistic graph card on some other sensor but it does not work and I do not know why? For example I have a sensor for the current I added some directives in the sensor declaration and now it looks like that:

state_class: measurement
unit_of_measurement: A
friendly_name: Grid I1
device_class: current

Seems like I have all requested properties? However, it does not work? Do you why and how to fix it?

I don’t know about the statistics card. For the energy panel you need

  • device_class: energy
  • unit: Wh or kWh
  • state_class: currently measurement; next release any of the 3 (see PR in post above)
  • last_reset: time of Last reset or 0-timestamp; next release this will not be needed necessarily / even be deprecated

So you see there is a lot of shuffling around currently. I’d just wait until 2021.9 (2,5 Weeks) or maybe even another release - for the dust to settle.

With both, statistics and energy, a new value is created every hour (I think 12min past the hour) so it takes some time for the graphs to appear.

Yep, dropping last_reset is totally needed. Additionally for the state_class, it should be total_increasing instead of measurement. Guess we will change our configuration once new release hits.

This is great.
Currently I am using a utility meter as a workaround but unfortunately for total_increasing type of sensor it does not work perfectly: each time HA is restarted (this happen a lot as I am experimenting with Energy management and statistics) the utility meter report increasingly wrong value.
see Utility meter sensor reports wrong value after HA restart · Issue #54932 · home-assistant/core · GitHub
PR has been closed for reasons I understand (even though I would not have it implemented like that)

I hope new features will make it 2021.9

The newest update 2021.10 broke it now even more.

last_reset: 0

crashes the entire recorder.

last_reset: '0'

gives an invalid warning and the sensor is not showing up in the dashboard.

last_reset: '01-01-2020 00:00:00' 

gives also an invalid warning and the sensor is not showing up in the dashboard.

removing last_reset, gives a warning in the dashboard that last_reset is missing.

So atm I see no way to repair my energy dashboard.

Ok I fixed it with:

last_reset: '2000-01-01T00:00:00'

Where do you put this line of code?

The new problem:

Old template style dont support state_class.

New template: only support measurement .
And energy asks for last_reset…

Edit:

Docs are outdated. Total_increasing is supported now

I set it as customization values.

Either in the UI:

Or in the file directly:

sensor.wlan_switch_energy_total:
  state_class: measurement
  icon: mdi:chart-histogram
  device_class: energy
  last_reset: '2000-01-01T00:00:00'