I have the need for buttons on one of my dashboards that do nothing except fire off a series of actions when tapped. This raises two questions that I struggle to figure out:
Most dashboard buttons insist on being associated with an entity_id. I guess I can just assign a random unrelated entity_id to the button but it feels silly to do so. What is best practice here?
So far I would create a script and have the button call the script. It feels a bit unnecessary. Again what is best practice? I have noticed that the custom button-card has a multiple-actions action that could take care of what I need. Would that be the best approach?
I just want to understand the best approach if I want to have a dashboard button that says āhere is a sequence of actions Iāll perform when you tap meā - regardless of any entity states or other conditions.
The simplest - add a Button card w/o an entity (which is an optional option) and specify an action āperform-actionā with some script which executes your things.
OR - you can create an āinput_buttonā helper, create a Button card for it, place it anywhere in a dashboard, then create an automation (triggered by that āinput_buttonā entity) containing your actions.
Same (almost) can be achieved by ONE script containing several actions.
āAlmostā = actions in a script cannot be like ānavigate to a particular viewā or āopen a Google pageā (unless you use a cistom browser-mod plugin).
You need to learn how to do things with stock cards first.
OP here. Iām not sure my original question has been answered, which probably means I did not ask it clearly enough. Let me try again. This is a question of ābest practiceā and dashboarding conventions rather than what works and what does not work.
Scenario: I have a button on a dashboard. I want it to perform a series of actions every time I tap it. No conditions attached, just some actions.
Question: Is the best practice really to create a script that performs the actions and call the script from the button? If I donāt anticipate Iāll ever call this script from anywhere else, why this layer of abstraction?
Or even worse, create an input button helper and an automation triggered by the helper - as one of the responses suggest - why all of these layers of abstraction?
And then a follow-up question, if it is OK under these circumstances to just add the actions directly to yaml of the dashboardās button, then
what entity do I bind the button to? (as the button does not require any relationship with an entity)
which is the best way code multiple serial actions in the buttonās YAML itself? It seems to me that the custom button-cardās multiple-actions is the best route, or is there a better way?
I think the main, general reason not to trigger multiple actions from the frontend is that execution can be interrupted much more easily. For example, by refreshing the page, navigating to another dashboard, or disconnecting from the backend.
Ildar already answered this, you can bind no entity
Custom button is the only I know and use. However, previous reservations apply, plus, multi-actions operate on a āfire and forgetā principle; they are not sequential actions.
As Ildar said itās not a best vs worse thing, itās a what suits your need thing. Personally for this sort of thing I use template buttons for their flexibility and level of control and then map a generic button to it. That way the templated button contains the sequential script that I may not need to reuse and I can call other scripts from it and if needed I can use its button press event to trigger automations.