Help with a Motion Sensor not triggering again after it turns off


#1

1) Give a description of the problem
So I’m very very new to webcore so I apologize in advance if this question is silly, and I’m sure there are way simpler ways to write this piston. I made a piston that works with a motion sensor, a contact sensor, and a virtual switch. After the motion sensor activates and then stays off and turns the lights off, it doesn’t turn back on again when motion is detected.

2) What is the expected behaviour?
When I walk into the bathroom, the motion sensor should detect my motion and turn the lights on (Whether a virtual switch is active or not determines the brightness). Then, when the motion sensor stays inactive for a certain time, the lights should turn off. Then, whenever motion is detected again, it should immediately turn the lights on again.

3) What is happening/not happening?
The issue lies when the motion sensor stays inactive and turns the lights off. For about fifteen seconds or so after the motion sensor turns the lights off, it won’t recognize any additional motion to turn the lights off. However, there is a contact sensor that turns the lights on automatically if it’s closed and turns them off if it’s open, and that works completely fine.

So with that piston, switch 5 is a virtual switch that I use to determine whether or not I’m sleeping or not. That way, if I get up in the middle of the night and walk in, the lights won’t go on full blast, but rather at one percent. The contact sensor is on the door, so when it’s closed (in a situation where I’m showering, etc.), then the lights will remain on indefinitely.

Any advice will really be appreciated. This is literally my third day using webcore, and I’m very new to all of this. I figured this would be the best place to start.
Stay safe everyone!


#2

Welcome to WebCore! You will find a lot of friendly and helpful advice here.

A couple quick rules you want to follow. First, put triggers first since that is what will get the piston started, Then use conditions under that to fine tune what you want done. Second, never use the same trigger twice in the same piston (see the first rule :slight_smile:). So for example, lines 40-60 would work much better like this:

If motion sensor 1 changes to active
then
  if switch 5's switch is off
  then
     set level to 100%
  else
     set level to 1%
  end if
end if

I think for what you want to accomplish, you would need triggers for when the door is closed, when motion changes to active and when motion changes to inactive. Right now with 4 different triggers on the same motion sensor, response is likely unpredictable and likely causing semaphore delays. Try to clean up as I suggested and then repost with trace turned on and logging set to full and post the log along with the piston. Then perhaps we can see why something may not be working.


#3

Thanks for your help! I’m pretty sure I got it now except for one thing. I re-wrote the entire thing from scratch because that was way easier. I’ve got everything pretty much set up the way I want it with one exception. I’d like to have it so that when the switch I use at night (switch 6 in this example) is on, then the lights should turn off after two seconds of no motion, whereas if the switch is off, then turn off after ten seconds of no motion. If I understood you right, I don’t want to keep asking for the same trigger more than once, so what’s a good way to make that work?


#4

Does it really need to be 2 and 10 seconds of no motion? What if you set for 2 seconds of no motion but then add an if within that to just wait an extra 8 seconds if the switch is off?


#5

Well if I just wait 8 seconds, then wouldn’t it just turn off even if motion is detected after the 2 second period? I think this script works though, let me know what you think. I’ve added a part where if someone closes the door for a long time, then turn the lights off (since no one should reasonably be in the bathroom for THAT long lol)


#6

Overall, I think this should work. I think line 68 should still be broken out as a separate if. The else if can bury the trigger and it may not function properly. once you split the else if out, then the only when can be added as another condition to the if above to simplify execution. When switch 6 is on you will always send two off commands (at 2 and 8 seconds) but that won’t hurt anything. It just adds extra network traffic.

To you question, If you add the wait and motion occurs during the wait, triggering of the motion should interrupt the wait and keep the light on but you will need to test to be sure. Partially depends on the length of the wait but usually >5 seconds, a restart is scheduled and can be interrupted by a new event.