Preconditions

Interesting observation about preconditions this morning.

I have a motion sensor set to turn on a lamp using the built in Automations. It’s set with a precondition to only execute between the hours of 10pm and 5am.

While reviewing the history log today, I noted that the Automation is executing outside of that time period. Like it should, it’s not actually turning on the lamp, but it is executing per the history.

Seems sort of counterintuitive to me. I would have thought the precondition would have prevented any processing of the Automation, saving some resources. Or at least some log space.

Is this how the preconditions work?

It is not the precondition that triggers the automation.
It is the change of state of the device (motion sensor) that triggers the automation.
The precondition is the cause of the “Then” part not being executed if the precondition is not met, period of time in this case.

EDITED:
Since the release of new app, last June, all automations that are triggered are shown in the history, whether or not the “Then” part is executed.

If you write an automation that has the state of a device as a precondition and you make it change state only that device, you will not see anything in the history, since the preconditions do not trigger the automations

Got it. I was surprised, as I thought it would be more efficient to not even monitor for the change of state if the precondition is not met. But I understand and won’t lose any sleep over it if it works. Thanks!

1 Like

This is really silly. I can’t think of a single person that would expect History to show an automation that didn’t meet the conditions.

4 Likes

Well, it doesn’t make a lot of sense, but they may have thought of it as a debugging aid. It is how the IDE live logging looks with the smart app, smart lighting, the events are shown whether or not they meet the condition.
In addition, this history information can be hidden

I see exactly what you mean.

It would be tempting to think of an Automation like a script. When it gets an event that might be of interest, it evaluates all its conditions there and then to see if it needs to do anything. So in your example you could say what happens with the motion outside the precondition could be ignored.

You could go to the other extreme though. You could consider the Automation as a logical grouping of Conditions, all of which are constantly being updated. Then when a trigger event happens the Automation works with the already evaluated true and false values to decide if anything needs to be done. So in this case you very much have to keep monitoring everything.

How do Automations behave? I don’t know, but there is definitely an air of the latter about them.