Questions about automations

How often does HA check the occurrence of an event? Once a second? Once a minute? Once an hour??

I am attempting to write an automation such as this: Let R be a temperature range, as measured by a sensor S. I need to make sure that fan switch F is OFF when S’s temperature is within range R, and ON outside the range R. I am having trouble figuring out the “events” that should trigger the action of switching F ON or OFF. The automations that I wrote go something like this:

- id: '1710619708422'
  alias: Gabe's fan ON
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: cce31f7baee6b00cedc9178847d7c01e
    entity_id: 5cf1a7f469c5fee78ef19b2becd6b634
    domain: sensor
    above: 21
    below: 18
  condition: []
  action:
  - type: turn_on
    device_id: 6005320f572f169d9ae6e355455a8163
    entity_id: d13dbbf26106c1d40ebdc1917b65a0e0
    domain: switch
  mode: single
- id: '1710619834762'
  alias: Gabe's fan OFF
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: cce31f7baee6b00cedc9178847d7c01e
    entity_id: 5cf1a7f469c5fee78ef19b2becd6b634
    domain: sensor
    above: 18
    below: 21
  condition: []
  action:
  - type: turn_off
    device_id: 6005320f572f169d9ae6e355455a8163
    entity_id: d13dbbf26106c1d40ebdc1917b65a0e0
    domain: switch
  mode: single

… though, to be entirely honest, I am not sure what the triggering “events” are in this. Is it that HA checks the temperature every second, and switches F OFF when it is within R, and ON when it finds it outside R? Does this action happen every second (or however often HA checks the temperature)???

No.

It is entirely state driven not polled. So as soon as your temperature sensor changes the triggers will be evaluated.

Thanks. Hence, for all intents and purposes, it’s as if the “checking” happens continuously, right?

Anyway, let me ask you something else: I am not sure what the range R is in the YAML script above. Is R=[18, 21], or is R=(18, 21)? I am asking because I am afraid of having a conflict: what happens at the edges of R, namely when the temperature is precisely 18C, say? Should I change the values so that I make sure the two automations do not “overlap”?

the answer to that question is in the options for the code above.

the trigger happens when transitioning above 18 or below 21. IOW, going from 18 to 19 or 21 to 20.

at 18 or at 21 it won’t trigger. at 19 or at 20 it will trigger.

and to be more precise it will trigger at 18.1 or at 20.9 if the entity has a float value instead of an integer

It is R=(18, 21)

1 Like