Conditions and Triggers: The difference?



Without wishing to comment further with conditions and triggers I thought I would comment on your pistons. (If you don’t mind).
Piston 1.
Instead of 2 IF statements, use 1. Change your first IF to a Time Is Between.This means that the piston can run anytime in that window should it be evaluated and not only at 2 fixed times.

Time is between 45 minutes to Sunset and 15 minutes past sunrise.
White bulb 1
Turn On.
Turn Off.

Piston 2.
As you are mixing conditions and triggers I always take a belt and braces approach to make sure everything subscribes as I want it to.
Click on your 3 IF statements individually and the the settings cog at the bottom.
Change each IF statement to ALWAYS Subscribe.


Thanks again @bangali. I’ve been learning more with each piston I mess with. So I agree, practice will get me a better understanding of whats going on.

Thanks. But I just want the light to turn on at 45% at a specific time (45 minutes prior to sunset) and then turn off at a specific time (15 minutes past sunrise). So why would I want the piston to be able to run at anytime between those 2 times? Genuinely asking, because I could certainly be missing something. In my head since I want the light to turn on and off at a certain time, I made those times my triggers and separated the IF’s.

Also, what function does ELSE serve in your example? I’ve not used that yet. And what is the difference between END WITH and END IF?

Thanks again. This made sense to me earlier, and what I tried with a few pistons but they were still funky. Most likely was something else though. This basically prevents the piston from ignoring conditions, correct?


I just do things this way as it makes it easier to test the piston when building them.
You hit the test button and if its true it works. If you use a specific time, test will not work for the piston as it will only be true at that specific time.
Either way is good and will work.

If the conditions are false then the ELSE with execute. i.e. Turn off the lights. Again helps to test things when building.

Correct. It forces the piston to subscribe to all regardless.

It’s probably just me but I like belt, braces, hard hat, steel toe cap boots, the list goes on.

It’s good that you ask the questions. Better to learn than follow blindly.
Everyone is here to help and we will all offer slightly different ways of doing things because we are human. (Well most of us).
Have fun. :wink:


Thanks again @bobbles. Did some playing around last night, and things are making much more sense to me now. Got all my pistons working as expected as well. Just like you guys said, playing around, testing, fiddling, etc. makes things easier to understand. And, of course, the help from the great people on here and the ST forums!!


Is there a role for the ELSE section of a piston when there’s a trigger in the IF block?

I can understand with conditions, one set of actions occurs when the condition is true; ELSE is basically when the condition(s) is false, and a different set of actions can be configured. Right?

So what does ELSE do when the actions in a piston occur after a trigger?


often triggers have multiple events generated by each such trigger. since the piston will receive all of these events sometimes else can be useful to code for scenarios other than the trigger being true. but you are right, strictly speaking you dont really need else every thing could be in an if block. but else allows to do things like this:

if motion changes to active (trigger)
   turn on heat
   turn off heat (this will run when motion changes to inactive)
end if


Excellent thread! I am just a week into exploring webCoRE though I have been playing with ST for a year. I am having an issue with a piston which I hope will help augment this discussion on triggers. I understand that one exception where you can have more than one trigger in a single IF is when using ‘followed by’.

Here is my use case: When I enter the garage and close the door, ‘followed by’ opening my garage (detached) door lock, I want my back door lock to my house to unlock. The code and the log follows. While the first trigger shows evaluating to true in the log, the second trigger evaluates to false even though the lock status shows as ‘unlocked’. This is very puzzling! Please help.


I have this:
If weather alert changes to Rain
Send Push notification “turn off irrigation”

It fires a bunch of times during the run-up to a rain storm, and a bunch of times during the storm itself. Gets annoying.

I’m guessing I should make a Boolean variable: ‘irrigation’
And when alerts come in, set that variable.

And then only when the variable itself changes, send the push notification.
I’ll have to try it out.

Edit: actually, I’m not really happy with this piston. Will start a new topic or look for one that addresses it best.


In my opinion this is over complicated. (just my opinion,m I do it all the time) lets start with what I think is the end of the two minute timer its expecting you to unlock the door. Not during or after. You should change that to “Garage Door lock is unlocked” That way at any point you’ve unlocked the garage door , when it reaches the 2 minute timer then your back door unlocks.

Now I question why have the timer at all. If the combination of the garage shut and the garage lock is unlocked then just unlock the back door. I assume your accounting for the time it takes to get to the door.
Maybe re right it like this if you want the timer.

Garage Door Closed
and Garage Door lock is unlocked
wait 2 minutes
then Unlock Back door

This is how I do mine.


Thanks @logeox. Let me explain my scenario a little better. When I close the garage door (that triggers the event), I am still sitting in my car and my ‘garage door lock’ is still in ‘locked’ state. So, if I use the IF condition that you suggest, it will still fail (because it will the check lock condition as soon as the ‘garage door closed’ trigger activates). The ‘followed WITHIN 2 minutes’ is not a simple WAIT for 2 mins timer, but I was presuming is an anticipation of a new trigger within 2 minutes (which in my case is, me getting down from my car and opening my garage door lock).

My hope was that @bangali (or anyone else) can explain the use of ‘Followed WITHIN x minutes by’ in an IF statement while expecting two distinct triggers.

Thanks again for your response.


This article I saw a while back and found it very information. It has an example of what you are trying to accomplish.

There is a difference in your version of code and mine. “Changes to” is a trigger! In my version Garage door “Closed” is a condition. So you can sit in your vehicle for as long as you want. Now the moment you unlock the Garage Door Lock, that’s the trigger. No you you have a state were the trigger and condition are true so it then proceeds to start 2 minute timer then unlock your Back Door after the timer.

There are more than one way to accomplish the same things. To each his own. Good luck.


Hi, I have a question about a piston I am writing. It’s very simple, but I think I may have an issue with a condition vs a trigger. The piston is very simple, it checks a contact sensor on my fridge to see if the door has been left open.

Here is the issue I am having. It seems like randomly it will tell me the door has been left open, but I can see it isn’t. What i think is happening is that it must be almost like adding up the time the fridge has been open over some time period. My piston states that if the door stays open for 5 mins. But in my head it can also work if i make it read WAS open for at least 5 mins.

All i really want is an alert that tell me if any any given time the doors has been open for a continuous 5 mins. Once closed it resets and starts the timer again when the contact changes to open. I feel like this is pretty basic, but I think I may be using the condition and triggers incorrectly.

Any able to help me diagnose and understand?



please post a green snapshot of the piston.


The 2nd one seems to cause the false alarms. Not sure if the first one fixes it, but was going to try.


this one reads was open. did you also try stays open for 5 minutes?


sorry i posted before i got both pics in. the stays ones seems to trigger the false alarms. I am not sure i understand the difference. only thing i can think of is the stay command maybe added up multiple mins when the fridge is open over some time period?


so 4x38i works fine but y7wqt doesnt?


i just tried the y7wqt piston it seems to work fine.

please turn on full logs and share the logs for when it has a false alarm.


ok, it may take a day or 2 because it doesn’t always say it. if i have open for a minute or 2 then close it sometimes triggers and sends the message later.

i test the one with WAS and it works, but won’t actually trigger the push or songs announcement until i close the fridge door.



  • the way was works is when the contact sensor is closed it will check when the contact was last opened and if it has been at least 5 minutes since then it will evaluate the condition as true.
  • the way stays works is when the contact sensor is opened it sets a timer for 5 minutes and when the timer expires if the contact is still open it will evaluate the condition as true.