Automation won't work ROAST ME

Hi again!

I’m trying to get my two lights to turn on when I open my basement (stairwell) door and if there is no motion after 5 minutes, turn them off.

The tricky part is if the door isn’t closed when the person is going down the stairs, it will mess up the automation.

The additional tricky part is I have a nighttime timer to do a similar function at a different time.

My automation definitely doesn’t follow optimal logic, so in the good spirit of finding a better solution feel free to roast this one.

For context, tradfri motion sensor 2 is hidden about halfway down the stairs.

Basement motion sensor is at the very opposite of the room from the steps and may or may not sense motion if someone were to go down the stairs depending on whether they make a right or left immediately after.

alias: Stairwell Door Open Daytime
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 3bd2cf73c26e6e44f6878ef15d661417
    entity_id: binary_sensor.basement_door_sensor
    domain: binary_sensor
condition:
  - condition: time
    after: "06:00:00"
    before: "16:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
  - condition: and
    conditions:
      - condition: device
        type: is_off
        device_id: f5b60f3b9de077d19b2fc6c75f6b643e
        entity_id: light.basement_dimmer_2
        domain: light
      - condition: or
        conditions:
          - condition: device
            type: is_off
            device_id: 2a52cd967002bee7554f86fde2fc7a58
            entity_id: light.stairwell_light
            domain: light
action:
  - type: turn_on
    device_id: f5b60f3b9de077d19b2fc6c75f6b643e
    entity_id: light.basement_dimmer_2
    domain: light
    brightness_pct: 80
  - type: turn_on
    device_id: 2a52cd967002bee7554f86fde2fc7a58
    entity_id: light.stairwell_light
    domain: light
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.tradfri_motion_sensor_2_motion
    state: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: c198fb32df024b0c1e4354220e0e5476
        entity_id: binary_sensor.basement_motion_sensor
        domain: binary_sensor
        for:
          hours: 0
          minutes: 5
          seconds: 0
  - service: script.turn_off_basement_2
    data: {}
mode: single

The way you have your conditions configured both lights have to be off for the actions to run. Logical combination conditions like and, or, and not apply only to the conditions nest beneath them… Your or only has one clause, meaning that clause must be true to pass. If you’re not married to the use of Device conditions, State conditions have a built-in OR ability by just adding match: any for the condition’s configuration.

Can you explain what you mean? There’s nothing in this automation that says the door must be closed close.

You may be better off creating a binary sensor group for all the motion sensors, then use that in your wait (or better yet a separate trigger).

alias: Stairwell Door Open Daytime
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 3bd2cf73c26e6e44f6878ef15d661417
    entity_id: binary_sensor.basement_door_sensor
    domain: binary_sensor
condition:
  - condition: time
    after: "06:00:00"
    before: "16:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
  - condition: state
    entity_id:
      - light.stairwell_light
      - light.basement_dimmer_2
    match: any
    state: "off"
action:
  - type: turn_on
    device_id: f5b60f3b9de077d19b2fc6c75f6b643e
    entity_id: light.basement_dimmer_2
    domain: light
    brightness_pct: 80
  - type: turn_on
    device_id: 2a52cd967002bee7554f86fde2fc7a58
    entity_id: light.stairwell_light
    domain: light
  - wait_for_trigger:
      - platform: state
        to: 'off'
        entity_id: binary_sensor.basement_motion_group
        for:
          hours: 0
          minutes: 5
          seconds: 0
  - service: script.turn_off_basement_2
    data: {}
mode: single
1 Like

Hi! Thanks for your helpful reply.

What I meant by the door was, when someone opens the door, it triggers this automation to turn things on. However, if someone opens the door, then closes the door, goes downstairs and then runs back up (like to grab a soda from the fridge or a forgotten item) when they open the door the automation will kick the lights back on.

This makes sense, I will give it a shot cause I’m not 100% sure I know how to create that but I think I should be able to figure it out.

I appreciate your help with this.

If it’s within the 5 minutes of the wait period, the automation’s actions will not execute again because you have the mode set to single.

Groups can be created on the Settings > Devices & Service > Helpers page.
More Info

1 Like

Well now I feel dumb…haha sorry!

When it comes to the binary sensor group, which option would that be in the visual editor? I’m currently trying “state” and typing in the two attributes to it.

Thanks for your help

I don’t know if understand the question… You do not create the binary sensor group in the Automation editor, you do it in the Helper menu.

If you’re asking how to use the group after it’s created… In the Wait for trigger, add a trigger, select “State” from the drop down. In the Entity ID field type in the name or entity ID of the group sensor. Leave the Attribute field blank. Type "on" in the From field and "off" in the To field. Set the duration.

1 Like