Let’s imagine you created very complex automation, via blueprint or manually. For example, the one for the two-button switch controlling multiple lights. So, multiple triggers, then conditions, a mix of scenes and service calls.
How would you trigger such automation from the UI? automation.trigger won’t work, as there’s no way to specify a trigger ID, scene.apply also isn’t the option as not every step is a scene.
One solution is to employ events for that:
Automation triggers pre-defined event(s) on device actions (e.g. click)
Same automation does the work, using event triggers
Lovelace UI components emit triggers
The issue of the solution above is that lovelace isn’t able to natively emit events. I have to write a script for that, and I need one script per event type, as event types aren’t “templatable”.
The automation’s trigger defines when it should begin to evaluate its condition and potentially execute its action.
The automation.trigger service is a misnomer because it doesn’t actually exercise the automation’s trigger but simply executes its action (optionally evaluates its condition). The “Run Actions” button is more accurately named because that’s the extent of what it achieves, effectively treating the automation like a script. However, this isn’t useful if the automation’s action references the trigger variable because that’s only defined when the automation is actually triggered by one of its triggers.
The only way to exercise an automation’s trigger is to actually trigger it via one of its triggers. If you add an Event Trigger just for testing purposes, it can allow you to trigger the automation via the UI (see below) but what purpose does that serve?
I am confused, an automation is exactly that, something that happens automatically via set events.
I assume you want to trigger a set of actions via a Lovelace button for example then surely you want a script not an automation? As that the only difference between automation and script, one is automated and one is requested.
It’s an automation, because I create re-usable automations from blueprints (created manually). For example a blueprint for curtain motors. It has a wireless switch, sunrise/sunset bindings, other date and time conditions attached. As I have multiple curtains installed, I just re-use them and never copy the automation code. And then, I would like to, in addition to the automation triggers, call parts of automations from lovelace buttons.
I would assume if you want to simply trigger the whole automation the simply adding a helper as an additional trigger would suffice here?
However if as the statement implies “part of the automation” then I can’t see how this would ever be possible unless you strip out the “part” and place it in a separate script.
Maybe I am missing something but I don’t use blueprints at all - find them too limiting
Using scripts is a nice suggestion, but they’re less convenient compared to the blueprints
They’re not portable (single file per project as in case of blueprints)
There’s no configuration UI to set of variables
I’ll have to pass all necessary arguments to the script in order to have all conditions evaluated
One example:
As I mentioned above, I have a blueprint/automation for a two-button switch, controlling 3 lights using 3 scenes. The scenes are: “only left light”, “only right light”, “both lights”. The brightness/color and temp are different, depending on the mode.
Then I have a blueprint, where I first set selector for a switch, lights, scenes
and then my conditions part looks like this (pseudo-code):
if left_button click then
if left_light is ON:
apply "only right light" scene
else
apply "both lights" scene
etc, etc
So I could theoretically move this part to script and call it from the Lovelace button or whatever, but then I’ll have to pass all variables to this script: lights, scenes, other parameters I’ve configured in automation. Doing the same multiple times - not my approach
Absolutely not, as there’s no way to set a trigger_id, in order to execute the specific part of the automation. My blueprint is basically a set of triggers and one big switch statement by trigger_id
And there it is; evidence of your misunderstanding of how automations are designed to work. You still believe there’s some way to artificially induce a trigger without the actual trigger ever occuring. It simply doesn’t work that way.
A trigger_id is produced when the trigger occurs automatically, not manually (manually “triggering” an automation doesn’t actually exercise its triggers). It’s vital to understand that a trigger is a listener and it listens for state-changes/events. To cause the trigger to fire the listener must detect the presence of the specific state-change/event its monitoring. You’re seeking some means of either bypassing the listeners or fool them into detecting a non-existent state-change. The only way to satisfy a listeners requirements is to cause the state-change/event its designed to detect.