Conditions and Triggers: What's the difference?

difference
faq
conditions
triggers

#1

as new users join the community, we expect that at some point many new users will ask this question. so, heres a quick note.

conditions: if there are NO triggers in a piston, webcore checks the conditions to 
            decide which events that piston should be subscribed to. if there are  
            triggers in that piston, webcore does NOT subscribe to the events the 
            conditions refer to.

triggers: if there are triggers in a piston webcore ONLY checks the triggers to 
          decide which events that piston should be subscribed to.

2 common followup questions that come to mind:

1) why use conditions, why not only use triggers?

because 2 triggers can never be simultaneously true. in the following example, the AC will NEVER turn on. why? each piston processes ONLY 1 event at a time and triggers are sent to the piston as an event.

when room sensor’s motion changes to active the piston will receive an event. then checking the 1st condition, the motion changes to active will be true. the piston will then proceed to check the 2nd condition. since its a trigger, it will check the current event in hand and find that its not a temp sensor 1’s temperature event, so the 2nd condition check will fail. similarly if the event that is being processed was a temperature event from temp sensor 1, the 1st if condition check would fail since its a trigger and this is not the right event.

if Room sensor's motion changes to active
   and
   Temp sensor 1's temperature rises above 80ºF
   with AC
      turn on
   end wtih
end if

however, if you write the same if as following. when motion changes to active the piston will receive an event. when checking the 1st condition, the motions changes to active will be true. the piston will then proceed to check the 2nd condition. since its a condition, it will check the current value of temperature for temp sensor 1 and if that is higher than 80ºF, the 2nd condition will also be true and since all conditions for the if now evaluate as true, the AC will be turned on.

if Room sensor's motion changes to active
   and
   Temp sensor 1's temperature is greater than 80ºF
   with AC
      turn on
   end wtih
end if

2) why use triggers, why not only use conditions? :slight_smile:

mostly to avoid inefficiency. in the following piston, since this if only has conditions, it will be subscribed to events from both the room sensor’s motion and temp sensor 1’s temperature. when the piston receives and processes the event with temp sensor 1’s temperature, it will then check the if conditions and if both conditions are true then turn on the AC. however, we know motion is active not continuously but intermittently. so, its more efficient to check the temperature only when motion changes to active. hence, the example below while it would work, the example above is more efficient.

if Room sensor's motion is active
   and
   Temp sensor 1's temperature rises above 80ºF
   with AC
      turn on
   end wtih
end if

while the processing efficiency would not be significantly degraded in a simple piston like this example, as you write larger and more complex pistons and have many more of them, you always want your pistons to be as efficient as reasonable.

other questions on this? please ask away on this thread.

EDIT: what i described here is the default behavior of a webcore piston. it is possible to override this default behavior and pick which triggers are not subscribed to and which conditions are subscribed to. once you are familiar with this default behavior those dont take long to understand and use. :slight_smile:


Trying to turn off a light after two motion detectors show inactive for 3 minutes
Trying to create reliable motion activation for simple lighting without turning off while still in motion zone
Piston Won't Turn Off
$Var Event Count within $var number of minutes before $now
Presence based notification that loops until button press
First Piston (Relock Door (with timer) based on Time of Day)
Piston with global variable "does not change" as trigger, not triggering as expected
pinned #2

#3

All users, DO NOT RESPOND TO THIS THREAD.
This thread is a duplicate in 2 categories for the most possible user visibility.

All questions/discussions should continue in the other thread.

Please click the link and continue discussions there:


Motion sensor-triggered light won't turn off