I have an automation that triggers when a smart plug is turned on.
I’d really only like it to perform its actions if the switch turns on because of events outside of Home Assistant’s control e.g. if the user presses the button on the smart plug. I don’t want it to perform the action if the switch is turned on by someone using the Home Assistant web or app GUI or if another automation turns it on for other reasons.
Is there any way of determining in the automation whether Home Assistant turned on the switch or if it just turned on without HA having asked it to?
If you wish; either way, the critical thing is if the template achieves your stated goal.
FWIW, if you ever want to inspect the automation’s trace, your version will report a single boolean value whereas the other reports three (makes it easier to inspect each one separately). Plus it’s slightly less verbose because the logical ANDing is implicit. However if you feel those benefits don’t outweigh any minor performance improvement, use your consolidated version.
I come from a C/C++/assember bare-metal embedded design background so looking for efficiency is automatic. Not all of us have gigabytes RAM and gigahertz CPUs. Some of the stuff I work with still has kilobytes and megahertz or even less.