How to add two (or more) actions to a single Button-card?

Hi All,
I’m trying to have two actions performed when a button card i clicked in Lovelace UI.
This issue her is not the actions themselves. Both works perfectly in their own, but combining them into a single YAML fails.
This is my first attempt:

type: button
name: test1
tap_action:
  - action: call-service
    service: remote.turn_on
    service_data:
      activity: 41122377
      entity_id: remote.harmony
  - action: call-service
    service: media_player.play_media
    service_data:
      entity_id: media_player.stue_ac_lms
      media_content_id: 'https://p7.p4groupaudio.com/P07_MH'
      media_content_type: music
entity: media_player.stue_ac_lms

This does not give any error message, but absolutely nothing happens when I click the button card. No log entries of any kind.
The I tried another variation, but this one gives syntax error “Bad indentation at line 5” and thus cannot be tested or saved:

type: button
name: test2
tap_action:
  action: call-service
    - service: remote.turn_on
      service_data:
        activity: 41122377
        entity_id: remote.harmony
    - service: media_player.play_media
      service_data:
      entity_id: media_player.stue_ac_lms
        media_content_id: 'https://p7.p4groupaudio.com/P07_MH'
        media_content_type: music
entity: media_player.stue_ac_lms

I need help to get this right

1 Like

I don’t think you can do this. You need to create a script that executes these actions and then call the script from the button.

Ok, thanks - I’ll try that.
But how are we to know what can and what can’t be done in the UI ?
It seems like there are lots of YAML limitations when used in the UI, while not so many when used in an automation and even less when used in a script. I thought YAML was YAML. If that’s not the case, where are these limitation documented ?

@Burningstone is right, you can’t do this (yet).

The documentation about buttons and actions always reads like there’s only one supported, but I get your point, it isn’t 100% clear.

However - there is an open pull request in the frontend repository, you could give that a thumbs up if you have a github account.
Seems like the PR is lacking documentation as well, if you want to contribute.

1 Like

I don’t know of any limitations of automations vs. Scripts?

The frontend is pretty limited, but I assume its intentional, because more complex scenarios should be handled by the backend.

1 Like

I like to think about possibilities, not limitations, and all of those are very well documented at home-assistant.io/docs
There are no limitation differences between automations and scripts. The only “limitation” I could think of is that you can’t manually execute an automation easily.
YAML is just the language, the syntax. There’s no tap_action in automations, so I don’t really know where you’re coming from here.

Thank you all for answers and guidance.
So, to sum up - It isn’t possible to add two (or more) actions to a singel button-card, unless i turn to scripting (which I did - and it works)

alias: Play Radio
sequence:
  - service: remote.turn_on
    data:
      activity: 41122377
    entity_id: remote.harmony
  - service: media_player.play_media
    data:
      media_content_id: https://p7.p4groupaudio.com/P07_MH
      media_content_type: music
    entity_id: media_player.stue_ac_lms
mode: single
icon: 'mdi:panda'

Currently - no. Again, someone is working on it and if this gets merged, you could do this natively.

I can’t believe this is still an issue in 2023: I want one dashboard button to tun on a switch while simultaneously navigating to another screen. Scripts don’t have the navigate function. Pah!

1 Like

They have a navigate function but then you have to install browser-mod.

settings:
  alias: settings
  sequence:
  - service: alarm_control_panel.alarm_arm_home
    data: {}
    target:
      entity_id: alarm_control_panel.open_settings
  - service: browser_mod.navigate
    data:
      path: /lovelace/instellingen/
  mode: single

I’d like my front door lock wake button (Yale lock) to be pressed when I navigate to the section of my UI for my front door so I have an up-to-date status whenever I check, but don’t have to create unnecessary battery drain by automating the wake button to be pressed every few minutes.

I want to have tap_action and hold_action from the following script both in one tap_action:

hold_action:
  action: call-service
  service: roborock.vacuum_load_multi_map
  service_data:
    entity_id: vacuum.roborock_s6_maxv
    map_flag: 1
tap_action:
  action: fire-dom-event
  xiaomi_vacuum_map_card:
    action_handler_id: robo_action
    action: map_mode.set
    data:
      index: 2

I tried to setup a script, but since “fire-dom-event” is not a service that is available within the script generator, I just don´t know how…

Hello

I’m trying to do two action with on key pressed, but I’ve been getting nowhere.
I read on the page that the action can use a template, so I tried to do it, but I can’t seem to get it right. here’s the code:

type: custom:button-card
name: Lights
icon: mdi:lamp
layout: icon_name
data: {}
tap_action:
  action: custom
  custom: |
    [[[ 
        hass.callService(
          fire-dom-event: "entity_id":"local_conditional_card",
          {
            "data": {  
              "action": {
                "set": {
                  "ids": 
                       {
                          "tabs1": "hide"
                          "tabs1": "hide"
                          "tabs1": "show"
                       }
                }
              }
            }
          }
        )
        hass.callService(
         "script.turn_on","entity_id": "script.set_monitoring_tab_number",
           {
               "data": {  
                 "variables": {
                   "tab_number": "{{ variable.var_tab_number }}"
                 }
               }
            }
        )
     ]]]
  variable:
    var_tab_number: 1

styles:
  name:
    - color: white
  card:
    - height: 40px
    - width: 200px
    - background-color: |
        [[[
              if (states['input_number.main_dashboard_tab'].state == 1)
                return "green";
              return "black";
            ]]]

Does anyone know how to fix this?
I’d be grateful.

Thanks

I agree it would be nice to have built in option for multiple actions for a button press rather than having to go the scripts/automation route.

1 Like