Issue with Motion Piston

motion

#1

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.

image

Thanks!


#2

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.


#3

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.


#4

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.


#5

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:

  1. When should the piston run? In this case, whenever Motion Sensor 1’s motion attribute changes.
  2. Is the condition (actually a trigger in this case) in the if statement true? It will be only when the event is Motion Sensor 1’s motion attribute changes from inactive to active. In this case the tasks in the if statement will start to execute.
  3. Is the condtion/trigger in the if statement false? If so, and there are any pending tasks (wait & turn on), should they continue to run or be canceled. This is controlled by the TCP setting of the with statement. If it’s the default, then yes, they will be canceled. If, however, TCP is set to Never, then the tasks will not be canceled and will run to completion.

#6

^^^ What @pnbruckner said. A way more comprehensive explanation than what I said :slight_smile: lol


#7

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?


#8

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.


#9

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.


#10

Here is a sample of my pistons with the variables…


This take into time, and motion versus physical turn on.


#11

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.