Count the time door was open during a month

Looking for some kind of a timer to have the statistics for how long the door was opened during a month.

History Stats to track the time open per day.

Utility Meter to aggregate the daily values into a monthly value.

3 Likes

Thanks for the history stats. Seemed like a perfect solution. But getting strange behavior. Set up the sensor for today.

  - platform: history_stats
    name: history door veranda open today
    entity_id: binary_sensor.door_veranda
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

And don’t get any update. Although on the door card i can clearly see all events registered

So you can see the new sensor, but the value isn’t what you expect? Did you restart? What does the history for the source sensor look like?

The History Stats sensor will report time in hours with two decimal places. That means the smallest increment of (displayed) time is 0.01 hours or 36 seconds.

If the door has been left open 3 times at 10 seconds each, that’s a total of 30 seconds which is 6 seconds short of 0.01.

However, if you are certain that the door’s cumulative “open time” has easily exceeded 36 seconds, and the History Stats sensor reports 0.00, then there may indeed be a problem with its configuration (or the referenced binary_sensor).

1 Like

Thanks! Excellent explanation. That is the case. Not a programmer at all but

from homeassistant.const import (
    CONF_ENTITY_ID,
    CONF_NAME,
    CONF_STATE,
    CONF_TYPE,
    CONF_UNIQUE_ID,
    PERCENTAGE,
    UnitOfTime,

Unit of time is hardcoded? Or can be overridden? Cutomize?

You’re welcome!

However you should mark Didgeridrew’s post with the Solution tag (not mine) because it is the one that suggested to use a History Stats sensor, and Utility Meter integration, to achieve your goal (how long the door was opened during a month).