Return light to previous state with motion detection

I’m bending my head of this problem and can’t find the solution.

After sunset I have an automation that turns on my outdoor light at 50% brightness. When my motion sensor detects movement change the brightness to 100%. After 2 minutes I would like te lights to go to: previous state (if time is before 23:30) or go out.

I created an automation with scene.create which work to up a point. the big problem is that is there are multiple movements within the 2 minutes of 100% light the scene.create snapshot messes up. Resulting in the lights staying on.

This is what I have so far.

alias: Beweging Terras
description: ""
trigger:
  - type: motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    id: achterdeur
  - type: no_motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition: []
action:
  - if:
      - condition: trigger
        id:
          - achterdeur
      - condition: template
        value_template: >-
          {{ states('sensor.hue_outdoor_motion_sensor_1_illuminance') | float(0)
          < 10 }}
        enabled: true
    then:
      - service: scene.create
        data:
          scene_id: terrasactie
          snapshot_entities:
            - light.signify_netherlands_b_v_lwa011_light
            - light.signify_netherlands_b_v_lwg004_light
        enabled: true
      - service: light.turn_on
        data:
          brightness: 255
        target:
          entity_id:
            - light.signify_netherlands_b_v_lwa011_light
            - light.signify_netherlands_b_v_lwg004_light
    else:
      - delay:
          hours: 0
          minutes: 2
          seconds: 0
          milliseconds: 0
      - service: scene.turn_on
        data:
          transition: 5
        target:
          entity_id: scene.terrasactie
        enabled: true
mode: single

I’m a bit confused by the mixture of devices and entities. I see from the template that you’re using a hue motion sensor, so presumably you have an entity sensor.hue_outdoor_motion_sensor_1_motion (or something similar)? Why the device triggers?

Also, I have always found scenes a pain. Wouldn’t something like this work? The entities are my own - I also have Hue outside lights operated by a motion sensor.

alias: Dim yard light
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.yard_motion_sensor_motion
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.yard_motion_sensor_motion
    to: "off"
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - if:
      - condition: state
        entity_id: binary_sensor.yard_motion_sensor_motion
        state: "on"
    then:
      - service: light.turn_on
        data:
          brightness_pct: 100
        target:
          entity_id: light.yard_1
  - if:
      - condition: state
        entity_id: binary_sensor.yard_motion_sensor_motion
        state: "off"
    then:
      - service: light.turn_on
        data:
          brightness_pct: 50
        target:
          entity_id: light.yard_1
mode: single

This doesn’t include the “if time is before 23:30” requirement. I would probably use a schedule helper to define times when lights should dim.

Edit: I like the idea of dimming the light - mine just go on and off. I’m going to steal that - thanks! :grinning_face_with_smiling_eyes:

Thanks. How is this triggered by the amount of outdoor light?

I dropped the idea of scene.create. Here’s my new automation. trying it out tonight. Problem is the point in the automation where the illuminance is measured. In theory this could mean that the lights are not switched off.

alias: Beweging Terras 2
description: ""
trigger:
  - type: motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    id: Beweging Achterdeur
  - type: no_motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: beweging gestopt
condition:
  - condition: template
    value_template: >-
      {{ states('sensor.hue_outdoor_motion_sensor_1_illuminance') | float(0) <
      10 }}
action:
  - if:
      - condition: trigger
        id:
          - Beweging Achterdeur
    then:
      - service: light.turn_on
        data:
          brightness: 255
        target:
          entity_id:
            - light.signify_netherlands_b_v_lwa011_light
            - light.signify_netherlands_b_v_lwg004_light
    else:
      - if:
          - condition: time
            before: "23:30:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
        then:
          - service: light.turn_on
            data:
              brightness: 128
              transition: 5
            target:
              entity_id:
                - light.signify_netherlands_b_v_lwa011_light
                - light.signify_netherlands_b_v_lwg004_light
        else:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.signify_netherlands_b_v_lwg004_light
                - light.signify_netherlands_b_v_lwa011_light
mode: single

It is triggered every time motion is detected. I have a condition (didn’t include it above - sorry) which prevents any action if light is above a certain level. Same principle as yours, I think, except I use a threshold helper which can be accessed by other automations as well.

condition: state
entity_id: binary_sensor.override_outside
state: "off"

That makes sense. Thanks.

tweaked the automation because the threshold in the condition was preventing the light from being shut down.

alias: Beweging Terras 2
description: ""
trigger:
  - type: motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    id: Beweging Achterdeur
  - type: no_motion
    platform: device
    device_id: c64c7196a48ffcf6a077870231964c54
    entity_id: f2f07f1387b3c9896416455ef997600d
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: beweging gestopt
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Beweging Achterdeur
      - condition: template
        value_template: >-
          {{ states('sensor.hue_outdoor_motion_sensor_1_illuminance') | float(0)
          < 10 }}
    then:
      - service: light.turn_on
        data:
          brightness: 255
        target:
          entity_id:
            - light.signify_netherlands_b_v_lwa011_light
            - light.signify_netherlands_b_v_lwg004_light
    else:
      - if:
          - condition: time
            before: "23:30:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
              - sat
              - sun
        then:
          - service: light.turn_on
            data:
              brightness: 128
              transition: 5
            target:
              entity_id:
                - light.signify_netherlands_b_v_lwa011_light
                - light.signify_netherlands_b_v_lwg004_light
        else:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.signify_netherlands_b_v_lwg004_light
                - light.signify_netherlands_b_v_lwa011_light
mode: single

This is nice. For some reason it works better than my template condition. Do you have any idea why?

Afraid not. I like threshold helpers because of the hysteresis option, which helps to prevent “bounce” when the light is hovering around the threshold.