Calculate cumulative on-time on for a switch

I use an ESPHome node to control some of my thermostats, and I have always been curious to know how much time each day my furnace actually runs for. Home Assistant has this information in it’s logs, but how do I calculate this?

I’m imagining this looking like a Statistics graph with bars for each day, but with a cumulative time spent in the “on” state for each day.

Has anyone found a way to do this with Home Assistant and/or ESPHome?

Create a Template Sensor plus History Stats sensor. Add Utility Meter sensors for long-term fata (daily/weekly/monthly/yearly).