This looks quite complicated to me, and I usually don’t trust
delay much (doesn’ŧ survive HA restarts, gets cancelled when new trigger comes in).
I have a fan that shall go OFF when either the temperature falls below 23.5 °C (as measured on two thermometers) or it has been running for 4 hours (the “4 hours” triggered me to read this post, hee hee):
# switch fan off
- alias: "Lüfter Wohnzimmer aus"
- platform: numeric_state
- platform: state
- service: homeassistant.turn_off
As you see, I simply use
for: in the trigger section, so that the switch goes off only when:
- The temperature has been below 23.5 °C for 2 minutes, or
- the switch (i.e., the fan) has been on for 4 hours.
- … you switch it off manually.
And of course you can use
switch.turn_off instead of
This construct never failed me (yet), and seems to me much more reliable than using delays.
EDIT: Oops. Only after typing all this, I realize that you were talking about ESPHome … Sorry. The syntax is so d**n lookalike. Well, maybe ESPHome also supports “for”?