bogdan1
(Bogdan)
November 15, 2024, 12:13pm
1
After a HA reset I’ve got some big values for my history stats
- platform: history_stats
name: Time active heating living
entity_id: sensor.living_th_status
state: "heating"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"
- platform: history_stats
name: Time active heating kitchen
entity_id: sensor.bucatarie_th_status
state: "heating"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"
- platform: history_stats
name: Time active heating bathroom
entity_id: sensor.baie_th_status
state: "heating"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"
- platform: history_stats
name: Time active heating bedroom
entity_id: sensor.dorm_th_status
state: "heating"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"
- platform: history_stats
name: Time active heating portprosop
entity_id: switch.portprosop_switch
state: "on"
type: time
start: "{{ 0 }}"
end: "{{ now() }}"
All configured the same, but 2 of them show that value. Before restart it worked.
Any ideeas?
Thanks!
tom_l
November 15, 2024, 9:22pm
2
bogdan1:
start: "{{ 0 }}"
Does your recorder database history go back to Thursday, 1 January 1970 12:00:00 AM?
That’s what you are asking it to do.
Related issue:
opened 01:50PM - 02 Sep 24 UTC
integration: history_stats
### The problem
Odd values are generated when creating a new History Stats time… based sensor if the duration is set longer than the Recorder purge days. The issue is described in this community thread: https://community.home-assistant.io/t/history-stats-not-working-as-expected/766212
### What version of Home Assistant Core has the issue?
core-2024.8.3
### What was the last working version of Home Assistant Core?
_No response_
### 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
```yaml
- platform: history_stats
name: 'Fruit Trees Valve 10 Day On Time'
entity_id: switch.fruit_trees_valve
state: "on"
type: time
end: "{{ now() }}"
duration:
days: 10
```
### Anything in the logs that might be useful for us?
```txt
No errors appear to be generated.
```
### Additional information
This could be either a bug fix or a suggestion. If it's a bug, the fix would be to prevent the History Stats sensor to attempt to include any data (that doesn't exist) if the Recorder Purge value is set to a shorter time than the History Stats time duration.
If this can't easily be fixed, then one option would be to update the History Stats code to read the current Recorder purge duration and generate a message (or error) telling the user that the results will be inaccurate unless the Recorder purge value is increased or the History Stats duration is decreased to match the Recorder value.
As a last option, the documentation should be updated to mention that the History Stats time based values will be inaccurate if the duration is set to a longer time than the Recorder. Currently the documentation only indicates that the values will be based on the length of time set in the Recorder purge_days, but fails to mention that those results can be wildly inaccurate.
A PR has been drafted to address this issue. It may make it into a future release but until then you should adjust your start time to only extend back as far as your recorder purge keep days (10 days by default).
Also just FYI if you are expecting this to record stats for all time this will not work. It can only use what is in your recorder database (10 days).