- alias: Fan
trigger:
platform: state
entity_id: light.bathroom
to: 'off'
action:
service: switch.turn_on
entity_id: switch.sonoff218
When the state of the light in the batroom (Philips Hue) changes to OFF the fan (Sonoff) starts running. So far so good but I did not succeed adding a timer function so the fan stops after a certain time.
Iâd generally go with a separate delay in a script. Cancelled when the light comes on, but called when the light goes off.
The major problem the ALL the usage cases above is you should be switching the fan on when the light comes on (but then start the âtimerâ /âdelayâ (whatever) when the light goes off.
I had exactly the same in the beginning. What I did to solve your problem:
If you use the first solution with the delay: if there are 2 people behind each other in the bathroom, and the second one turned on the lights 59 mins after the first one (if the delay is 1 hour), then the fan will shut off 1 min after this last one entered the bathroom. If you use timers, you wonât have this behaviour, and the fan will shut off 1 hour after the second one.
If I restart HA, the fan is never shut off. Thatâs why Iâm using this script: How to make active timers survive a restart. Only downside is that itâs way more complex
I use an Itho/Daalderop fan that is operated with a RF remote that - as far as I know - does not work with Home Assistant. The remote has a button that, if pressed once, turns the fan into the highest position for 10 minutes.
My switch 218 (Wemos D1 mini with Tasmota and a relay shield) switches the remote/button via the relay which is connected to the button switch of the remote. The relay closes only 0.5 seconds so in my case I do not run into issues as you describe.
@tom_lâs approach will also turn off your fan if you have 2 persons after eachother in the bathroom. For example: one person at 10:00AM until 10:15AM and another person as from 10:59AM. The fan will then shut off at 11:00AM, which you would not like in this case.
Because when you restart, the fan is on, so it wont trigger the automation (it hasnât seen a state change) so then wonât be on for (insert time period here) to switch the fan off.
OK, if youâve tested this Iâll accept your word for it.
Implicit in this is if I create the automation and reload it, the fan (which I turned on 10 mins before that) will turn off in 50 mins.??? (trying to get this clear, thx)