#Can tap_action have more than one action?

1 messages · Page 1 of 1 (latest)

rocky trench
#

Heya,

see topic - is it possible to have something like this:

tap_action:
  - actions:
    - action1
      ...
    - action2
      ...

or do I have to create a script? Talking about ~25 buttons where I need to firstly write-enable a device (action1) before I can write to it (action2), so scripts would mean 'loads of scripts'.

/tom

keen temple
#

Pass the script the entity id to write enable and change, then you only need one

#

Set up a field, then put the same key under "data:"

cunning grail
#

If you're a glutton for punishment, you can do it within a card. I don't know if this is something specific to the custom:button-card but it does work. You should be able to define the following as a custom:button-card configuration template and apply variables within the card such as var_device1 and var_device2; you would have to template the entity_id. This would require minimal lines of code to be repeated when referencing the template across the 25 buttons.

#
type: custom:button-card
name: Multi_calls
icon: mdi:multicast
variables:
  var_device1: light.living_room_lights
  var_device2: light.kitchen_lights
tap_action:
  action: nothing
  multi_calls: |
    [[[
      hass.callService(
        "light",
        "toggle",
        { entity_id: "light.living_room_lights" }
      );
      hass.callService(
        "light",
        "toggle",
        { entity_id: variables.var_device2 }
      );
    ]]]
```EDIT: Added variables. Examples shows using a hardcoded entity and a variable now.
EDIT2: IIRC, the custom:button-card is probably the only card that allows "templatable" actions.
rocky trench
#

Thanks @keen temple @cunning grail. Indeed, the triggering button is always a custom:button-card next to the corresponding input_number field (that contains the value to write to the device), so that approach sounds perfect! 🙂

keen temple