How to call a tap_action navigate action from a script?

Ahh, I finally figured it out.
What I wanted to do was call a script and change the dashboard page with a single button push.

action: custom is what I’m calling it, but anything that’s not a real action ( more-info , toggle , call-service , none , navigate , url , assist) will work.

Figured this out with help from this issue comment

Using the amazing Button Card you can do this: Call a script or 2 and then navigate to a new page (or scroll the window position back up to the top (commented out in this example)).

- type: custom:button-card
  show_name: false
  show_icon: true
  tap_action:
    action: custom
    custom: |
       [[[
        hass.callService(
          "input_boolean",
          "turn_off",
          { entity_id: "input_boolean.ui_pin_open_auto_close_panels"}
        )
        
        hass.callService(
          "script",
          "turn_on",
          { entity_id: "script.ui_hide_panels"}
        )
        
        //window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })

        window.history.pushState(null,"","/lovelace-main/0");
        window.dispatchEvent(new CustomEvent("location-changed"));
        ]]] 
3 Likes