After upgrading to 2023.3, I’ve noticed some strange behavior of some history stats sensors. They get some sudden drops, which is not what I expect from a sensor with a fixed duration and end=now()
. Some sensors seem to be unaffected, but maybe the issue just hasn’t occurred yet.
There are definitions of the troublesome sensors:
- "duration":
"minutes": !!int "20"
"name": "bathroom fan cooldown need"
"state": "on"
"entity_id": "switch.bathroom_fan"
"end": "{{ now() }}"
"type": "ratio"
"platform": "history_stats"
- "duration":
"hours": !!int "24"
"name": "fridge humidity ok last 24h ratio"
"state": "on"
"entity_id": "binary_sensor.fridge_humidity_ok"
"end": "{{ now() }}"
"type": "ratio"
"platform": "history_stats"
History of those sensors:
I had a hypothesis that the key difference is that some history stats are based on a sensor that rarely changes (so the issue doesn’t appear that frequently), while some change frequently (so there are more opportunities for this bug). However, this is currently not the case of the binary_sensor.fridge_humidity_ok. This sensor is true as long as the fridge humidity is under 60 %, so it doesn’t change that frequently. Actually, it has dropped even during the period where binary_sensor.fridge_humidity_ok was continuously on.
I’ve looked at the changelog, but there is no mention of history stats. Has anyone any idea what’s going on?
EDIT: Update: The issue seems to be bidirectional. I’ve seen a history stats sensor suddenly increasing to 100%, although it should have been just 5 %.
Also, I might have found the key for troublesome sensors. Maybe all troublesome sensors are type: ratio
and troublefree sensors are type: count
. I don’t think I use type: time
.
EDIT 2: After updating to 2023.3.1, it looks like the fridge-related sensor got fixed. But I am not sure if it is fixed just temporarily by the reboot, or fully by some code fix. I don’t see any relevant commit at Commits · home-assistant/core · GitHub .
EDIT 3: The PR Fix check on non numeric custom sensor device classes by jbouwh · Pull Request #89052 · home-assistant/core · GitHub might be related, as the source of both history stats sensors is non-numeric…