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?
No.
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.
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)).
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
cards:
- type: custom:mushroom-template-card
primary: Home
tap_action:
action: fire-dom-event
browser_mod:
service: script.choose_tablet_menu_option
data:
browser_id: THIS
menu_option: home
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.
Rgds.