Can anyone tell me why the switch 2 (lights) in this piston are not turning off after 5 minutes?
The sensor’s active state becomes inactive after 4 minutes.
Thanks!
Can anyone tell me why the switch 2 (lights) in this piston are not turning off after 5 minutes?
The sensor’s active state becomes inactive after 4 minutes.
Thanks!
Because the piston runs again when the motion sensor becomes inactive, and at that point the condition is no longer true, so the pending events (the wait and turn off) are canceled, because that’s the default. You can change the Task Cancellation Policy (TCP) of the with statement to Never and that would resolve the issue.
Thanks!
I don’t quite follow why the piston would run again when the motion changes to inactive, but i’ll take your word for it, and make the change you have suggested.
It’s because the piston is subscribing to events of that motion sensor. So when the motion sensor changes to inactive, webcore knows it needs to evaluate the piston again and decide whether or not to run.
This is fairly basic to how pistons work. The trigger you have (Motion Sensor 1’s motion changes to active) causes Motion Sensor 1’s motion attribute to be subscribed to, which means the piston will run whenever it changes. That’s separate from evaluating the trigger, which will happen every time the piston runs.
So there’s three separate things going on:
Hold on a sec… There’s been some good info relayed here. However, what’s the goal of this piston? If the goal is to have the lights go out after the motion has changed to Inactive then the proposed solution (setting TCP to never) does not actually do that What that setting will do though is to ensure that the lights go out 5 minutes after motion turned them on. It does not mean that they will go out 5 minutes after the motion is Inactive. That may be an important distinction.
If you want the lights to go out exactly 5 minutes after they came on… Set TCP to never. However, if you want them to go out 5 minutes after the motion is Inactive then you need a different approach. Which is it?
As the OP, what I was looking for was to have the lights go out 5 min after they turn on, not 5 min after the motion is inactive.
It would probably be better to set it maybe to 10 min or so, and have them stay on if motion is detected again before the 10 min are up… or have them turn off if no motion is detected for X minutes.
One step at a time.
I had a similar issue and the suggestion to have another if statement on motion stays inactive for X minutes corrected mine… (I had issues with the task cancellation policies)
If
Motion changes to active
Then
with switch
Turn on
If
switch is On
and
Motion Sensor stays inactive for x minutes
Then
with switch
Turn Off
Mine is more complex as I use variables to see if the light was turned on manually or turned on with motion. As the above would turn it off after x minutes no matter how it turned on.
Here is a sample of my pistons with the variables…
Thanks for your info.
Your example looks like something I could use.
I have programming experience, just trying to learn the nuances of piston coding, and the possibilities.