Wondering how to write this event, turn fan off if door has been open 20 mins

Looking at maybe switching from HomeSeer but not clear how I’d do this event:

  • If guest bathroom door closes, turn the fan on
  • If the guest bathroom door opens and stays open for 20 minutes, turn the fan off
  • If the door closes again during those 20 minutes then cancel that and leave the fan on

You can do that pretty easily with AppDaemon. Just take a look at the tutorials. IIRC the first tutorial matches your situation quite well.

It’s 2 automation.
One to turn the fan on:

automation:
  - alias: Turn ON bathroom fan
    hide_entity: True
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: device.door_sensor
      from: 'open'
      to: 'close'
    action:
      service: switch.turn_on
      entity_id:
        - switch.fan

And one to turn it off:

automation:
  - alias: Turn OFF bathroom fan
    hide_entity: True
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: device.door_sensor
      from: 'close'
      to: 'open'
      for:
        minutes: 20
    action:
      service: switch.turn_off
      entity_id:
        - switch.fan

It will only turn off if the door has been opened 20 minutes ago and is still open.

2 Likes