Return to previous state double trigger problem

Hi,

I have a problem that I can’t find a solution for at the moment, at least not with the editor.

I have some lights in the kitchen and a sensor. After sunset I want these lights to take on a certain setting (bright) when I enter the kitchen. When I leave the kitchen again, the lights should return to their previous setting after 3 minutes. So far it works fine.
However, when I enter the kitchen again within those 3 minutes, a new snapshot is made in the scene, this time of the bright setting, with the result that the lights retain this setting and do not go out anymore.

For a moment I thought that the ‘Running automations’ attribute in the editor could help me, but it remains 0? (Current in YAML)

Does anyone have the solution how I can prevent the execution of the snapshot function again before the sensor has not triggered any more movement?

alias: Sensor Keuken Memory
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 6398dbc0c917aa150cd1fe2538d1d7c5
    entity_id: 567194f69cee99f48dcd070c2ae5eb15
    domain: binary_sensor
    id: Keuken Beweging
  - type: no_motion
    platform: device
    device_id: 6398dbc0c917aa150cd1fe2538d1d7c5
    entity_id: 567194f69cee99f48dcd070c2ae5eb15
    domain: binary_sensor
    for:
      hours: 0
      minutes: 3
      seconds: 0
condition:
  - condition: sun
    before: sunrise
    after: sunset
    enabled: true
  - condition: state
    entity_id: automation.sensor_keuken_memory
    attribute: current
    state: 0
action:
  - if:
      - condition: trigger
        id:
          - Keuken Beweging
    then:
      - data:
          scene_id: memory
          snapshot_entities:
            - light.hue_lightstrip_plus_2_links
            - light.hue_lightstrip_plus_rechts
            - light.hue_go_1_keuken
            - light.hue_color_lamp_keuken
            - light.hue_smart_plug_1
        action: scene.create
      - metadata: {}
        data:
          transition: 5
          kelvin: 4835
          brightness_pct: 100
        target:
          entity_id:
            - light.hue_lightstrip_plus_2_links
            - light.hue_lightstrip_plus_rechts
        action: light.turn_on
      - metadata: {}
        data: {}
        target:
          entity_id: light.hue_smart_plug_1
        action: light.turn_on
      - metadata: {}
        data:
          transition: 5
          rgb_color:
            - 207
            - 139
            - 23
          brightness_pct: 100
        target:
          entity_id: light.hue_go_1_keuken
        action: light.turn_on
      - metadata: {}
        data:
          transition: 5
          rgb_color:
            - 207
            - 139
            - 23
          brightness_pct: 100
        target:
          entity_id:
            - light.hue_color_lamp_keuken
        action: light.turn_on
    else:
      - data:
          transition: 10
        target:
          entity_id: scene.memory
        action: scene.turn_on
mode: single

Regards,
Gunther.

Hi Gunther,

You need to reference a global variable.
When you get a trigger, check for the condition of a helper boolean (that you need to create) and make sure it’s off.
When you hit the first action, turn the boolean on.
Do you thing with the lights, and the last thing you do at the end of that action is set the boolean back off.
This prevents it from triggering again.
Now, should the automation fail or get interrupted somehow, the boolean will get stuck on, so add another automation to turn the boolean off if it’s ever on for say 10 minutes continuous or you pick a number. A watchdog if you will.