Prevent Motion Light Piston from Triggering When Voice Command is Used to Turn Lights On


#1

1) Give a description of the problem
I created a piston that uses our Ring Doorbell as a motion sensor to turn our porch lights on when motion is detected. I then created a second piston that waits 2 minutes after motion ends, unsubscribes from the first piston for 15 seconds, and turns the lights off. This prevents the motion sensor and lights from looping endlessly however, it also limits me to only being able to use the porch lights as motion activated lights–or only being able to turn the lights on in 2 minute intervals.

2) What is the expected behavior?
In addition to using the porch lights as motion activated lights I would like to be able to ask Alexa to turn the porch lights on and have them stay on until I ask her to turn them off.

3) What is happening/not happening?
Currently, if I ask Alexa to turn the porch lights on this triggers the motion sensor and activates the piston that will turn them right back off two minutes later.


#2

You can try adding to your existing piston…
If
Motion is detected
And
Light is off
Then
Do

Or use a variable that depends on the state of the light.

But since you didn’t post an image of your piston, I am only guessing…


#3

Thanks! Yes…I see where you are going with this. I think I would need to combine my two pistons into one somehow. I’m not quite sure how to do this and avoid the loop that ensues when the lights turn off. I’ve posted my two pistons in case that helps. (These were the first two pistons I ever built–so please don’t laugh!)


#4

#5

This works perfectly! I’m posting my new piston here in case it would be helpful to others…


#6

I’m a little confused by this. You are setting a variable to false when the light is also on. This is a bit of duplication. The light will always be on when the variable is false, therefore one is duplicate. Also, you have it set to OR for the two dimmers. This means that if motion is detected and either one of them is off, both will turn on and then turn off. This means that your voice command to turn the one on will be overridden unless both of them are on at the same time. Also,be careful, you are using all conditions in your IF part of the piston. This means that both the state of the light and the motion sensor are triggers (see the little lightning bolt). If you truly only want the motion to be the trigger and not the switch, change the operator on the motion sensor to “changes to” instead of “is”. The way you have this piston set up, if either of the switches get turned on while motion is detected, the sequence will begin again. I think this might get you into a loop. It will definitely cause multiple triggers of the piston to occur most likely resetting your timer.


#7

So, I am VERY new to this and do not have a background in coding but I will do my best to explain this the way I understand it. I originally had the operator on the motion sensor set to “changes to”, but switched to “is” when I built this new piston simply because that is way the person in the thread jkp linked to had his set up. That person did not have the state of the lights as a condition but still had an issue with looping. Am I to understand it is the “is” operator on the sensor that would cause it to loop? I think the way I got around the loop you are talking about is by changing the “with” statement to “never cancel tasks.” Someone mentioned this in the thread jkp posted and it seemed to work to prevent the piston from resetting and getting “stuck”. So as it is, it is not getting stuck in a loop, but perhaps there was an easier way to achieve that end?

As far as the dimmers being set to OR. That was an initial oversight. When I noticed it, I was going to change it, however, it doesn’t seem to be causing a problem since we never turn just one on. We always turn both of them on at the same time using a single command. However, I would change it if it turns out to cause problems.

In looking at the variable settings. You make a good point. I don’t have a good understanding of Boolean variables. My intention was to turn off the motion sensor for a few seconds while the lights turn off to prevent the motion sensor from being triggered and turning the lights back on. I was copying this idea from the piston posted in the thread jkp linked to, however my true/false settings are opposite of the other person’s piston because when I copied directly it did not work, but this did.


#8

I’ll take each of your points individually. The consequence of having both the switch and your motion sensor be the trigger is that both will cause the piston to fire. Therefore, if you change one of the two dimmer on, and motion is active, the piston will fire, turning on both dimmers for a set period of time and then turning them off. I don’t know the specific application…this might not be a problem. I just wanted to make sure that you were aware that both the dimmer state and the motion sensor are both triggers here.

As far as the motion sensor not triggering during the “shutdown” phase we’ll call it…most motion sensors have a configurable parameter, either through code of hardware, for a “timeout period”. This is a period of time that the sensor will remain in an active state after motion is no longer detected. This is to prevent too many messages going back and forth unnecessarily. So, check your motion sensor to see what time timeout is.

And that brings me to my last point, turning the lights off. Depending on the timeout of your motion sensor, you could change the structure to turn the lights off when motion goes inactive. That’s the great part about motion sensors, you can keep the light on when motion is detected. In your setup, the light will go out after 3 minutes, regardless of whether motion is still active or not. As long as the sensor continues to report motion, the lights will not come on. You would have to wait for the timeout of the sensor, the sensor would then switch to inactive, then you could move again and have the lights come on. That’s one of the drawbacks of using a timer to turn the lights off. If you are going to use a timer rather than motion detected, I would recommend setting your motion sensor timeout to something very small, like 2 seconds. That way, you won’t get caught with the lights out. However, the best way, IMHO, is to set the timeout for your sensor at 3 minutes and turn the lights off when the sensor reports inactive. That way the lights will stay on as long as motion is detected and then 3 more minutes, just in case you’ve only stopped moving for a second.


#9

This is really helpful. Thanks. After reading more about triggers vs conditions I took your advice and changed it to one trigger. I also changed the OR on the lights while I was in there.

I don’t know if I can change the time out period since I am using the Ring doorbell as my motion sensor and their options seem pretty limited, but I will play around with setting it up to turn off the lights a few minutes after motion ends. We’ll see how it all goes. Thanks again.