Help with automation counter

how to write automation
I want to count the number of times the boiler was heated based on the temperature of the tanks - I have created a counter

I have a temperature sensor that goes up to 85° during heating, (depending on the consumption of the house it then oscillates between 77 and 85 degrees) When it stops heating, the temperature gradually decreases as the tank cools down.

I have automation:

alias: counter
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.cidlo_1
    for:
      hours: 0
      minutes: 10
      seconds: 0
    above: "80"
condition: []
action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.pocet_topeni
  - delay:
      hours: 12
      minutes: 0
      seconds: 0
      milliseconds: 0
mode: single

the delay there is to bridge the oscillation time until the temperature starts to drop. Unfortunately on reboot HA turns on the trigger and adds another one.
How to do such automation in HA?

Add the uptime integration. Then:

condition:
  - "{{ now()|as_timestamp - states('sensor.uptime')|as_timestamp(0) > 30 }}"

That’ll stop updates within the first 30s of a restart.

I would not use an automation.

Use a threshold binary sensor to report when your boiler is on:

binary_sensor:
  - name: Boiler
    platform: threshold
    entity_id: sensor.cidlo_1
    upper: 80
    hysteresis: 5 # on at 85, off at 75

Then feed that to a history stats sensor to count the number of times it turned on.

(Example for monthly count, other time periods possible, see the examples in the docs above)

sensor:
  - platform: history_stats
    name: Boiler ON Count 
    entity_id: binary_sensor.boiler
    state: "on"
    type: count
    start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
    end: "{{ now() }}" 

thank you both, i will try and report back

the first solution after a forced restart added up on the counter
the second solution with the helper and history stats doesn’t work for me either, now I’m heating and the history stats sensor is already 2

Can you share a screenshot of the history graph of sensor.cidlo_1?

this is the history of the sensor, usually the temperature exceeds 80°C but maybe 85°C is not always reached, it happens at different times, sometimes the tanks are heated at noon, other times they are added to the boiler in the evening and the tanks are not heated until after midnight. Usually the tanks cool down before flooding again, but sometimes they flood the very next day when they are still 60°C (this is a 2000l tank, the sensor is located at the top)


unfortunately, I can’t integrate the boiler into HA, and I’m interested in the number of times it flooded

Get a water leak sensor.

As for the values to detect on/off try this:

binary_sensor:
  - name: Boiler
    platform: threshold
    entity_id: sensor.cidlo_1
    upper: 70
    hysteresis: 5 # on at 75, off at 65

sorry google translator no fflooted, but heated :slight_smile:

1 Like

I suspected a typo :slight_smile: