Light automation - refresh within time

Hi there,

I use this automation to turn the lights in my hall on / off with a Hue motion sensor and Aqara light sensor:

alias: Deckenlampe Flur Bewegung
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.bewegungsmelder_flur_occupancy
    from: "off"
    to: "on"
    id: Bewegung erkannt
  - platform: state
    entity_id:
      - binary_sensor.bewegungsmelder_flur_occupancy
    from: "on"
    to: "off"
    id: keine Bewegung mehr erkannt
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Bewegung erkannt
              - condition: time
                after: "05:30:00"
                before: "22:00:00"
              - type: is_illuminance
                condition: device
                device_id: 14730b8068709e6fd95b21be8ba04ead
                entity_id: 2c995f091d49d134800925fc0720a432
                domain: sensor
                below: 14
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.deckenlampe_flur
            data:
              brightness_pct: 100
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id:
                  - Bewegung erkannt
              - condition: time
                after: "22:00:00"
                before: "05:30:00"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.deckenlampe_flur
            data:
              brightness_pct: 10
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: light.deckenlampe_flur
                state: "on"
              - condition: trigger
                id:
                  - keine Bewegung mehr erkannt
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - light.deckenlampe_flur
mode: restart

Now I have the issue that the refresh time of the light sensor is 5 s.
Means if the lights turn off and someone enters the hall within this 5 s the automation will not work due to the higher lux level.

How can I modify my automation to check if motion was detected for the next 5 s after the lights were turn off?
I tried it with “refresh automation” and set the automation w/o a lux level, but then the lights are turning always on :smiley:

Sorry for the trashy automation, but this is the best what I can configure :smiley:

alias: Deckenlampe Flur Bewegung
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.bewegungsmelder_flur_occupancy
    from: "off"
    to: "on"
    id: Bewegung erkannt
  - platform: state
    entity_id:
      - binary_sensor.bewegungsmelder_flur_occupancy
    from: "on"
    to: "off"
    id: keine Bewegung mehr erkannt
    for:
      hours: 0
      minutes: 0
      seconds: 30
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Bewegung erkannt
          - condition: time
            after: "05:30:00"
            before: "22:00:00"
          - or:
              - condition: template
                value_template: |
                  {{ is_state('light.deckenlampe_flur', 'off') and 
                  now() < states.light.deckenlampe_flur.last_changed + timedelta(seconds=5) }}
              - condition: device
                type: is_illuminance
                device_id: 14730b8068709e6fd95b21be8ba04ead
                entity_id: 2c995f091d49d134800925fc0720a432
                domain: sensor
                below: 14
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.deckenlampe_flur
            data:
              brightness_pct: 100
      - conditions:
          - condition: trigger
            id:
              - Bewegung erkannt
          - condition: time
            after: "22:00:00"
            before: "05:30:00"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.deckenlampe_flur
            data:
              brightness_pct: 10
      - conditions:
          - condition: state
            entity_id: light.deckenlampe_flur
            state: "on"
          - condition: trigger
            id:
              - keine Bewegung mehr erkannt
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id:
                - light.deckenlampe_flur
mode: restart
1 Like

thanks I will test it and report :slight_smile:

Update:
works fine, thank you!!!