When do rules fire?

I have rules that appear not to fire but perhaps my understanding of the conditions for firing are wrong.

These ones I think are obvious (but maybe I’m wrong):

  1. Motion sensor - fires immediately on activity
  2. Open\Close sensor, button or switch - fires immediately the state changes

But what about these?
3) Temperature Sensor - Does the rule fire each time the temp sensor reports the temperature (5 minutes). Or does it report every 5 minutes AND whenever the temperature value changes.
4) Do the same rules governing temp sensors apply to thermostat.
5) Smart Weather Station - Do rules fire when a particular data point changes or are these polled at a predetermined frequency?
6) What about a Rule where the Event Trigger is always True. For example a motion sensor that is always Inactive (in a drawer or dead battery) or a thermostat temperature that is less than 100. Do they fire every second, every minute, every 5 minutes?

Is there a resource that would answer these kinds of questions. Without knowing when Rules SHOULD fire it becomes even more difficult to troubleshoot.

I will file a bug report for the specific Rule issue I have but I think this would be a useful topic for people to understand more fully.

1 Like

Rules are always run based on Triggers which are instantaneous events like a device changing state or time ticking over to a particular time.

As shown in the screenshot above, Triggers can either be Event based or Time based - either way, those are instantaneous events that cause the trigger to be evaluated. If the trigger condition is met, the rule is run.

Note that Event Triggers are always OR’ed together. Meaning that when any of the triggers become active, the rule will be run.

Event Triggers

Event based triggers include the following options:
image

As you might infer from the name, these type of triggers occur based on events in the home. With events being the instantaneous moment that the state of the thing, mode, or alarm status changes to meet the specified condition. (This is different than If Conditions that we’ll talk about later that are based on checking what the current state is)

  • Device
    • When you select a Device based trigger, you’ll then be prompted to select the Device, Attribute, Operator, and Value.
    • These are evaluated anytime an event is reported from your hub to SharpTools
      • For most devices, this is anytime the attribute value changes - whether that Thing’s attributes update only based on events from the physical device or whether it polls the physical device for changes
    • These are triggered as soon as the attribute state changes to meet the condition you specify
    • For Example:
      • ‘Motion is active’ - as soon as the motion changes from inactive to active, the rule is triggered
      • ‘Temperature > 70’ - each time the temperature changes, the trigger is evaluated and if it’s above 70, the rule will then run. eg. 69=false → 70=false → 71=true → 72=true → 71=true → 70=false; So each time the temperature is reported and it’s above
    • Also keep in mind that you can set up two triggers for an attribute with exactly opposite conditions to trigger anytime the Thing’s attribute state changes
      • For example, setting up triggers with ‘Motion is active’ and ‘Motion is not active’ will cause the rule to trigger anytime the motion status changes
      • You typically will want to use this along with a condition inside the flow
  • Routine
    • These are triggered whenever a SmartThings Classic ‘Routine’ is executed.
    • As soon as the selected routine is executed, an event is sent to SharpTools and this is considered triggered
  • Mode
    • Whenever the SmartThings or Hubitat location’s mode changes to your desired mode, this will trigger.
  • SHM - Smart Home Monitor (SmartThings Classic)
    • Whenever the Smart Home Monitor state changes to your desired status, this will trigger
  • HSM - Hubitat Safety Monitor (Hubitat)
    • Whenever the Hubitat Safety Monitor state changes to your desired status, this will trigger

Time Triggers

Similar to Event triggers, Time Schedule triggers are instantaneous events that trigger a rule.

image

When the time ticks over to your configured time schedule, the rule will run.

  • Timer
    • When the time changes to the specific time, run the rule
    • Also has options for repeating on a daily basis, only on certain days, or one time (‘none’ repetition setting)
    • Note that these require that your approximate geo coordinates are set for your location, so the system can figure out your timezone.
  • Sunrise
    • When sunrise occurs at your location, run the rule
    • You can optionally specify an offset before or after sunrise - for example, 30 minutes before sunrise
    • Note that these require that your approximate geo coordinates are set for your location, so the system can determine the sunrise and sunset for your location
  • Sunset
    • When sunset occurs at your location, run the rule
    • You can optionally specify an offset before or after sunset - for example, 30 minutes before sunset
    • Note that these require that your approximate geo coordinates are set for your location, so the system can determine the sunrise and sunset for your location

Once a rule is triggered, the Flow is evaluated / executed.


So back to your specific questions:

  1. Motion sensor - fires immediately on activity
    The trigger condition is evaluated anytime the attribute value changes and if the trigger condition is met, the rule is triggered and run.

    Keep in mind that some motion sensors have multiple attributes, so if you have something like ‘Kitchen Motion Sensor - motion is active’ as the trigger, the trigger will only be evaluated when the motion attribute changes and will only trigger the rule to run when the value specifically changes to ‘active’

  2. Open\Close sensor, button or switch - fires immediately the state changes
    Same comments as motion sensor.

  3. Temperature Sensor - Does the rule fire each time the temp sensor reports the temperature (5 minutes). Or does it report every 5 minutes AND whenever the temperature value changes.
    The trigger is evaluated each time the temperature sensor changes and triggers the rule every time if the condition is met. (See example in ‘Devices’ above)

  4. Do the same rules governing temp sensors apply to thermostat.
    Yes, anytime the attributes of a thermostat changes, the trigger is evaluated and if the trigger condition is met, the rule is triggered and run.

  5. Smart Weather Station - Do rules fire when a particular data point changes or are these polled at a predetermined frequency?
    The trigger is evaluated anytime the device reports an event and the rule is run if the trigger conditions are met.

    There is no periodic polling done from the rules at all - it’s always event driven based on the events that the device driver reports.

  6. What about a Rule where the Event Trigger is always True. For example a motion sensor that is always Inactive (in a drawer or dead battery) or a thermostat temperature that is less than 100. Do they fire every second, every minute, every 5 minutes?
    They fire one time when the event is received. So if the motion sensor was already ‘inactive’ in the drawer when the rule is setup, the rule will not trigger until the motion sensor becomes inactive.

3 Likes

This post is so well explained that we can turn this one into a KB article. :rofl:

4 Likes

Thanks Josh, that is a great set of explanations. The key message is that all rules are event driven.

I do have one clarification. In the case of temperature it has a checkInterval of 720 (seconds I presume)
image

So if the temp remained constant at 70, an event where “Temperature=70” would be expected to fire every 720 seconds (because the hub has received an update even though the temperature remains the same) or only on the first instance of changing to 70?

It depends on the device handler, but events are generally only generated when the attribute value changes unless the device handler has specifically be coded to force report state changes each time.

That being said, if multiple forced temperature=70 events kept coming in, the trigger would be evaluated each time and the rule would run each time.

Note that Zigbee and Z-wave temperature sensors report back on their own whenever temperature values change. Sensors, especially battery powered ones, are inherently event driven.

Regarding the checkInterval, this is part of the new SmartThings Device Health feature. If the device has the Health Check capability, the Device Health feature uses the checkInterval to determine the maximum amount of time a device should go without reporting events.

If the device hasn’t reported any events within that time period, Device Health will try to ping that device and if it still doesn’t generate any events, then SmartThings marks it as offline.