core: History_stats miscalculation: data not yet written to disk by recorder is not taken into account
The problem
I have the following in configuration.yaml:
template:
- binary_sensor:
- name: "Pompa interrata"
unique_id: pompa_interrata_attiva
icon: mdi:pump
state: >
{{ states('sensor.shelly_em50_pro_em1_power') | float(0) > 10 }}
availability: >
{{ states('sensor.shelly_em50_pro_em1_power') | float(none) != none }}
sensor:
- platform: history_stats
name: "Pompa interrata duty cycle"
entity_id: binary_sensor.test_pompa_interrata_attiva
unique_id: pompa_interrata_duty_cycle
state: "on"
type: ratio
duration: "00:30:00" # 30min
end: "{{ now() }}"
Here’s the calculated duty cycle:
Negative duty???
59 seconds / 30 minutes Expected: it should stay level at around 3% for 30 minutes Result: peak at 7% for a brief moment
What version of Home Assistant Core has the issue?
System Information version | core-2025.3.4 – | – installation_type | Home Assistant OS dev | false hassio | true docker | true user | root virtualenv | false python_version | 3.13.2 os_name | Linux os_version | 6.12.18-haos arch | x86_64 timezone | Europe/Rome config_dir | /config Home Assistant Community Store
GitHub API | ok – | – GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.5 Stage | running Available Repositories | 1621 Downloaded Repositories | 2 Home Assistant Cloud
logged_in | false – | – can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok Home Assistant Supervisor
host_os | Home Assistant OS 15.0 – | – update_channel | stable supervisor_version | supervisor-2025.03.3 agent_version | 1.7.2 docker_version | 28.0.1 disk_total | 30.8 GB disk_used | 12.1 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | kvm board | ova supervisor_api | ok version_api | ok installed_addons | File editor (5.8.0), ESPHome Device Builder (2025.3.2), Advanced SSH & Web Terminal (20.0.2), Piper (1.5.2), Music Assistant Server (2.4.4) Dashboards
dashboards | 2 – | – resources | 0 views | 2 mode | storage Network Configuration
adapters | lo (disabled), enp6s18 (enabled, default, auto), docker0 (disabled), hassio (disabled), vethbbb2966 (disabled), vethfe5a4f2 (disabled), vethdfc7652 (disabled), veth37aa873 (disabled), veth3747a93 (disabled), veth9a06d92 (disabled), vethafd6773 (disabled), veth59b9bec (disabled) – | – ipv4_addresses | lo (127.0.0.1/8), enp6s18 (192.168.102.1/24), docker0 (172.30.232.1/23), hassio (172.30.32.1/23), vethbbb2966 (), vethfe5a4f2 (), vethdfc7652 (), veth37aa873 (), veth3747a93 (), veth9a06d92 (), vethafd6773 (), veth59b9bec () ipv6_addresses | lo (::1/128), enp6s18 (fe80::2917:a985:6278:a7a8/64), docker0 (fe80::c80c:d7ff:fef6:1c65/64), hassio (fe80::248c:2bff:fe7e:637/64), vethbbb2966 (fe80::6caf:59ff:feb4:630e/64), vethfe5a4f2 (fe80::8a0:4ff:fe18:efd5/64), vethdfc7652 (fe80::5c99:d1ff:fef4:1cef/64), veth37aa873 (fe80::dcfc:41ff:fe50:551e/64), veth3747a93 (fe80::183a:99ff:fe31:5b11/64), veth9a06d92 (fe80::8857:4bff:fe36:f5c5/64), vethafd6773 (fe80::5c5e:8eff:fed7:e8a2/64), veth59b9bec (fe80::3449:e4ff:fe5e:d1d2/64) announce_addresses | 192.168.102.1, fe80::2917:a985:6278:a7a8 Recorder
oldest_recorder_run | March 20, 2025 at 00:06 – | – current_recorder_run | March 24, 2025 at 02:26 estimated_db_size | 92.09 MiB database_engine | sqlite database_version | 3.48.0
Home Assistant Community Store
GitHub API | ok – | – GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.5 Stage | running Available Repositories | 1621 Downloaded Repositories | 2Home Assistant Cloud
logged_in | false – | – can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | okHome Assistant Supervisor
host_os | Home Assistant OS 15.0 – | – update_channel | stable supervisor_version | supervisor-2025.03.3 agent_version | 1.7.2 docker_version | 28.0.1 disk_total | 30.8 GB disk_used | 12.1 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | kvm board | ova supervisor_api | ok version_api | ok installed_addons | File editor (5.8.0), ESPHome Device Builder (2025.3.2), Advanced SSH & Web Terminal (20.0.2), Piper (1.5.2), Music Assistant Server (2.4.4)Dashboards
dashboards | 2 – | – resources | 0 views | 2 mode | storageNetwork Configuration
adapters | lo (disabled), enp6s18 (enabled, default, auto), docker0 (disabled), hassio (disabled), vethbbb2966 (disabled), vethfe5a4f2 (disabled), vethdfc7652 (disabled), veth37aa873 (disabled), veth3747a93 (disabled), veth9a06d92 (disabled), vethafd6773 (disabled), veth59b9bec (disabled) – | – ipv4_addresses | lo (127.0.0.1/8), enp6s18 (192.168.102.1/24), docker0 (172.30.232.1/23), hassio (172.30.32.1/23), vethbbb2966 (), vethfe5a4f2 (), vethdfc7652 (), veth37aa873 (), veth3747a93 (), veth9a06d92 (), vethafd6773 (), veth59b9bec () ipv6_addresses | lo (::1/128), enp6s18 (fe80::2917:a985:6278:a7a8/64), docker0 (fe80::c80c:d7ff:fef6:1c65/64), hassio (fe80::248c:2bff:fe7e:637/64), vethbbb2966 (fe80::6caf:59ff:feb4:630e/64), vethfe5a4f2 (fe80::8a0:4ff:fe18:efd5/64), vethdfc7652 (fe80::5c99:d1ff:fef4:1cef/64), veth37aa873 (fe80::dcfc:41ff:fe50:551e/64), veth3747a93 (fe80::183a:99ff:fe31:5b11/64), veth9a06d92 (fe80::8857:4bff:fe36:f5c5/64), vethafd6773 (fe80::5c5e:8eff:fed7:e8a2/64), veth59b9bec (fe80::3449:e4ff:fe5e:d1d2/64) announce_addresses | 192.168.102.1, fe80::2917:a985:6278:a7a8Recorder
oldest_recorder_run | March 20, 2025 at 00:06 – | – current_recorder_run | March 24, 2025 at 02:26 estimated_db_size | 92.09 MiB database_engine | sqlite database_version | 3.48.0What 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
see above
Anything in the logs that might be useful for us?
no related errors
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (7 by maintainers)
I’ll try a PR for that. I think it would be more elegant and also fix https://github.com/home-assistant/core/issues/140007 which I believe also stems from commit_interval issues.
Anyone who wishes to comment is free to comment and give their opinion here.