Help with logic on multiple stair sensors

Good day everyone.

I have a LED light strip running down my staircase and have a sensor at the top and bottom of the stairs.

Currently I have 5 automations setup to run the effect basically.
Top stair trigger, so when the top stair triggers it turns on the light and sets a triggered state. then the bottom sensor has two automations based on the state (I still need to setup the if then actions automation to basically clean them up into one automation but that’s for later). 1 automation triggers the light to dim and turn off if the top sensor has been triggered. and the other runs the same light up sequence in reverse.

I need some help figuring out how to have the “turn off” sequence delay if another person enters the stairwell (follows the first trigger). I imagine having a counter and then having the turn off delay based on that counter being greater than 1 but I can’t figure out how to logically do it.

Top stair triggered initial

alias: PRESENCE_Stair lights on Top
description: Turn the stair lights on when top motions is detected.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.stair_sensor_top_stair_motion_top
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.stair_auto_leds
    state: "on"
  - condition: state
    entity_id: light.stairwell_bannister_light
    state: "off"
  - condition: state
    entity_id: input_boolean.top_stair_sensor_tripped
    state: "off"
action:
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.top_stair_sensor_tripped
  - service: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.stairwell_bannister_light_main
  - service: select.select_option
    metadata: {}
    data:
      option: Start Wipe
    target:
      entity_id: select.stairwell_bannister_light_preset
  - service: timer.start
    metadata: {}
    data:
      duration: "00:02:00"
    target:
      entity_id: timer.stair_motion_timer
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - service: select.select_option
    metadata: {}
    data:
      option: Solid WW
    target:
      entity_id: select.stairwell_bannister_light_preset
mode: single

Bottom Stair triggered second

description: >-
  Turns the stair lights off when the bottom sensor picks up movement after
  initial transition
trigger:
  - platform: state
    entity_id:
      - binary_sensor.stair_sensor_bottom_stair_motion_bottom
    to: "on"
condition:
  - condition: state
    entity_id: light.stairwell_bannister_light
    state: "on"
  - condition: state
    entity_id: input_boolean.stair_auto_leds
    state: "on"
  - condition: state
    entity_id: input_boolean.top_stair_sensor_tripped
    state: "on"
action:
  - service: light.turn_on
    target:
      entity_id: light.stairwell_bannister_light
    data:
      transition: 5
      brightness: 1
      rgbw_color:
        - 0
        - 0
        - 0
        - 255
      effect: Solid
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - service: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.stairwell_bannister_light
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.top_stair_sensor_tripped
    data: {}
mode: single

The state cleanup (catch all if someone goes down and back up the stairs halfway)

alias: Presence. Stair motion cleanup
description: >-
  Resets the stair motion triggers after a two minute timer if the light is
  still on. 
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.stair_motion_timer
    id: Timer finished
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: input_boolean.bottom_stair_sensor_tripped
        state: "on"
      - condition: state
        entity_id: input_boolean.top_stair_sensor_tripped
        state: "on"
  - condition: state
    entity_id: light.stairwell_bannister_light
    state: "on"
action:
  - service: light.turn_on
    target:
      entity_id: light.stairwell_bannister_light
    data:
      transition: 5
      brightness: 1
  - service: light.turn_off
    target:alias: PRESENCE_Stair lights on Top
description: Turn the stair lights on when top motions is detected.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.stair_sensor_top_stair_motion_top
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.stair_auto_leds
    state: "on"
  - condition: state
    entity_id: light.stairwell_bannister_light
    state: "off"
  - condition: state
    entity_id: input_boolean.top_stair_sensor_tripped
    state: "off"
action:
  - service: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.top_stair_sensor_tripped
  - service: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.stairwell_bannister_light_main
  - service: select.select_option
    metadata: {}
    data:
      option: Start Wipe
    target:
      entity_id: select.stairwell_bannister_light_preset
  - service: timer.start
    metadata: {}
      entity_id: light.stairwell_bannister_light
    data: {}
  - service: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id:
        - input_boolean.bottom_stair_sensor_tripped
        - input_boolean.top_stair_sensor_tripped
mode: single

I’d appreciate some direction and advice please.

Thanks.

Well I managed to figure out the problem I think.

Two things,
I had to create counters for both the bottom and top stair sensors.
I had to set the top and bottom stair automations to parallel so they would trigger even if the initial lightup sequence wasn’t complete.

In the end I ended up with 4 Helpers and 3 automations.

Helpers:

  • Counter.Top stairs
  • Counter.Bottom stairs
  • Input_boolean.top stairs
  • Input_boolean.bottom stairs

Automations

  • Top Stairs triggered
  • Bottom stairs triggered
  • Stair cleanup (Catch all to clear the counters and boolean switches)

The automations ended up like this

alias: PRESENCE_Top stair sensor
description: >-
  Dual automation to catch the top stair trigger. When triggered from the top it
  will start the lights going down. If the bottom has already been triggered
  then it will start to turn off the lights.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.stair_sensor_top_stair_motion_top
    to: "on"
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.top_stair_sensor_tripped
            state: "off"
          - condition: state
            entity_id: input_boolean.stair_auto_leds
            state: "on"
          - condition: state
            entity_id: light.stairwell_bannister_light
            state: "off"
        sequence:
          - service: counter.increment
            metadata: {}
            data: {}
            target:
              entity_id: counter.stair_top_trigger
          - service: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.top_stair_sensor_tripped
          - service: light.turn_on
            target:
              entity_id: light.stairwell_bannister_light_main
            data: {}
          - service: select.select_option
            metadata: {}
            data:
              option: Start Wipe
            target:
              entity_id: select.stairwell_bannister_light_preset
          - service: timer.start
            metadata: {}
            data:
              duration: "00:01:00"
            target:
              entity_id: timer.stair_motion_timer
          - delay:
              hours: 0
              minutes: 0
              seconds: 6
              milliseconds: 0
          - service: select.select_option
            metadata: {}
            data:
              option: Solid WW
            target:
              entity_id: select.stairwell_bannister_light_preset
      - conditions:
          - condition: state
            entity_id: light.stairwell_bannister_light
            state: "on"
          - condition: state
            entity_id: input_boolean.stair_auto_leds
            state: "on"
          - condition: state
            entity_id: input_boolean.bottom_stair_sensor_tripped
            state: "on"
          - condition: numeric_state
            entity_id: counter.stair_bottom_trigger
            above: 1
        sequence:
          - service: counter.decrement
            metadata: {}
            data: {}
            target:
              entity_id: counter.stair_bottom_trigger
      - conditions:
          - condition: state
            entity_id: light.stairwell_bannister_light
            state: "on"
          - condition: state
            entity_id: input_boolean.stair_auto_leds
            state: "on"
          - condition: state
            entity_id: input_boolean.bottom_stair_sensor_tripped
            state: "on"
          - condition: numeric_state
            entity_id: counter.stair_bottom_trigger
            below: 2
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.stairwell_bannister_light
            data:
              transition: 5
              brightness: 1
              effect: Solid
              rgbw_color:
                - 0
                - 0
                - 0
                - 255
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.stairwell_bannister_light
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.bottom_stair_sensor_tripped
          - service: counter.decrement
            metadata: {}
            data: {}
            target:
              entity_id: counter.stair_bottom_trigger
      - conditions:
          - condition: state
            entity_id: light.stairwell_bannister_light
            state: "on"
          - condition: state
            entity_id: input_boolean.stair_auto_leds
            state: "on"
          - condition: state
            entity_id: input_boolean.bottom_stair_sensor_tripped
            state: "off"
        sequence:
          - service: counter.increment
            data: {}
            target:
              entity_id: counter.stair_top_trigger
mode: parallel
max: 4

So this automation catches when a person enters the stairwell, and if another enters before the bottom sensor is triggered then the counter increments. If the counter is less than 2 (i.e only one person in the stairwell) then it will shutdown the light after triggering the bottom sensor (in the bottom automation not the one above which is the top automation). If the counter is higher than 1 (i.e 2 or more people in the stairwell) it will only decrement the counter when the bottom triggers.

I figured that there wouldn’t be more than 4 people on the stairs at any point in time and it only takes 5-6 seconds to descend the stairs so having no more than 4 parallel tasks should be fine.

Any tweaks or advice are welcome and this is provided to assist anyone else with the same problem