core: History_stats count not working
The problem
Not sure what the issue and will try going back to 2022.4.7 today to see if issue persists. I noticed my vacation lights history_stats sensor was not working properly as it wasn’t aligning to the on/off history from a week prior (sensor 1). I have multiple versions of that sensor and they all do not work similarly. I decided to purge my database and create a new sensor (sensor 2 “replay_test”) to see if the issue persisted since I no longer had history from a week prior.
Initially replay_test worked when it was first created and the system was running for long enough for history to populate. So when I turned on that light, 30 seconds later the light would turn on. That worked the first one or two times tested, and since then no longer works just like the previous sensors. Just stays at 0 even when it should be going to 1.
What version of Home Assistant Core has the issue?
core-2022.5.3
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
history_stats
Link to integration documentation on our website
https://www.home-assistant.io/integrations/history_stats/
Diagnostics information
No response
Example YAML snippet
- platform: history_stats
name: "replay_lamps"
entity_id: light.lamps
state: "on"
type: count
start: "{{ as_timestamp(now()) - (7*86400) }}"
duration: 00:00:15
- platform: history_stats
name: "replay_test"
entity_id: light.office_light_lamp
state: "on"
type: count
start: "{{ as_timestamp(now()) - (30) }}"
duration: 00:00:15
Anything in the logs that might be useful for us?
No response
Additional information

No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (15 by maintainers)
I opened https://github.com/home-assistant/core/pull/71952 to restore the count behavior to how it was in
2022.4If its agreed upon, I’ll adjust the docs as well so we don’t have any misalignment between the docs and how the integration actually works.