Complete noob question: how do I write automations to handle both the “turn on”-condition and the “turn off”-condition? I keep creating 2 automations evertime I need to handle an “on” and “off” action.
Concrete example: I have a humidity sensor in the bathroom. I have an automation so that, when humidity increase above 75%, HA acivates a “boost mode” on the ventilation system. I then have a separate automation to turn boost mode off again, when the humidity drops below 60%.
I use the front-end for this stuff, but I suppose the YAML is easier to share. Here are the two automations. How do I write this a single automation?
Add both your triggers to 1 automation and set a trigger id on each (different obviously). Then in actions use a choose and triggered by to call the right action.
and there is realy no need to check for condition ’on’, nothing will happen if you call the service again (as you can only turn a switch on/off once )
I do the extra check in order to avoid spurious log messages or notifications. Eg. many of my automations ends with notifying me that the thing has happened (at least while setting things up, veryfying that everything works as I expect it to). Some triggers happens more frequently than Id like and so I took to the habit of checking if we’re actually moving from one state to the next, even if redundant calls aren’t harmful.
Perhaps there are better ways to filter out frequent or multiple triggerings of the same thing?
The best practice would be to use State when you need a trigger or a condition, and use Call service when you need an action. Both will let you use entity_id’s.
That’s a bit out of date. Device automations are now supposed to be marked as unavailable if the devices they depend upon are not available, however that may be broken and it may prevent all automations loading. See here for some more up to date advice: Why and how to avoid device_ids in automations and scripts
That thread was amazingly helpful. Wish I had seen that a long time ago.
Even this simple statement is super helpful in wrapping my head around the terminology of Home Assistant;
Essentially, devices are physical objects, while entities are the functions or services.
For example, a Philips Hue motion sensor is a device which acts as a container for seven entities.
Nothing for it but to go back and rewrite my old automations.