Triggering same automation instantly and after five minutes seems not to work

Hi,
I am writing one automation here to do the following.
It is triggered by a templated sensor which seems to be working correctly (this is an occupancy sensor that is going on and off as people move around the house and triggering as I would expect).

  • The plan is that as soon as the occupancy sensor turns on, lights go to full.
  • Then as soon as no occupancy is detected, sensor turns lights to 1%.
  • After 5 minutes, they should turn off
  • If during the above points the occupancy sensor re-triggers to on, the lights should go back to full and the 5 minute timer effectively restarts

The first two points are working as intended. However, the last point seems to never trigger. I am not sure if the automation is firing but the condition isn’t correctly met? Or if we just wrote the whole thing wrong.

Please help =)

alias: DS Occupancy Lighting
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    to: "on"
  - platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    to: "off"
    for:
      minutes: 5
  - platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    to: "off"
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.is_downstairs_occupied
            state: "on"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.downstairs_lights_all_group
            data:
              brightness_pct: 100
      - conditions:
          - condition: state
            entity_id: binary_sensor.is_downstairs_occupied
            state: "off"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.downstairs_lights_all_group
            data:
              brightness_pct: 1
      - conditions:
          - condition: state
            entity_id: binary_sensor.is_downstairs_occupied
            state: "off"
            for:
              minutes: 5
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.downstairs_lights_all_group
            data: {}
mode: single

alias: DS Occupancy Lighting
description: ""
trigger:
  - id: '100'
    platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    from: 'off'
    to: 'on'
  - id: '0'
    platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    from: 'on'
    to: 'off'
    for:
      minutes: 5
  - id: '1'
    platform: state
    entity_id: binary_sensor.is_downstairs_occupied
    from: 'on'
    to: 'off'
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.downstairs_lights_all_group
    data:
      brightness_pct: "{{ trigger.id | int(0) }}"
mode: single

Thanks, a clever solution that seems to be working!

1 Like