Counter For Sensor On Time Each Day

I have a binary sensor for which I’d like a counter for minutes in ‘on’ state for each day so that I can show a bar graph in the UI with daily usage (i.e. one bar pr. day). What would be the best way to accomplish this?

Create a History Stats sensor to report the binary sensor’s total ‘on’ time for the current day.

Use the History Stats sensor with the Utility Meter integration to report daily/weekly/monthly/yearly stats.

Example

1 Like

Thanks for the tip!

I don’t think I will be needing the utility meter though as I cannot use them for bar-graphs.

I’m also having an issue when trying to plot the history_stats sensor in a bar graph. Although the sensor resets at midnight it seems that when plotting the max value in the statistics graph it picks up the last point from the previous day so that if the previous days “on time” was longer the following day will show the same value (see e.g. Dec 4 and 5 in the plots below).

Any suggestion on how to avoid this?

sensor:
  - platform: history_stats
    name: Water Heater On Time
    entity_id: binary_sensor.water_heater_on
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

image

Utility Meter sensors can be displayed as bar graphs using the Statistics graph.

If you create a daily Utility Meter sensor, set the graph’s options to Day, Bar, and State. It won’t offer Max for the simple reason that a daily Utility Meter sensor provides one value for the entire day and it represents the total for the day.

Example

The following Statistics graph shows the total number of hours the fan was on for each day (for the past 30 days).

1 Like

Based on the information I provided about the Utility Meter integration (i.e. it can be graphed as a bar chart), any progress to report?