I would like to use a toggle helper to easily control or view whether an automation is on or off.
Let’s consider for exemple an “alarm” automation, which:
Would be triggered by presence detection and/or door opening
Would notify, produce sound, lights…
This automation should be activated only in some cases. For example, when everybody leave home I can activate the automation by answering to a message on my HA app. But I may also want also to activate the alarm automation manually or activate it by some other scenarios.
So, the configuration could be the following:
One “alarm” automation that may be on or off
One script that activate the alarm automation
One or more other automations that activate the alarm automation calling the script above
Then I would like to have a toggle helper which could be usefull to known the status of the alarm automation (or on off) and potentially manualy activate/disable the alarm automation, directly from a dashboard.
The question is: how to link the boolean helper to the automation status?
An easy to implement solution is to set the toggle helper as a condition of the alarm automation: it would then being always activated but potentially stopped by the helper. I am wondering if there is any drawback in term of ressource usage: in this case the automation is always on, triggered very often (door opening, presence…) but stopped by the boolean helper.
Another solution would be to modify the script who activate the alarm so that it activates the alarm but also modifies the helper state.
In this case I would also have to set an automation to activate/disable the alarm automation when manually modifying the toggle status in a dashboard…in this case the automation is really off, but being sure that the helper and the automation are always synced is not so straightforward…is this cumbersome option of any interest?
To be honest, I started with the second option…and then discovered this video showing how easy it would be to directly integrate the helper as a condition…
Automation entities have a state, they are either on or off. If you include an automation entity in your dashboard then you will see a toggle that lets you turn it on or off. And you can also turn it on and off via a script or another automation by using its services: automation.turn_on, automation.turn_off and automation.toggle. So I’m not really understanding why you would need to introduce another boolean helper here, seems like automations already do everything you need?
That being said what I would suggest is a different option entirely. IMO having automations toggle other automations on and off is a code smell. Now when trying to debug or remember how an automation works to make changes you can’t just look at the automation since that’s not a complete picture of the logic. That only shows what happens when it is on, you also have to look at other automations/scripts to see what turns it off.
It also introduces a new source of difficult to debug issues. For example if you have an automation that turns on another automation when you leave home then what happens if HA was restarting when you left the house? You missed the trigger so now your other automation simply never turns on. Later when you look at it you’re left wondering what the heck happened when HA seems to be running fine but your automation is unexpectedly off.
IMO a much better approach is to refactor your “turn off the automation” logic into a condition in the automation itself. Like instead of having an automation that is “activate the alarm” and another one that is “enable or disable the alarm when I am not home” just add a condition to the “activate the alarm” automation for “when I am not home”. That way its always technically “on” but it often never proceeds past the condition step.
To each their own here obviously but that’s how I would do it.
I did not know that I could add an automation entity to the dashboard, so that could be a solution.
The other things that was not so explicit in my previous post is that my ‘alarm’ is not only the automation, but also other devices (mainly cameras) that have to be ‘turned-on’ (or activate detection) together with the automation.
This is why everything cannot be inside the automation as a condition. I really need a mechanism of turning on or off, by some other automations or by a manual toggle.
By the way, you contributed to make me advance in my thoughts. Thanks.
An automation’s condition can be used to confirm the state of any entity (and many entities). What CentralCommand explained is a very common design pattern to control an automation’s behavior. I doubt your application couldn’t take advantage of it.