Quick changes - only actioning on one event?

I’ve got a bunch of MySensors placed throughout, and one of them is a distance sensor at the foot of the stairway to sense a person, and turn on a strip of LED lights running up the stairs under the railing.

Here’s the automation code:

- alias: 'Turn on stairway lights 20 seconds'
  trigger:
    platform: state
    entity_id: sensor.stairway_distance_sensor_9_1
    from: '1'
    to: '0'
  condition:
    - condition: state
      entity_id: light.dimmableled_2_0
      state: 'off'
  action:
    - service: light.turn_on
      entity_id: light.dimmableled_2_0
      data:
        brightness: 255
    - service: notify.alert_david
      data:
        title: "Stairway lights on"
        message: "Turned on"
    - delay: 0:0:20
    - service: light.turn_off
      entity_id: light.dimmableled_2_0

Now, the distance sensor likes to send a lot of updates quickly, so I put a condition in its local logic to not send an update unless it’s a major distance change. As a result, the “distance” is always ‘1’, unless somebody walks in front of it, then it is ‘0’. But, sometimes it will quickly cycle from 1 to 0 a few times when somebody is in front of it. So, I put a condition to only turn the lights on if they are already off. They only get turned on by this sensor.

Still - despite the condition, the round-trip time to turn the lights on, confirm they are on, and then update the state is apparently too long, and I still get double or triple executions in this automation (using Pushbullet to let me know).

Any way to get more current state for condition, or force only executing once per second or two?

You could kick off a script that has a delay and use that as a debounce mechanism. Scripts that contain delays have a state of “on” when they’re active and “off” after the delay/script has completed. You could use that as a condition.

Also, if you search around, I think I’ve seen some people use template conditions in conjunction with an automation’s last_triggered value.

1 Like