CoRE Piston based on presence incorrectly running all the time

So I hope someone can help me out with this… I’ve got a piston that I want to have turn on my porch light on whenever it’s after sunset and before sunrise and triggered by my SmartThings arrival sensor & iPhone being present, but I’ve noticed that they both are always show they are falsely coming or going causing the porch light switches on & off. It’s generally only on for about a half hour to an hour, but still wastes electricity plus by now I think my neighbors must be wondering what the hell im doing.

Is there a more reliable way to do this? Can I put another condition in that will present this from happening? Thanks!

Post a picture of your piston so we can check it out. What I do in this situation is add a variable that would indicate that light has been turned on previously and include that as a condition. When it’s time to turn off the light, then add a task that will reset that variable to false.

Oh my bad - I saved the picture but spaced out on uploading it.

I would insert another condition in your condition set. Initialize this local boolean variable.

Variable lightOn is false

Then in your set of tasks, right after the push notification.

Set boolean variable lightOn to true
Wait for common time (sunrise)
Set boolean variable lightOn to false

Let me know if that makes sense.

I’m going to try that, but as for it making sense - not really. I’ve been wondering how to use variables for a while now and tried once before with no success.

On a side note, can you set a variable to save the on/off state and level of a dimmable light so I can have a level increase to 100% flashing multiple times when a contact sensor status changes, but afterwards have the light return to whatever brightness it was at before the piston ran? Not see if that makes sense or not.

You can use the Save attribute to variable tasks for that. Make sure to add a Wait of about 2 seconds before you perform any other task on the light/dimmer to give it time to save the variable. To restore the settings, use Load attribute from variable

1 Like

Thanks for your help - I’ll try fixing my porch light tonight and let ya know how it works.

One more thing - do you know if there’s a way to duplicate pistons to copy what I’ve already done and still have something there in case this won’t work?

Ok so I went back in to add another condition, chose variable then Boolean but don’t see one that’s says lighton. All these start with $ before the words and none have lighton listed. Am I in the wrong area?

No way to copy/duplicate pistons at the moment.

You need to initialize/create the variable first. Open your piston and at the bottom should be an area to Initialize variables.

How does this look?

You’ll need the condition Variable lightOn is false in your IF


It has to be in the same group as the first three conditions.

LOL I told you that I’m still not fully understanding everything yet - this good?

That looks like it should work. Just to explain the the use of the variable lightOn. This will prevent the light from turning on again until the next day. Now, in this scenario, I don’t see the porch light being turned off by the same piston so once your other piston turns the light off and the phone presence comes and goes again, it will not turn on the porch light again.

I believe you have a problem with Time is after Sunset and Time is before sunrise. Before Sunrise is midnight to sunrise, After Sunset is Sunset to midnight, therefore both can’t be true together. Instead put in a piston restriction: Only execute if time is between sunset and sunrise.

Ok so I put the command for turning the switch on as pointed out by the red arrow…

I think what he was trying to say was to remove your two TIME conditions and add them as a restriction instead.

Or you could remove one and change the other so that time is BETWEEN sunset and sunrise

Ok so now the porch light doesn’t come on at all automatically.