history_stats delivers a wrong up time
Agomund opened this issue · comments
The problem
I have 2 history_stats to calculate the "on" time of some equipment. This worked fine, but since the change to the newest core version there is the following issue:
- if my equipment is running over midnight, then the "on" time calculation does not fit with the "on" time of the equipment. It seems to me, that it's counting the hole time from midnight until the end of the next "on" period of the equipment. So the result includes the "off" time between the run over midnight and the first run after midnight.
- if my equipment is not running over midnight, everything is okay.
What version of Home Assistant Core has the issue?
core-2022.5.5
What was the last working version of Home Assistant Core?
core-2022.5.4
What type of installation are you running?
Home Assistant OS
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
sensor:
- platform: history_stats
name: Entfeuchter ON today
entity_id: switch.shellyplus1pm_7c87ce65cbfc_switch_0
state: "on"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
- platform: history_stats
name: Entf. Atelier ON today
entity_id: switch.shellyswitch25_e8db84a9acde_channel_2
state: "on"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
Anything in the logs that might be useful for us?
No response
Additional information
No response
history_stats documentation
history_stats source
(message by IssueLinks)
I have a bit more work done for investigating the issue an I have seen, that the timestamp of the history_stat sensor and the change of the state from the switch are very narrow:
- switch changed state from "on" to "off": 22:00:32.662214
- calculation timestamp shows: 22:00:32.682934
I have no idea how the calculation is done. Only as an information, possibly meaningless.
After some more investigation I see, that the reason is not the "on" state over midnight. It seems that the coincidence of the statistic update and the state change is the origin of the problem.
Many thanks in advance for looking at that.
I'm having trouble understanding what is wrong here.
It would help if you included screenshots showing the unexpected data.