Conditions and Triggers: The difference?

difference
faq
conditions
triggers

#69

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
else
   turn off heat (this will run when motion changes to inactive)
end if

#70

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.


#71

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.


#72

In my opinion this is over complicated. (just my opinion,m I do it all the time) lets start with what I think is wrong.at 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.


#73

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.


#74

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.


#75

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?

Thanks!


#76

please post a green snapshot of the piston.


#77

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


#78

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


#79

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?


#80

so 4x38i works fine but y7wqt doesnt?


#81

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.


#82

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.


#83

ok.

  • 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.

#84

does closing it reset that timer by default?


#85

the timer gets cancelled if the door is closed before 5 mins.


#86

Ok I finally caught it with a false alarm and logs turned on! Here’s a quick screenshot of the logs. If there’s another way to share or look at let me know.


#87

Sorry, not sure why photos uploaded like that?


#88

just select the log text and paste it. also please post the piston green snapshot as is with trace on.