https://gist.github.com/yousaf465/4b69151eb423d1f532b323d36aede44d
Is this automation correct?
Any particular issue?
1 messages · Page 1 of 1 (latest)
https://gist.github.com/yousaf465/4b69151eb423d1f532b323d36aede44d
Is this automation correct?
Any particular issue?
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
what if light is turned on from the rocker switch?
assuming its just a toggle function that switching it triggers then it doesnt effect anything, if its on for 45 mins it goes off, if the door opens it will switch off
if someone opens the door after 45mins it will stay off?
and if before 45mins it will turn off?
it doesnt care how it gets turned on, it just turns it off after 45 mins
issue is if someone open the door before 45mins will stay on?
if door is left open and it will be a simple toggle which doesn't serves the purpose
can you explain exactly how you want it to function
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.
so:
when door opens - turn on switch (or keep on)
if light on for 45 minutes - turn off switch
when door closes alternate between having light on and turning light off
does that seem right?
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
Yes, I am trying to accomplish all these scenarios
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