# Calculate number of gas heating cycles/hour based on flow temperature chart?

I’d like to convert the changes of the flow temperature of my gas boiler to a number of heating cycles in the past e.g. 60 minutes – but have no idea, how to do so. For a human it’s easy to count the peaks or troughs over the past hour, but how would a template/sensor/helper/… do that?

Here’s an example chart:

The reason I’m interested in the number of cycles is that too many short cycles are inefficient. I’d want to identify phases of frequent cycles and have an automation adjust some parameters (such as adjusting the target temperature in various rooms) to help the boiler “get rid” of the energy it’s sending to the radiators. I know, it’s only an ugly workaround, but my boiler is way bigger than necessary, meaning that it struggles when it’s not too cold outdoors.

Thank you very much for any suggestion.

Do you have any other sensors like one that knows if the boiler is running or not? Or do you only have a temperature sensor and you are using that as your baseline?

If the temperature sensor is your baseline and you want to assume that a rise in temperature is a “cycle” then you just need, for example, a helper that logs the high temperature and if you go over that value then you know you are heating.

So what kind of sensors are we dealing with here to help with the solution?

That‘s unfortunately my only sensor. The gas boiler isn‘t smart and its communication proprietary (Vaillant eBUS), so I placed a Bluetooth temperature sensor with external probe on the copper pipe leading to the radiators.

The moment the temperature rises, the heater is on. The moment it drops, the heater turns off the flame (and keeps the pump running for another 3 minutes).

Would something like the number of crosses above a moving average be a good way to tackle the problem? I just have no idea yet how to create a template helper with such a logic.

Thanks!

Perhaps. The pitfall I think about is that you would start to get false readings when it’s warmer outside and the temperature keeps increasing but the boiler isn’t doing it. But you could create a baseline of say X degrees or have a toggle in HA to indicate if the boiler should be counted right now.

You could do a helper or a sensor template to track this. I like to first understand how my brain sees the data and jumps to the value to better understand how to do it in code - and that’s what I’m not yet getting.

So when the boiler temperature goes up (perhaps over an average and at least X degrees) then do what? Create a counter of each time this occurs? So at the end of the day you might have, say, 15 times that the boiler turned on? Or do you want something more granular than that, like how may times per hour?

And when it goes off, the temperature goes down again (perhaps with a 3 minute lag for the pump), how do you want to see that?

Thanks for all your help. From all I‘ve read, the goal is to reduce the number of cycles. A „long“ cycle of a couple of minutes and then a pause of 15 minutes is fine, but when the boiler turns on only to turn off again after 2 minutes, with the next cycle less than 10 minutes later, this is indicates that the boiler generates hot water in the pipes which isn‘t cooled down quickly enough in the radiators, leading to a high temperature of the water returning to the boiler, causing a temporary heating break.

So what would help is e.g.:

• average cycle duration based on the past three cycles
• average cycle duration in the past 30 (or 60) minutes
• number of cycles within the past 30 (or 60) minutes
• average time from trough to peak in the past 3 cycles
• average duration of the flow temperature of a cycle above the 1hour average water flow temperature

Whatever is easiest to code will be useful. But when looking at the issue in an abstract way, the question is how to calculate the frequency of a sinus wave that‘s fit to the measured curve.

Edit: whenever I see too many short cycles within 30-60 minutes, I would turn up the target temperature of all my thermostatic radiator valves for 30 minutes, allowing the hot water to distribute across all radiators, giving the heater a way to cool down while temporarily overheating all rooms by a tiny bit.

@CO_4X4 I’ve come across the Pulse Width Sensor — ESPHome and while this isn’t exactly what I’m looking for and also it’s not available for HA, it’s probably a step forward. So what would help a lot is how to measure the length (in seconds) of the past cycle, defined by, e.g.

``````previous_timestamp_when_signal_rose_above_1hour_moving_average - timestamp_when_signal_rose_above_1hour_moving_average
``````

I think this might be possible with a trigger sensor, but I’m still unsure how.

While I’m digging for something else I stumble on your post. Hoping the following might help you.

From my binary_sensor.yaml file :

• platform: template
sensors:
hvac_heating:
friendly_name: “HVAC Heating”
value_template: >-
{% if states.climate.thermostat.attributes.hvac_action in [‘heating’] %}
{{states.climate.thermostat.attributes.temperature}}
{% else %}
0
{% endif %}
icon_template: >-
{% if is_state(“binary_sensor.hvac_heating”, “on”) %}
{% else %}
{% endif %}

 adding more entries for template.yaml

# Heating

• sensor:
• name: Heating Count
unique_id: heating_count
state: “{{ states(‘sensor.heating_count_today’) }}”
• name: Heating Time
unique_id: heating_time

# convert from hours to minutes

state: “{{ states(‘sensor.heating_on_today’) | float * 60 }}”
unit_of_measurement: min

The following sensors defined in sensor.yaml is the counter you’re looking for.

# today count

• platform: history_stats
name: Heating Count Today
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: count
start: “{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}”
end: “{{ now() }}”

# yesterday

• platform: history_stats
name: Heating Count Yesterday
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: count
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
hours: 24

# this week so far

• platform: history_stats
name: Heating Count this Week
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: count
start: “{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}”
end: “{{ now() }}”

# last 7d

• platform: history_stats
name: Heating Count past 7 days
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: count
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
days: 7

# last 30d

• platform: history_stats
name: Heating Count past 30 days
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: count
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
days: 30

The following sensors defined in sensor.yaml allows to graph the time our boiler is on.

# today

• platform: history_stats
name: Heating On Today
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: time
start: “{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}”
end: “{{ now() }}”

# yesterday

• platform: history_stats
name: Heating On Yesterday
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: time
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
hours: 24

# this week so far

• platform: history_stats
name: Heating On this Week
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: time
start: “{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}”
end: “{{ now() }}”

# last 7d

• platform: history_stats
name: Heating On past 7 days
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: time
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
days: 7

# last 30d

• platform: history_stats
name: Heating On past 30 days
entity_id: binary_sensor.hvac_heating
state: ‘on’
type: time
end: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
duration:
days: 30

Thank you very much for your follow up. It seems you have a sensor indicating if the heater is heating or not. And my challenge is that I don’t have that – all I have access to is the temperature of the heater. If the temperature is rising, the boiler is burning gas. The higher the slope, the more gas is burnt per minute. And if the temperature falls, the boiler has turned itself off.

So I wonder: Is there any statistics integration (or helper,…) that will automatically calculate the slope for the temperature measurements of the past 5 minutes? Then a threshold sensor helper could be used on this slope to convert it to a binary heating on/off sensor.

You could perhaps try the Derivative integration.

I’m not sure how your gas heater works, in my case I for the gas boiler I used a Zooz ZEN17 that has 2 inputs and a Zooz ZAC98 (NC/NO relay). The relay is required because the inputs of the ZEN17 can’t take 24VAC from the gas heater. How does your gas heater works if you have no way to know if it’s on or off? You can’t install a smart thermostat?

Are you familiar with Ebusd?

Most Vaillant heaters transmit many datapoints, like “flame On”.

The hardware is relatively cheap.

I have received ebusd hardware 2 weeks ago but didn’t yet manage to install it. I need to find out how to remove my calorMATIC 370 from the wall and between calorMATIC and cable coming out of the wall add in another cable leading to the ebusd hardware. And I need to check what kind of cable is needed and purchase that too.

Thanks for mentioning the Derivative integration, I did’t find that, probably I was searching for “slope”, not “derivative”, also I was expecting to find such a function in the Statistics integration.

It’s a clip-on system, pry it loose with your fingers.

Any 2 wire cable will do. I used cat-5 with 2x2 wires in parallel.

You can connect the adapter (in parallel) on the calormatic side or on the heater side, whatever is more convenient (and you feel brave enough to open up your heater!).