This SQL query calculates the number of times doors and windows have been opened and closed in Home Assistant, along with the average uses per day, and retrieves the current voltage for each sensor.
To be used with the SQLite Web addon, replace all binary_sensor and sensor entities with your own.
WITH state_changes AS
(SELECT sm.entity_id,
s.state,