home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.14k stars 29.81k forks source link

Faulty history time accrual with history_stats while trackable binary mqtt sensor value passes midnight #84361

Closed tarmor1 closed 1 year ago

tarmor1 commented 1 year ago

The problem

Hi all! I have a history stats sensor calculating daily ON time for my domestic water pump on MQTT binary sensor (YAML for both of their configs attached below). That is, history time accrues when pump is ON and resets back to 0.00h at midnight. I have observed once that if the ON event starts right before midnight and ends after midnight (eg, being ON while the dates change), the history stats counts the ON time until the next event on observed entity, assuming ON the whole time. As you can observe from the screenshots attached from Log, the pump was switched on at 23:59:40, and off 00:00:05. Yet history wise, time was appended until 04:43:31, when the next plugged-in event happened.

What version of Home Assistant Core has the issue?

core-2022.12.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Statistics

Link to integration documentation on our website

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

Diagnostics information

stats_example log_example

Example YAML snippet

- platform: history_stats
    name: Water_pump_on_time_today
    entity_id: binary_sensor.water_pump
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

mqtt:
  binary_sensor:
   - name: "Water pump"
     state_topic: "water_pump_pinger"
     device_class: plug
     payload_on: "ON"
     payload_off: "OFF"
     expire_after: 180

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @fabaff, @thomdietrich, mind taking a look at this issue as it has been labeled with an integration (statistics) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `statistics` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign statistics` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


statistics documentation statistics source (message by IssueLinks)

home-assistant[bot] commented 1 year ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (history) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `history` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign history` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


history documentation history source (message by IssueLinks)

issue-triage-workflows[bot] commented 1 year ago

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.