Edit: Just to avoid misunderstandings, this originally was a reply to a very long thread that had a discussion about how people (don’t) understand the “if” and “when” of automations.
As someone who has a very technical background with 40 years of programming and system design experience, just having installed HA yesterday and having struggled mightily with even 2 very simple automations, here’s my 2 cents on the whole if/when trigger/condition situation:
Expressing to a computer that it should do certain things based on conditions that change over time always has been problematic and very non-trivial. Compared to what was the computer’s predecessor in many field of automation, the electro-mechanical logic, it’s even worse.
With electromechanical logic, all conditions are evaluated in parallel all the time. If you want some condition to not run, you have to add a ( ... ) AND NOT x
to it, i.e. power it down with an additional relay. While that seems daunting to design, if you lay out all the logic in text, it is very intuitive. (I recommend Technology Connections series on how a flipper machine works on YouTube.) The same is not true for a computer (or mircoprocessor, to be exact) that evaluates every instruction in sequence. That looks intuitive for writing instructions to do something (e.g. calculate pi), but when reacting to triggers and conditions, it becomes the opposite.
So, in my opinion, the main issue with HA’s automation is that they are not just executed by a computer, but also configured like a computer program. The most unintuitive thing about conditions over time is exposed to the user. Oops?
Were I to design such a system from scratch, I would go the other route and present it to the user like an electromechanical device, leaving the hard work of translating that to a sequence of instructions to the computer.
For example, an automation trigger could look like this:
(time is after sunset OR luminance sensor is below 20%) AND (any of (user1, user2, user2) is in zone "home") AND (motion sensor is triggered)
When entering state:
-> (X) execute once or (_) execute every [__] seconds
-> (X) execute immediately or (_) execute when condition persists for [__] seconds
-> run action [turn on lights]
When exiting state:
-> (X) execute once or (_) execute every [__] seconds
-> (_) execute immediately or (X) execute when condition persists for [30] seconds
-> run action [turn off lights]
The computer would then be responsible to find out on which state changes to evaluate the formula (i.e. when to trigger it). Also, action could have further logic, e.g. in this example to check in the “turn off lights” script if the lights were turned on manually and do nothing then. An advanced form would have more than two states, with conditions and actions for each possible state change.
Also, reading this topic has made me realise that my first instinct on how to write my automations was right and I just made it worse when I changed what I had done based on what the UI presented me as possibilities in the “when” section. I will change it back to running on a “every 15 minutes” trigger as I want it to activate no matter which in order my “and if” conditions become true. Is that the best or intended way to use automations? Probably not, but my device is more than powerful enough to check half a dozen on values every 15 minutes…
Probably will be something like:
When: every 15 minutes
And if: bedroom AC is off AND user1 is home AND bedroom temp is too high AND outside temp is too high to open the window AND window is closed AND none of the ACs are set to "heat" AND time is between sunset and 5am
Then do: set bedroom AC to "cool", remember that automation has turned on the bedroom AC
Edit: This ^ isn’t a call for help; the AC automation is just something I’m playing with while I wait for the Bluetooth bridge to arrive that I need to use the sensors I got HA for. Hard to order all the parts upfront when you don’t know if the internal BT chip will work without testing and you can’t test as HA fails to install with a network error if the boot medium is to slow, so you first need to order an SSD.