#Bathroom door light automation with timed off if left on for more than 45mins

1 messages · Page 1 of 1 (latest)

fallow raptor
opaque spear
# fallow raptor https://gist.github.com/yousaf465/4b69151eb423d1f532b323d36aede44d Is this auto...

you could just trigger on door opened or switch on for 45 mins then call switch.toggle

something like this:

alias: demo bathroom
description: ""
triggers:
  - entity_id: binary_sensor.door_sensor_2_opening_2
    from: "off"
    to: "on"
    id: door_opened
    trigger: state
  - entity_id:
      - switch.sonoff_zbminir2
    to: "on"
    id: relay_on
    trigger: state
    for:
      hours: 0
      minutes: 45
      seconds: 0
conditions: []
actions:
  - action: switch.toggle
    metadata: {}
    data: {}
    target:
      entity_id: switch.sonoff_zbminir2
mode: single

if door is opened then the light toggles to opposite state
and if thes been on for 45 mins then it toggles to oppsite(which would always turn it off as its on by nature of the trigger)

its a more simple approach and prevents any "long running" automations which in general its good practice to avoid

fallow raptor
opaque spear
fallow raptor
#

and if before 45mins it will turn off?

opaque spear
#

it doesnt care how it gets turned on, it just turns it off after 45 mins

fallow raptor
#

issue is if someone open the door before 45mins will stay on?

opaque spear
#

no it will go off

#

every time the door opens - it will "toggle state"

fallow raptor
#

if door is left open and it will be a simple toggle which doesn't serves the purpose

opaque spear
#

can you explain exactly how you want it to function

fallow raptor
#

I want it to turn on when door is first opened, door is closed but light remains on, you do your business and when you step outside of washroom, light turns off when you close the door. if you leave the door open somehow, it will auto turn off after 45mins. if someone turn it on using rocker switch it will again turn off after 45mins if not turned off.

opaque spear
#

the obvious edge case is that if you open door and someone is waiting, they go in and close the door and the light turns off

fallow raptor
opaque spear
#

I suggest making a helper toggle for "occupied"

trigger on door open to turn on switch
trigger on switch on for 45 mins to turn off switch
trigger on door closed to toggle occupied helper. then check if occupied is on/off and turn light off if its off