I am currently running a automation to turn off the fan after 4 minutes when the switch goes off. I have a switch on a NodeMCU then a fan connected to a wifi switch. Using an automation that fires a script after 4 minute delay.
toilet_fan_switch_off:
alias: Toilet Fan Switch off
sequence:
- type: turn_off
device_id: 718b56eb2840d46c243f54451929b154
entity_id: switch.powertech_plug_2
domain: switch
mode: single
icon: mdi:fan-off
The problem is that if someone turns the fan switch back on during that 4 minute period, the automation turns it off regardless of the switch now being on.
I know there must be a way that I have some type of condition or checking method to stop it from turning off if the switch is now back on, I am just not sure how to go about it. Can anyone help?
The toilet fan is an entity named switch.powertech_plug_2.
Where is the entity representing the other switch (the one based on the NodeMCU)? In other words, why is it not modelled as an MQTT Switch (or even an MQTT Binary Sensor) instead of reading its status via an MQTT Trigger?
If you model it as an MQTT Switch, you can easily solve the problem you are facing by using a State Trigger with a for: '00:04:00' option (instead of delay).
Thanks for the reply @123 Taras. I probably haven’t got it set up as best that I could, I think I originally had some problem with doing it via switch so I fell back to just using the MQTT method. I have the following in my config to allow the switch already:
That’s effectively what I suggested but I am a bit confused by what you said in your previous post. You showed a configuration for an MQTT Binary Sensor and then indicated it resulted in two entities:
I don’t see how that’s possible. You must have created an MQTT Switch but didn’t post its configuration?