How to call a tap_action navigate action from a script?

I’d trying to call a tap_action navigate action from a script.

type: button
  action: navigate
  navigation_path: /lovelace-main/0

This works when pressing the button, but I don’t see anyway to do this from a script (or from an automation).

In trying to solve this problem most answers seem to suggest using the broswer_mod integration which has a navigate command, but this seems to require that the browsers be registered. Also, because I want to use this on a dashboard that I’m casting to multiple Google Nest Hub devices, browser_mod doesn’t work well for each screen individually (like the tap_action navigate action does).

Is there any way to call a navigate to a new path command from a script?

Thank you :slight_smile:

Lovelace is front end, it runs locally in the browser.
Automations and Scripts are backend, they run on the server itself.

browser_mod adds both backend stuff, and frontend stuff - that is accessed on the frontend via the websocket that the frontend uses to talk to the backend server.

You can however cast a dashboard to a Chromecast / Nest Display via a script or automation.

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
    action: custom
    custom: |
          { entity_id: "input_boolean.ui_pin_open_auto_close_panels"}
          { entity_id: "script.ui_hide_panels"}
        //window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })

        window.dispatchEvent(new CustomEvent("location-changed"));

This is a good solution, but you could simplify it by using browser_mod. If you use browser_mod, then you can put everything you want to happen inside a single script, and then call that script from any card that supports tap_action. This is what I do with my dashboard navigation. I have a giant script setup to handle any calls from any of the tablets. When a navigation button is pressed, I send the browser_id and the menu option chosen as variables and the script performs the appropriate actions. This makes it really easy to change anything across all tablets as all I have to do is modify the script, not update tap actions on individual buttons across multiple lovelace pages.

      - type: vertical-stack
          - type: custom:mushroom-template-card
            primary: Home
              action: fire-dom-event
                service: script.choose_tablet_menu_option
                  browser_id: THIS
                  menu_option: home

I find something a little bit easier, using action navigate :

  action: navigate
  navigation_path: |
      { "entity_id": "input_text.gsm_active_page","value": variables.navigation_path});
      return variables.navigation_path;

Using a variable from the template (button-card), I code everything that I wanted to be executed before returning de path for the action navigate. In this example, I am keeping in an input_text the active page (as lovelace has no global variable for this usable in Jinja2 for example). But you can also turn on a scene, a light, set a boolean, open a door…
I read many thing on this topic, I finally found that wich seems to be very efficient, easy and permit ti use defined action.