Lights Left On Notification- Please check my "math"

loops
presence

#1

I’m trying to create a piston that notifies me a specified amount of times that a light has been left on and there is no motion. If the light isn’t turned off, then it would be automatically switched off.

More or less, here is how I’d like it to flow:

  1. Light is left on and there is no motion for 30 mins
  2. Send a notification that light was left on, repeat this up to three times with 1/2 hour in between.
  3. If light is turned off before the loop completes, then break the loop and send a message that the light is now off.
  4. If the light isn’t turned off after the loop ends, then turn off the light.

See below for where I’m at. I could mostly use help with the loops and stopping said loop if a condition changes. Any help would be really appreciated!


#2

At line 27 you’ve used a trigger instead of a condition. If you change is from changes to off, to is off this should work for the notifications if I am reading it correctly.

The switching it off at the end won’t work though as that is in an else if of the outer IF statement meaning once you hit the loop it won’t be run. You need to more the else if to an IF which is immediately after the loop and says if light is on then turn it off.


#3

Try this (Just fill in the light bulb and motion sensor in lines 18&19, and make sure to have piston execute itself on line 39):


#4

Thank you. You went above and beyond!

So when you say “your webcore,” why does the piston self reference itself?

I noticed starting at line 50, you had the light turn on if it detected motion. What I was attempting to do is the opposite. If the loop of “lights on” messages cycles through and the light is still on and motion still hasn’t been detected, then turn off the light. Here’s my attempt:

I may have a couple more questions for you so I can understand what you did why you did for future pistons.


#5

You wanted a 2-hour loop, it calls itself after a 30-minute wait (max 3 times) to achieve that.

I noticed starting at line 50, you had the light turn on if it detected motion.

Yes, I assumed that you would want the light on if there was motion. It also resets the loop counter to 0 (thereby restarting the 2-hour loop). But it shouldn’t interfere with the 2-hour loop if no motion. In your version, the Piston won’t get to the stays inactive for 3 hours bit until after it loops through my 2-hour loop. Try mine and see if it does what you want. Feel free to ask me any questions.