Double Motion Sensor w/ Led light strips

I wasn’t able to find any real answers for this automation question so I figured I would make my own post and try to find the best answers. So here’s the task,

1.) One motion sensor on the base of the stairs and one on the top of the stairs (my stairs wrap around a corner, so no false trips).
2.) Flux Led light strip ran the whole length of the stairs.
3.) When motion is detected at the bottom of the stairs check to see if the light is on or off and turn it on or off depending on the first check. And when motion is detected at the top of the stairs check if the light is on or off and turn it on or off depending on the check.

Essentially I want it to only turn on the light when we walk up or down the stairs and turn it off when we exit the stairwell. I’m super new to the Home Assistant coding world and can’t seem to wrap my mind around this automation. Thank you all in advance for any feedback you can provide.

Easiest would be to trigger a light.toggle whenever motion is detected on either the top or bottom motion detector. However, this could also mean if 2 people go down the stairs in short succession, both could be end up without a light on the stairs.

To Circumvent that you could work with timers, or extra conditions checking if the bottom, or top motion sensor was triggered in the past seconds before.

Other possibility is to group the motion sensors, and then trigger light turn on when motion is detected by the group, and turn it off when the motion in the group is not detected anymore (+ any amount of time you’d like)

The simplest form would be:

trigger:
  - platform: state
    entity_id: sensor.pir_top_of_stairs
    to: 'on'
  - platform: state
    entity_id: sensor.pir_bottom_of_stairs
    to: 'on'
action:
  service: light.toggle
  entity_id: light.flux_led

If you change your mind half way down the stairs and go back up (or vice-versa) it should still turn off the light (assuming you dont have one of those awful zigbee or zwave PIRs that trigger for 3 minutes!). However…
This won’t protect against someone starting on the staircase while someone else is already ascending or descending. This could turn the light off while the they are both on the stairs. I’m not sure how to protect against that. The easiest way would just be a timed off delay using two automations instead of the one above:

trigger:
  - platform: state
    entity_id: sensor.pir_top_of_stairs
    to: 'on'
  - platform: state
    entity_id: sensor.pir_bottom_of_stairs
    to: 'on'
action:
  service: light.turn_on
  entity_id: light.flux_led

and

trigger:
  - platform: state
    entity_id: sensor.pir_top_of_stairs
    to: 'off'
    for:
      seconds: 20 # or however long it takes to go up/down the stairs
  - platform: state
    entity_id: sensor.pir_bottom_of_stairs
    to: 'off'
    for:
      seconds: 20 # or however long it takes to go up/down the stairs
action:
  service: light.turn_off
  entity_id: light.flux_led

You get a bit of a delay after exiting the stairs before the light turns off but you dont have the two person on the stairs problem as in the first automation example above.

2 Likes

I honestly never thought to use a double trigger like that. I will definitely have to give this a go when I get off work and let you know how things go, but from the looks of it this should work perfectly.

So I was finally able to test this out and it worked perfectly. The only thing I did was changed the light.turn_on service into a If/Else statement to allow for the “on” state to trigger a turn on or turn off based on the current state of the light strip. Below is the code I used with your help. Thank you again.

- alias: 'Turn stair lights on'

  trigger:
    - platform: state
      entity_id: binary_sensor.second_floor_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.first_floor_motion
      to: 'on'
  
  condition:      
   - condition: state
     entity_id: sun.sun
     state: 'below_horizon'    
      
  action:
    - service_template: '{% if is_state("light.led_light_strip", "off")%}light.turn_on{%else%}script.delay_turn_off{%endif%}'
      entity_id: 
        - light.led_light_strip


- alias: 'Turn stair lights off just incase'

  trigger:
    - platform: state
      entity_id: binary_sensor.second_floor_motion
      to: 'off'
    - platform: state
      entity_id: binary_sensor.first_floor_motion
      to: 'off'
      
  action:
    - service: light.turn_off
      entity_id:
        - light.led_light_strip
  delay_turn_off:
  
    alias: "Delay Turn Off"
    sequence:
      - delay:
          seconds: 30
      - service: light.turn_off
2 Likes