Controlling tasks from running too much in webCoRE - Task Execution Policy

When writing automations, sometimes the devices being monitored generate a lot of events - this is common with temperature, power, vibration, and motion sensors for example.

Especially with temperature, this can cause logic to execute many times, and sometimes with unwanted side-effects.

Here is an example from the webCoRE forum:

What is going on:

  • the temperature device could keep sending readings that are all above check level (46 degrees) in line 18.

    • the intent of the automation writer is if the temperature remains above for 90 minutes to do some actions. (remains above means the current reading and the previous reading are above the check value)
  • if the temperature keeps changing (but always staying above 46 degrees), the piston will keep reseting the wait for another 90 minutes - ie as written the piston is checking it is above 46 degrees for the last two readings and does not change for 90 minutes...

  • take for example the temperature readings are coming in like 42, 49, 51, 53, 48, 55... at a regular basis (and less than 90 minutes apart)

    • When the 49 degree reading comes in the comparison will still be false, as the change was 42 -> 49 (ie it did not remain above 46 from the previous reading)

    • When the 51 degree reading comes in the comparison will be true as there have been two reading above 46 degrees, and the goal was to start the 90 minute timer. So long as all the subsequent readings are above 46 degrees, they wanted the notification to happen 90 minutes from the 51 degree reading.

    • The unwanted side effect is the readings after the 51 degrees wakeup the piston, and the if at line 18 is true and this causes the tasks including wait at line 20 to be reset/restarted...

So what to do?

  • webCoRE has a feature Task Execution Policy (TEP) just for this:

    • TEP is applied to the task statements (in this example the block of tasks at line 20, that are controlled by the if at line 18)

    • by default TEP is set to always execute the tasks if the block is executed, which in this case is not doing what we want

    • TEP should be set to "Execute tasks on condition state change only"

What this does:

  • As long as the result of the if statement on line 18 remains unchanged (ie the readings starting at the 51 degrees and forward stay above 46 degrees), webCoRE will not re-execute the tasks controlled by line 18's condition, since the tasks have already been started/run.

  • this setting is done by selecting the block of tasks (when editing it looks like with) and use the gear icon to change Task Execution Policy

In this example, the default Task Cancellation Policy (TCP) is doing the right if the temperature drops to 46 degrees and below, it will cancel any pending waits for the tasks, and end the timer.

TCP is discussed in this tip

Documentation for TEP:

Original post:

1 Like


Download the Hubitat app