core icon indicating copy to clipboard operation
core copied to clipboard

History stats sensor (type "time") shows incorrect values

Open Al-Dek opened this issue 10 months ago • 4 comments

The problem

History stats sensor ( "time" type) shows incorrect values and has strange behavior.

What version of Home Assistant Core has the issue?

Core 2024.2.5

What was the last working version of Home Assistant Core?

core-2024.2.5

What type of installation are you running?

Home Assistant OS

Integration causing the issue

History

Link to integration documentation on our website

https://www.home-assistant.io/integrations/history_stats/

Diagnostics information

I am checking for a VPN connection via binary_sensor.192_168_1_1 (friendly name "Home (XXXX 3/9)") I get statistics on connection quality for the current day and for 10 days of history using sensors : #---------------------- VPN Fault Duration Today -------------------------------

  • platform: history_stats name: vpn_fault_duration_today type: time
    unique_id: vpn_fault_duration_today entity_id: binary_sensor.192_168_1_1 state: "off" start: "{{ today_at() }}" end: "{{ now() }}" #---------------------- VPN Fault Count Today ----------------------------------
  • platform: history_stats name: vpn_fault_count_today type: count unique_id: vpn_fault_count_today entity_id: binary_sensor.192_168_1_1 state: "off" start: "{{ today_at() }}" end: "{{ now() }}" #---------------------- VPN Service Availability Today -------------------------
  • platform: history_stats name: vpn_fault_ratio_today type: ratio unique_id: vpn_fault_ratio_today
    entity_id: binary_sensor.192_168_1_1 state: "on" start: "{{ today_at() }}" end: "{{ now() }}"

#---------------------- VPN Fault Duration Last 10 days ------------------------

  • platform: history_stats name: vpn_fault_duration_10d type: time
    unique_id: vpn_fault_duration_10d entity_id: binary_sensor.192_168_1_1 state: "off" end: "{{ now() }}" duration: days: 10

#---------------------- VPN Fault Count Last 10 days ---------------------------

  • platform: history_stats name: vpn_fault_count_10d type: count unique_id: vpn_fault_count_10d entity_id: binary_sensor.192_168_1_1 state: "off" end: "{{ now() }}" duration: days: 10

#---------------------- VPN Service Availability Last 10 days ------------------

  • platform: history_stats name: vpn_fault_ratio_10d type: ratio unique_id: vpn_fault_ratio_10d entity_id: binary_sensor.192_168_1_1 state: "on" end: "{{ now() }}" duration: days: 10

--------------------------------------------------------------

The sensors for the current day are working perfectly, without errors. Sensors for 10-days number of breaks and the 10-days ratio also work correctly. But the sensor 10-days total time of breaks (vpn_fault_duration_10d) is completely inadequate! Periodically, there is a huge increase in the total break time. After that, he begins to decrease this "value" by 15 seconds with an interval of 15 seconds until real value. Then it works fine for a while (several hours). And then everything repeats - a spike, then decreasing... No pattern of such spikes has been found.

image .. image ... image ... image ... image

Real VPN faults data exported from History...

  entity_id state last_changed
1 binary_sensor.192_168_1_1 off 2024-03-24T08:55:30.864Z
2 binary_sensor.192_168_1_1 on 2024-03-24T08:56:03.925Z
3 binary_sensor.192_168_1_1 off 2024-03-24T10:34:16.769Z
4 binary_sensor.192_168_1_1 on 2024-03-24T10:34:30.812Z
5 binary_sensor.192_168_1_1 off 2024-03-24T18:46:39.316Z
6 binary_sensor.192_168_1_1 on 2024-03-24T18:46:55.366Z
7 binary_sensor.192_168_1_1 off 2024-03-24T23:30:25.525Z
8 binary_sensor.192_168_1_1 on 2024-03-24T23:31:40.584Z
9 binary_sensor.192_168_1_1 off 2024-03-24T23:32:16.620Z
10 binary_sensor.192_168_1_1 on 2024-03-24T23:35:21.763Z
11 binary_sensor.192_168_1_1 off 2024-03-25T08:56:02.819Z
12 binary_sensor.192_168_1_1 on 2024-03-25T08:56:35.875Z
13 binary_sensor.192_168_1_1 off 2024-03-25T13:13:49.719Z
14 binary_sensor.192_168_1_1 on 2024-03-25T13:15:19.810Z
15 binary_sensor.192_168_1_1 off 2024-03-25T17:46:46.441Z
16 binary_sensor.192_168_1_1 on 2024-03-25T17:47:00.487Z
17 binary_sensor.192_168_1_1 off 2024-03-26T13:15:20.371Z
18 binary_sensor.192_168_1_1 on 2024-03-26T13:15:53.424Z
19 binary_sensor.192_168_1_1 off 2024-03-27T13:15:53.023Z
20 binary_sensor.192_168_1_1 on 2024-03-27T13:16:26.084Z
21 binary_sensor.192_168_1_1 off 2024-03-27T18:13:27.914Z
22 binary_sensor.192_168_1_1 on 2024-03-27T18:13:41.961Z
23 binary_sensor.192_168_1_1 off 2024-03-28T13:16:30.260Z
24 binary_sensor.192_168_1_1 on 2024-03-28T13:17:03.318Z
25 binary_sensor.192_168_1_1 off 2024-03-28T18:00:51.374Z
26 binary_sensor.192_168_1_1 on 2024-03-28T18:01:05.421Z
27 binary_sensor.192_168_1_1 off 2024-03-29T13:17:14.193Z
28 binary_sensor.192_168_1_1 on 2024-03-29T13:17:30.234Z
29 binary_sensor.192_168_1_1 off 2024-03-30T13:17:39.384Z
30 binary_sensor.192_168_1_1 on 2024-03-30T13:18:12.445Z
31 binary_sensor.192_168_1_1 off 2024-03-30T19:16:29.128Z
32 binary_sensor.192_168_1_1 on 2024-03-30T19:16:45.175Z
33 binary_sensor.192_168_1_1 off 2024-03-31T13:18:10.690Z
34 binary_sensor.192_168_1_1 on 2024-03-31T13:18:43.748Z
35 binary_sensor.192_168_1_1 off 2024-03-31T17:40:15.846Z
36 binary_sensor.192_168_1_1 on 2024-03-31T17:40:29.893Z
37 binary_sensor.192_168_1_1 off 2024-04-01T09:49:15.225Z
38 binary_sensor.192_168_1_1 on 2024-04-01T09:58:40.630Z
39 binary_sensor.192_168_1_1 off 2024-04-01T13:18:43.214Z
40 binary_sensor.192_168_1_1 on 2024-04-01T13:19:16.297Z
41 binary_sensor.192_168_1_1 off 2024-04-01T17:53:11.059Z
42 binary_sensor.192_168_1_1 on 2024-04-01T17:53:25.105Z
43 binary_sensor.192_168_1_1 off 2024-04-02T13:19:16.966Z
44 binary_sensor.192_168_1_1 on 2024-04-02T13:19:50.020Z
45 binary_sensor.192_168_1_1 off 2024-04-02T16:05:12.135Z
46 binary_sensor.192_168_1_1 on 2024-04-02T16:05:26.179Z

Example YAML snippet

No response

Anything in the logs that might be useful for us?

There are no any related errors/warnings in the logs.
HA restart or host reboot does not solver problem.

Additional information

No response

Al-Dek avatar Apr 03 '24 16:04 Al-Dek