sfalkman / ngenic-hass-platform

Ngenic platform for Home Assistant
MIT License
33 stars 18 forks source link

changing state_class for energy sensor #34

Closed SeaquestNet closed 3 years ago

SeaquestNet commented 3 years ago

Changing NgenicEnergySensor state_class to STATE_CLASS_TOTAL_INCREASING. This will ensure statistics are calculated correctly (instead of being treated as current measurement).

I am currently a bit unsure if last_reset should be used together with this (see docs below): https://developers.home-assistant.io/docs/core/entity/sensor/#properties

When testing it seems to work alot better then before though.

argoyle commented 3 years ago

I've made the same change in the Ferroamp-integration (https://github.com/henricm/ha-ferroamp) and I removed the last_reset attribute and it works as expected.

SeaquestNet commented 3 years ago

Yeah, you are probably right, found this: _For sensors with state_class totalincreasing, a decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter.

Will change, test it and then update code.

sfalkman commented 3 years ago

This looks good, I haven't noticed the new STATE_CLASS_TOTAL_INCREASING.
Actually, I haven't tested the new Home Energy Management that much since I'm having a lot of trouble with Home Assistant crashing (due to other reasons), that is why I haven't promoted the 2.0.0 out of beta.

I will merge this and create a new beta release.

sfalkman commented 3 years ago

Might it be that we need to bump the least supported homeassistant version for this? Currently it's at 2021.6.0: https://github.com/sfalkman/ngenic-hass-platform/blob/master/hacs.json#L4

argoyle commented 3 years ago

Yes, STATE_CLASS_TOTAL_INCREASING was introduced in 2021.9