I have a device (Not tied to HA) that is triggering a binary sensor in HA. When this devices activates I want it to turn on a Series of lights and then after a certain time frame turn them off. Now the trick that I can not figure out is if those lights were on prior to this automation being triggered I do not want them to turn on.
Currently the device triggers the Sensor to on and then after the certain time frame triggers it to off to which I thought about setting two Automation’s up one for turning the lights on and the other for turning them off. However I am not sure if using one automation to get the before condition with a delay set to turn them off after the certain time would work better. I am open to either.
Can anyone help me with this? I think it is a particular condition but I am unable to find exactly what looks like would do the trick.
You may find that it’s easier to use a script to start the timer (you don’t have to pass arguments in the body of the URL from the outside sensor).
Then have an event that watches that timer’s state (it becomes “active”). That automation should have a condition that checks whether the lights are on so that it won’t fire if they are. Or if you’re using that binary_sensor for other things, have an automation watch the binary_sensor.
An easy way to poll a several lights is to put them in a group. The group will become “on” if any of the lights in the group are on.
Then watch for timer.finished to turn the lights back off.
Triggering a timer (rather than the sensor) has the added benefit of letting you have the remote sensor set the timer repeatedly while sensing. You can have each sensed event restart the countdown on the timer.