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?