muppet3000 / homeassistant-grott

Home Assistant Integration for Grott - MQTT
MIT License
76 stars 17 forks source link

Entity "Load Consumption Energy (AC) - Today (Calculated)" from integration grott has state class total_increasing, but its state is not strictly increasing #94

Open BobC76 opened 2 months ago

BobC76 commented 2 months ago

Just going through errors and warnings in my logs, and saw this, tells me to create a bug report :)

I've noted there is indeed a step down in the value: image Looking more closely at the contributing values

{ "name": "Load Consumption Energy (AC) - Today (Calculated)", "device_class": SensorDeviceClass.ENERGY, "unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, "state_class": SensorStateClass.TOTAL_INCREASING, "icon": "mdi:home-lightning-bolt",

Import from Grid - Battery AC Charge

"func": lambda js: js['values']["etouser_tod"] - js['values']['eacharge_today'],
"divider": 10,
"unique_name": "calculated_003",

},

..it seems there's the potential for negative delta, due to offset timing for each contributing sensor to be updated: image

I guess that's coming from grott, and then from growatt itself, so I may just ignore the warning, or edit the sensor to be "total" instead? Is there any disadvantage to using 'total' instead of 'total_increasing'?

Log entry shows it affects a couple of the other calculated sensors:

Logger: homeassistant.components.sensor.recorder Source: components/sensor/recorder.py:303 integration: Sensor (documentation, issues) First occurred: 05:00:10 (4 occurrences) Last logged: 10:00:10

Entity sensor.nwctch107g_load_consumption_energy_ac_today_calculated from integration grott has state class total_increasing, but its state is not strictly increasing. Triggered by state 2.1 (2.2) with last_updated set to 2024-08-29T03:56:38.242633+00:00. Please create a bug report at https://github.com/muppet3000/homeassistant-grott/issues Entity sensor.nwctch107g_load_consumption_energy_today_2 from integration grott has state class total_increasing, but its state is not strictly increasing. Triggered by state 4.9 (5.0) with last_updated set to 2024-08-29T08:56:48.380611+00:00. Please create a bug report at https://github.com/muppet3000/homeassistant-grott/issues Entity sensor.nwctch107g_load_consumption_energy_pv_today_calculated from integration grott has state class total_increasing, but its state is not strictly increasing. Triggered by state 1.8 (1.9) with last_updated set to 2024-08-29T08:56:48.381098+00:00. Please create a bug report at https://github.com/muppet3000/homeassistant-grott/issues Entity sensor.nwctch107g_load_consumption_energy_pv_battery_today_calculated from integration grott has state class total_increasing, but its state is not strictly increasing. Triggered by state 2.6 (2.7) with last_updated set to 2024-08-29T08:56:48.385175+00:00. Please create a bug report at https://github.com/muppet3000/homeassistant-grott/issues

muppet3000 commented 2 months ago

Hi @BobC76 sorry I didn't respond to this sooner, I've only just seen it while doing some admin.

The difference between the 'total' and the 'total_increasing' sensor types is the difference between something that resets daily (total_increasing) and something that increases forever (total) it's buried somewhere in the HA documentation and you'll have to just trust me that it's implemented correctly.

As you've identified though, there is the potential for this 'calculated' value to have a negative delta based on the offset of when things are calculated, now, looking at your graphs it should always be within an acceptable percentage of the previous value. What I could do is ensure that if the value has not dropped by greater than X percentage just re-use the previous value.

I'd need to dust off my knowledge of how to get the current state of a sensor, but I think it could be done with a little bit of effort.

BobC76 commented 2 months ago

Thanks, its not a big deal, but occasionally crops up in my logs and a cursory read of what HA docs I could find seemed to favour "total" where its possible a value can go negative. Anyway happy to close "won't fix" rather than waste your time on it further.