Conditions and Triggers: The difference?

difference
faq
conditions
triggers

#126

Is there a time when a Condition becomes a Trigger?

I have a piston where I turn on a virtual switch, but within the piston, I use the state of the switch as a condition. But when I turn it on, I get a timed event that executes the piston. This seems to cause a

Piston waited at a semaphore for 10022ms

message since nothing was waiting on this event to occur.

Here is the log at the time that this occurs.

Here is the piston.

Any insights would be appreciated.


#127

If you have no triggers in a piston (like this one), then all conditions become triggers. Notice all the lightning bolts in the left margin. Each one of those are acting like triggers, and executing the piston at any event.


#128

Pistons have timeout handlers set on them so they are “time monitored” pretty regularly

During piston executions these timeout handlers try to recover the piston. When a piston is idle the timeout handlers check if the piston missed some early time setting. I expect this code was added during the ST platform issues in regards to schedules, run-in, etc.


#129

I thought the On Events at the top is the Trigger, and all other IS’s are Conditions. I did see the lightning bolts for the Conditions, which is why I was asking.

I just changed the On Events power statement to If power changes, and that seems to have fixed the IS-becoming-a-trigger problem. Now the only lightning bolt is for the power change Trigger and not any of the Conditions later.


#130

I would like to cut down on the number of times my piston is triggered. Therefore, I put a condition in in an attempt to stop the trigger from firing.


This piston controls a “My Ecobee thermostat”. The condition at line 58 should stop the trigger in line 60. What is happening is the piston is triggered every time there is a temperature change even though the setclimate is not “Low Heat”.

This piston has two jobs. When IFTTT detects an event starting, it triggers the piston and puts the thermostat in the “Home” climate for 5 hours. When IFTTT detects the end of an event, the piston is triggered and the thermostat is commanded to resume program.

Just looking for the reason that the piston is triggered all the time reguardless of the setclimate setting.
The second job is if the setclimate is “Low Heat” the thermostat is to just keep the building from freezing. Since a furnace’s exchanger will corrode when operated below 55 degrees, the room temperature has to be brought up to 55 degrees before it should be turned off. So when the setclimate is “Low Heat” the furnace is to turn on at 40 degrees and turn off at the heat setpoint. Therefore the piston only needs to be triggered by a temperature change when the setclimate is “Low Heat”


#131

Any line with a lightning bolt will trigger if that device’s attribute changes in either direction.

In your case, anytime:

  • Thermostat 1’s setClimate changes, or
  • Thermostat 1’s temperature changes
    Your piston will start at the top, and work it’s way down to the bottom.
    (executing any code allowed by conditions)

You cannot prevent a trigger from triggering unless you unsubscribe to it.
(and then it will never trigger)

The method I employ is keeping only one trigger per piston, and let my conditions below decide which path to take afterwards.


By the way, when I say “one trigger per piston”, I really mean one attribute for one device.

For example:

  | execute
ϟ |    IF Outlet's switch changes to ON
  |       Then do stuff
  |    END IF
  |
ϟ |    IF Outlet's switch changes to OFF
  |       Then do other stuff
  |    END IF
  | end execute

Even though there are two lightning bolts, there’s really only one trigger. (Outlet’s switch)


#132

(repeated for emphasis)
I also strongly recommend this policy. In typical coding environments, one usually groups all the similar functions into one program. In webCoRE, one can group similar functions into a single category, but putting them all into one piston often results in odd interactions and unnecessary triggering. (To be honest, this particular programmer had to learn this through an annoying amount of experience :slight_smile: )


#133

I see the point of one trigger per piston. So I could have a master piston that pauses and resumes another piston that controls the thermostat. A paused piston will not fire correct?


#134

I have created a control piston that pauses and resumes a piston for the Low Heat climate. When the piston is resumed in registers itself and starts working. Now there is now triggers at all when they are not necessary. I designed it like calling a subroutine. The control piston enables the Low Heat piston. the Low Heat Piston Pauses itself when the Low Heat climate is no longer in effect.

Works like a champ.


#135

First, I want to thank all who have contributed to this thread. I am brand new to webCoRE and just trying to learn as I go. After reading through the majority of this thread, I think I understand that triggers are what cause a piston to execute and conditions limit the task that occur when the piston is executing. Triggers automatically subscriber, conditions do not. You shouldn’t have more than one trigger in a piston because 2 triggers can not be true simultaneously and if you have no triggers, conditions will act like triggers.

What I am missing is how do I distinguish a trigger and condition in a piston that I am writing? I know this may be an obvious noob question, but I am a noob. Does the lightning bolt indicate the trigger? I have written a few simple pistons to do a few things. They all appear to be working as intended. I have pasted green versions below I would appreciate it, if someone could highlight for me the triggers and conditions. Any other comments on making these pistons better or more efficient would also be appreciated.

This piston, turns on a light when the doorbell is pressed as long as it is dark outside and then turns it off after 10 mins.

This one turns on 2 lights when a door is opened and it is dark outside, then turns them off 3 mins later.

This final one exercises the Water Main shut off valve. Once each month it, closes the valve and then reopens it, sending me SMS messages indicating the progress and completion.

I really appreciate any information that you can provide.


#136

Each device will display a bit differently, but basically, in the drop down, conditions are at the top, and triggers are farther down the list…


Yes, but the lightning bolt will also indicate a condition that is acting like a trigger.


#137

Piston umyjm:
Line 20 is a trigger

Piston ezc5m:
Line 20 is a condition acting as a trigger

Piston chwv6:
Line 17 is a time-based trigger


Essentially, a condition is vague, and can be true for hours at a time…
A trigger is precise, and only true for a brief moment…


#138

Thanks WCmore. That is really helpful.


#139

I’m having issues understanding the difference as well. I think the big reason for that is that when you want to add a new statement on a piston, you have 2 choices: if block or action:

If you go to if block, you have the option of adding a condition (which makes sense, since this is the regular terminology for a “if” in programming):

A condition requires a device and a comparison. A comparison can be a condition or a trigger (condition again).

That leads me to a couple of questions:

Question 1: a trigger makes me think of something that perform an action. I’m not sure if triggers in this context relates to the action displayed on the 1st pic. I believe it doesn’t. Does it?

Question 2: when you talk about a condition on this thread, is the condition as the comparison (first rectangle on the 3rd pic)? Or a condition in general (2nd pic), regardless of the comparison type?

Thank you!


#140

Hi Newbe question,
I searched the forum but could not find an answer. I want to turn on a light for X seconds and then turn it off. The trigger is activating a routine.
The thing is that I want that X will be different each time. I’m trying to find a way to pause the piston , ask the user to input X in a popup window on smartthings app, and continue with the piston. Is that possible ? This is what I did for now , but how to input the X parameter ?


#141

You are correct, it does not relate to the actions in your first picture.

In the context of this thread conditions and triggers relate to what is in your third picture. Triggers (second rectangle) will be indicated by a lighting bolt in the left margin. Triggers will start a piston running (which is why they are called triggers) whereas conditions (first rectangle) are just logic elements to determine which code to execute. Typical structure for a piston is to have a trigger to get the piston running followed by conditions to more finely determine the appropriate action.


#142

There is no way to do this I am aware of. You can do a JSON request through. website and get a parameter that way but I’m not sure webcore can wait too long for a user response. More likely, you would have to set a global variable somehow before you turned on the light.


#143

I use webCoRE and Alexa to accomplish this…

  • WebCoRE prompts me with a question…
  • I answer verbally to Alexa…
  • The same piston does things differently, based on my answer.

Feel free to play around with my method.

That thread only shows 3 three possibilities of “X”, but there is nothing stopping you from adding more options.


#144

Hi I have a question related to this.

I have 2 fans and a motion sensor. I want the fans to come on when motion is detected and turn of when motion stops. (I accomplished that) however I want to add a condition that if my lights are on and motion stops fans should stay on.

This is what I did:

If motion changes to active
Then
With switch 1 and 2
Turn on
If motions stays inactive for 3 mins
And light X is under 10%
Then
With switch 1 and 2 (fan)
Turn off

But it don’t seem to work. I can’t seem to find the condition of light status so.i used this.

Thanks for any help in advance.


#145

You should post questions like this in the piston design help but I think to do what you want you should make your light condition a separate if within the inactive trigger:

if motion stays inactive for 3 minutes
then
  if light X is under 10% then
     with switch 1 and 2
        turn off
     end with
  else
     with switch 1
        turn off
     end with
  end if
end if