Historical Statistics for switches and binary sensors

Hi, I love the long there statistics for Measurment and increasing sensors. And min, max, mean, sum, change. etc
I believe we could use similar analysis for Boolean information (switch and Binary sensor)
for example: sum of state changes, or count of on off cicles and Percentage of on or off time, and average on time length.
This would be great for on - off pump, fans, valves…

I don’t disagree with your FR, but just for completeness from my experiences…

It is possible to use a statistics sensor to get the value you want, and then set the required long-term statistics fields in “customize.yaml” since that sensor doesn’t (yet) support them. However, there isn’t a sensible device class to use, so it’s a bit of a hack.

The statistics sensor works on a period though - like the last 24 hours, not “today”. So you’re possibly better off using a triggered template sensor which resets at midnight (or just before).

For a statistics sensor, you could set the following in “customize.yaml”:

sensor.front_door_opened:
  device_class: duration
  unit_of_measurement: d
  state_class: measurement

Using “duration” and “d” results in a count of 7 open events displays as “168:00:00” in the front-end, so that’s probably not a great choice - maybe “weight” would look better, and I’ve used “monetary” before.

You are right, all of this can be done. I am using NODE-RED for counting, on-off percent etc.
But it would be really convenient if it could be integrated into Statistics.
There are a lot of visualization that could be done with this.