A dashboard button that *just performs some actions*

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:

  1. 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?
  2. 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.

A script is also an entity, so just adding the script to the dashboard is enough

2 Likes

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

  1. what entity do I bind the button to? (as the button does not require any relationship with an entity)
  2. 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

show_name: true
show_icon: true
type: button
icon: mdi:abacus
name: ABCD
tap_action:
  action: perform-action
  perform_action: script.some_script

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.

1 Like

These are not best or worst solutions. Each has own niche.

No need to use a custom plugin when standard components can do same (in most cases).

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.

2 Likes