Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History Stats (type: time) problem when restarting Home Assistant #80871

Closed
hneel opened this issue Oct 24, 2022 · 11 comments
Closed

History Stats (type: time) problem when restarting Home Assistant #80871

hneel opened this issue Oct 24, 2022 · 11 comments
Labels

Comments

@hneel
Copy link

hneel commented Oct 24, 2022

The problem

I found that my History Stats sensor increases with a rather large (random?) number when I restart Home Assistant.

Here is my sensor in sensor.yaml

- platform:     history_stats
  name:         "stat_otgw_flame"
  entity_id:    binary_sensor.otgw_flame
  state:        "on"
  type:         time
  start:        "{{ now().replace(year=2022, month=5, day=14, hour=23, minute=59, second=0) }}"
  end:          "{{ now() }}"

Here is an example:
ha_gas
At around 16:xx hour you can see a sudden unexpected increase.

Here is a part of the log of the binary sensor.
hass_log

When it dawned to me that it might have something to do with restarting Home Assistant, I tried that again and could easliy reproduce the problem.

My guess is that the start time of the History Stats sensor is undefined after restarting.

What version of Home Assistant Core has the issue?

2022.10.5

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

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

- platform:     history_stats
  name:         "stat_otgw_flame"
  entity_id:    binary_sensor.otgw_flame
  state:        "on"
  type:         time
  start:        "{{ now().replace(year=2022, month=5, day=14, hour=23, minute=59, second=0) }}"
  end:          "{{ now() }}"

Anything in the logs that might be useful for us?

No response

Additional information

No response

@CaptTom9
Copy link

I had the problem again, this time right around the time I restarted HA:
image

As you can see, the value of the history_stats entity jumped from around 2 hours to over 10 hours the next time the underlying sensor went to "on." This is clearly a bug.

@hneel
Copy link
Author

hneel commented Nov 5, 2022

Is anyone looking into this yet? My guess is that it must be very easy to fix. Just check if the 'on' timestamp has been assigned a valid value, when the 'off' event occurs.

@McGagnor
Copy link

Hi all, the same problem here!
My history stats values grow to very big value.

Entity config:

  • platform: history_stats
    name: Vita_Debatterizzatore_UV
    entity_id: switch.o3
    state: "on"
    type: time
    start: "{{ 0 }}"
    end: "{{ now() }}"

image

Hope we can solve the issue, I'm available to test something if needed.
Regards.
McG

@dotdoom
Copy link

dotdoom commented Jan 15, 2023

This is also reported on community forums.

https://community.home-assistant.io/t/history-stats-sensor-creates-wrong-data/476466

cc @bdraco who's been working on significant improvements to history_stats (e.g. #73040 and #73289) recently and may have an idea.

UPD: I'm on 2022.11.5.

@LustigePerson
Copy link

Same Problem here:

  - platform: history_stats
    name: P1 ON Today
    entity_id: light.p1_lights
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

This works and sums the hours P1 has been on per day. However, If I restart HA and P1 turns on, for example at 12 o'clock the value will instantly start at 12. So if it runs for 2 hours the end sum for the day will be 14 instead of 2.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@LustigePerson
Copy link

With all Home Assistant components up-to-date this issue still persists.

@sylverstream
Copy link

sylverstream commented Jul 18, 2023

I also have the same problem, calculating how long a binary sensor has been on. Restarted HA this morning and it went from about 1h 10 minutes to 8h 15 minutes.

To be more precise, the different was 7h 19 minutes, for two historical_stats sensors measuring two different input booleans.

@wadey
Copy link

wadey commented Aug 26, 2023

I think I'm seeing the same issue, basically when I upgrade Home Assistant and it restarts, my history_stats type:time based on a binary sensor values are wrong for the next 24 hours, with odd spikes. See the screenshot, you can see the time period after I did the restart with all of the odd spikes:

IMG_7989

@github-k8n
Copy link

Same issue here. Seems it happened during the update to 2023.11.0.
Bildschirmfoto vom 2023-11-03 14-01-41

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants