Duty Cycle from Binary Sensor

Hello and TIA!

Sorry if this gets asked and answered. I did my best to search, and I have a technical/math background. But I’m failing to figure this out.

  • What Grafana version and what operating system are you using?

v10.4.1. I’m using the Home Assistant add on (which is a docker container
zoo

  • What are you trying to achieve?

I’m trying to inspect how much my furnace has been running in different conditions during the winter, specifically on the worst winter nights.

I am about to go searching for a replacement furnace/heat pump and I would like to know if/how much my current furnace is over spec’ed. I have been recording the state of my thermostat into a boolean “heating” variable for 18 months or so.

A typical on/off cycle is on for 30-50mins and off for 50-150mins. I’m mostly interested in the coldest nights.

I’d like to zoom into a particularly cold night and get several measurements that represent the duty cycle for the night. A period of 3hours or so, with the amount of time “on” in those 3 hours, plotted during the night, sampled every 10mins or so would be great.

Example data from the last 10 days in home assistant:

(The large “on” period is a bug. The power went out for 14 hours and it was “on” when we lost power, and then “on” again after we got power back).

  • How are you trying to achieve it? & What happened?

This is as far as I’ve gotten. This is similar to what I have in home assistant except:

  1. It is only sampled on the 10 minute marks.
  2. The unknown state is represented as the previous. I think this is ok. It usually means that my thermostat isn’t publishing when it is off for a long time.

I don’t know how to get the select/group stuff to show anything like a duty cycle. I don’t know how to compute a duty cycle every 10 mins for the amount of time on over the last 3 hours.

  • What did you expect to happen?
    N/A
  • Can you copy/paste the configuration(s) that you are having problems with?
    See screenshot.
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    None
  • Did you follow any online instructions? If so, what is the URL?
    None

Is moving_average what I need to use for this?

If these samples are every 10mins, then 18 would be 3 hours, right?

So this is showing me that on this particular night, the heat was on 70% of the time?

SELECT field(value) mean() moving_average(18) math(* 100)

Playing around with this: It almost works. But the number of samples is dependent on zoom. 18 isn’t necessarily 3 hours. I think this will help me enough to inform my decision. But maybe you know a better way to force a 3h window?