The concept is basically the same, but the motion sensor is more likely to fire more frequently, thereby refreshing the current status, and causing the later part of the code to be skipped (unless TCP is set to Never).
Event not happening after WAIT
Actually, this is not the case. Notice how even me manually turning the switch off, (with no code for off anywhere), it still updated the status, and line 18 did not complete.
This is why in practice, we code âas ifâ the trigger only remains true for a moment, even though there are occasions where it may linger for a bit. The more complex your code is, the less you can count on those.
You are right. I figured out that I was testing by not subscribing to anything, flipping the switch, hitting âtestâ, and flipping the switch again. In that instance, I got both messages since nothing triggered the piston before the wait timer did. I canât believe I didnât run a test with a normal trigger. That is rather embarrassing.
Btw, I forgot to update this. The problem is that the Bosch motion sensor goes to Inactive a few seconds after becoming Active, thus canceling the Wait and all other following tasks.
My solution is as follows:
- Use âbecomes activeâ ONLY to turn the lights on and set a brightness.
- âUse âbecomes inactiveâ to set a brightness, initiate the Wait period, and turn off the lights after the Wait period.
This works on multiple levels. The sensor wonât report motion for another few minutes, even if there is motion in the room. If it does report motion, (1) above fires. This cancels task (2). Then a few seconds later (2) fires again, thus re-starting the Wait period.
Thanks for the help in understanding the issue.