#Add 40min inching in bathroom door automation?

1 messages · Page 1 of 1 (latest)

bleak coyote
#

I have this automation setup and running fine but I want to add a 40min limit on light, if e.g door is left open, in that case light should turn off after 40mins . How should I add that?

description: "Turn on and off the bathroom light using the aqara contact sensor. "
triggers:
  - entity_id:
      - binary_sensor.door_sensor_2_opening_2
    from: "off"
    to: "on"
    id: first opening
    trigger: state
conditions: []
actions:
  - metadata: {}
    data: {}
    action: light.turn_on
    target:
      entity_id: light.sonoff_zbminir2
  - wait_for_trigger:
      - entity_id:
          - binary_sensor.door_sensor_2_opening_2
        from: "off"
        to: "on"
        id: "wait for door to open again. "
        trigger: state
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 5
  - metadata: {}
    data: {}
    action: light.turn_off
    target:
      entity_id: light.sonoff_zbminir2
mode: single
thin tartan
#

i just use two different automations. light on triggers on one or more sensors (in my case mmwave and ir). it turns on the light and sets a countdown timer. every time this triggers the timer is reset.
light off then just triggers on the timer reaching zero.

bleak coyote
#

I would like to combine it into one single automation

thin tartan
#

you are reacting to the door closing for both?

bleak coyote
#

what I want is to turn off the light after 40mins if somehow it is left on for that long

thin tartan
#

if you turn off when the door gets opened instead of when it closes then i think you have something that could work?

#

i still think reacting to any state change (opening or closing) as a "someone is present" and turn on the light and a timer, then turning off based on the timer is more user-proof

thin tartan
#

if you want to go down the path you are on i would say react to the door opening or closing by turning on the light, then react to the door opening again by turning off. that covers the case where the door is left open

#

the next problem then is when someone opens the door to change a towel or fetch their cell phone without closing the door while they are in the room. and then close it as they go out. now light is on until someone comes to use the bathroom next. then it goes off when they open the door and on again when they close it. so you also want to handle the case where the door is left closed with lights on. that's why i still propose making 2 independent automations for on and off. the code bacomes simpler and still more flexible.

bleak coyote
#

this is my goal ✅ Turn on the light when I enter (door opens)
✅ Start a 40-minute countdown immediately
✅ BUT if I leave earlier (door opens again), light should turn off then
✅ Otherwise, light auto-turns off after 40 minutes

#

come up with this ```yaml
alias: Bathroom door light
description: "Turn on light when entering bathroom. Turn off after 40 minutes or when door opens again (you leave)."
mode: restart

trigger:

  • platform: state
    entity_id: binary_sensor.door_sensor_2_opening_2
    from: "off"
    to: "on"
    id: entered_bathroom

  • platform: state
    entity_id: binary_sensor.door_sensor_2_opening_2
    from: "off"
    to: "on"
    id: left_bathroom

condition: []

action:

  • choose:
    • conditions:

      • condition: trigger
        id: entered_bathroom
        sequence:
      • service: light.turn_on
        target:
        entity_id: light.sonoff_zbminir2
      • delay:
        minutes: 40
      • condition: state
        entity_id: light.sonoff_zbminir2
        state: "on"
      • service: light.turn_off
        target:
        entity_id: light.sonoff_zbminir2
    • conditions:

      • condition: trigger
        id: left_bathroom
        sequence:
      • service: light.turn_off
        target:
        entity_id: light.sonoff_zbminir2
thin tartan
#

and when the door is left open, next person arrives and closes the door... they have to open it again to get the lights on? or if someone arrives before the 40 minutes are out, closes the door and sit down - and then the lights go out? too many corner cases doing it that way.

west laurel
#

I think that opening a door is not a good trigger for turning on a light. The door can be opened but no one can access the bathroom, for example, in which case it would not be necessary to turn on the light.

Now if the door is closed, the light will be on. If someone opens, enters and closes the door, the light will turn off. The user will then have to keep opening and closing the door until it is synchronized with the actual use of the bathroom. I recommend using a mmwave motion sensor.

bleak coyote
#

even though I do have a few LD2420 and LD2450 radar in my inventory

#

most LD2410 are working already in different locations in house

bleak coyote
thin tartan
bleak coyote
sick gust
#

I have a helper called bathroom bright that I turn on to override the timer in case someone is taking a leisurely bath and won’t be sensed by the motions sensor. Another approach for showers is to use a humidity sensor to override shutting off.

novel token
#

My bathroom automation is probably my most "complex" automation. In the bathroom is a motion detector and door sensor. Motion detector detects = lights turn on and timer starts. If the door is open, new motion restarts the timer. If the door is closed, timer is canceled but the lights stay on; motion doesn't matter. Opening the door restarts the timer.
Using trigger_ids and a timer entity brings it all together. There is a lot more flexibility when using the timer entity as opposed to using a delay. IMO, delays are good for something short (like a minute) and you're not looking to want to be able to override/reset/delay it.
I just put the automation up on my GitHub if you want to take a look. https://github.com/dsellers1/home-assistant/blob/main/automations

balmy hare
novel token
sick gust
#

@balmy hare If you're on Zwave, I have a dozen Zooz zse41 sensors. They are low profile, and I've been happy with both sensitivity and battery life over the past 3 years.

balmy hare
balmy hare