[SOLVED] How can I get my dashboard to refresh automatically, instead of showing the "Refresh?" prompt?

This was a brilliant starting point! Since I use FullyKiosk, I amended the example to reload the start page on the kiosk.

This is YAML for an automation. You can also create the same automation manually in the UI using a Manual Event trigger for event type “lovelace_updated” and a Service Call action to press the load start url “button” entity registered by the FullyKiosk integration.

alias: Reload kiosk when lovelace is updated
description: ""
trigger:
  - platform: event
    event_type: lovelace_updated
condition: []
action:
  - service: button.press
    data: {}
    target:
      entity_id: button.dash_kiosk_load_start_url
mode: single
2 Likes

Not working for me. Not sure what I’m missing. I have this snippet in a file under config/www/custom.js.

Then I have the following in my config:

frontend:
  extra_module_url:
    - /local/custom.js

Finally, to test I’m opening up my dashboard in two tabs. I make a change in one tab and save it then go back to the other tab. I see the usual “Your dashboard was updated. Refresh to see changes?” message, but it doesn’t auto refresh. What’s the deal?

What if I just want to refresh the dashboard every hour?

Try this:

frontend:                                                                                                                   
  themes: !include_dir_merge_named themes                                                                                   
  extra_js_url_es5:                                                                                                         
    - /local/custom.js                                                                                                      
  extra_module_url:                                                                                                         
    - /local/custom.js  

Then open browser console (Inspector), check for errors (syntax errors may stop loading custom.js silently when loaded via extra_module_url). Add console.log('custom.js loaded'); on the beginning of custom.js file.

Edit JS, remove the last check whether notification is present and contains expected information and just do the reload. Change value in setInterval(refreshOnLovelaceChange, 500); accordingly (3600 * 1000).

My version of custom.js being a mix of some ideas from this thread, working as of 2024.02:

console.log("custom.js loaded!");

function refreshOnLovelaceChange() { 
    // uncomment for Kiosk mode ('kiosk' param must be in the url, tho)
    //var urlSearchParams = new URLSearchParams(window.location.search);
    //if (urlSearchParams.get('kiosk') !== 'true') return;

    var ha = document.querySelector("home-assistant");
    if (!ha || !ha.shadowRoot) return;
    var nm = ha.shadowRoot.querySelector('notification-manager');
    if (!nm || !nm.shadowRoot) return;
    var haToast = nm.shadowRoot.querySelector('ha-toast');
    if (!haToast) return;

    // uncomment to refresh for a given user name only (name as seen in UI)
    /*var userNameToRefresh = 'user-for-dashboard';
    try {
        var userName = ha.shadowRoot.querySelector('home-assistant-main').shadowRoot.
            querySelector('ha-drawer').querySelector('ha-sidebar').shadowRoot.
            querySelector('a[class*=profile]').querySelector('paper-icon-item').
            querySelector('span[class=item-text]').textContent.trim();
           if (userName !== userNameToRefresh) {                                                                                                                              
               return;                                                                                                                                                        
           } 
    } catch (error) {                                                                                                                                                  
        //console.error(error);                                                                                                                                        
    }*/                                                                                                                                                                 

    if (haToast.opened && haToast.text.includes('dashboard was updated')) {
        console.log("Refreshing page...");
        try {
            haToast.querySelector("mwc-button").shadowRoot.querySelector("#button > span.mdc-button__label").click();
        } catch (error) {
            console.error(error);
            console.log("Going to reload whole page instead...");
            location.reload();
        }
    }
}
setInterval(refreshOnLovelaceChange, 1000); 

If you update the script, then you need to clear browser cache (reload hard). It also works in the Companion app (you will need to clear its data to pick up the changes - you will need to login and configure the app tho).

Update for 2024.4.2 down there: [SOLVED] How can I get my dashboard to refresh automatically, instead of showing the "Refresh?" prompt? - #66 by psko

2 Likes

On my office computer I have a screen that has a dashboard that shows my security cameras.
I installed that page as an app in Edge and set it to auto-refresh once an hour. There is an add-on for that.
On a pc reboot, it will automatically load that dashboard for me also.
Not much good for an android tablet though…

Solution to refresh Raspberry Pi 400 running chromium kiosk with 15" uPerfect touch screen Display. Via Node Red and SSH command to XDOTOOL.

CHROMIUM KIOSK Mark Watt Tech Tutorial.

uPerfect unify y Vertical Monitor

My Home Assistant Server runs on a Home Assistant Blue. My Raspberry pi400 utilises the full screen kiosk (above) to log into the server via Nabu Casa.

  1. INSTALL XDOTOOL
  2. INSTALL NODE RED if you do not already have it installed.
  3. INSTALL node-red-contrib-ssh-v3 node in Node Red.

The flow is very simple, consists of an inject node that injects the SSH command via msg.payload, every 10 minutes. This is so my Ventusky weather map shows the latest data, running in iFrame.

Below is the setup for the inject node.

msg.payload is set to (string)

The full SSH command is: Insert your own username.

export XAUTHORITY=/home/INSERT USERNAME/.Xauthority; export DISPLAY=:0; xdotool key ctrl+r

The part of the above that completes the virtual key press of ctrl+r is xdotool key ctrl+r

I discovered this command works directly after my other attempts failed. See this website XDOTOOL fails. Error: Can’t open display: (null)
Failed creating new xdo instance

I set repeat interval to 10mins.

Setup for the SSH V3 node is as below.
Hostname: The IP address of your Raspberry Pi
Port: 22 (default setting)
Username: The username you use to log into your Pi
Password: The password you use to log into your Pi
Ssh: Leave this as the default grey text, the msg.payload from the inject node needs no other file path.

Works perfectly. Basically my Home Assistant Blue, running Node Red is sending a keyboard shortcut ctrl+r to my Pi 400 every 10 minutes.

xdotool works properly for you with Wayland/Wayfire (default on Raspberry OS Bookworm), because I had no luck with it.

I am using Debian GNU/Linux 12 (bookworm). I just checked raspi.config and I am running X11 Openbox window manager with X11 backend. I am unsure if you can set that and have your Pi run correctly?

See the below links for Wayland.
https://www.reddit.com/r/linuxquestions/comments/u5mxzi/xdotool_alternative_for_wayland/

Yup, probably I saw that sometime ago, for sure I had no luck with ydotool. I switched to use JS to reload dashboard.

Xdotool won’t work with Wayland. On Wayland, the compositor cannot be tampered with or spied on by applications connecting to it.

I have what is the beginning of a tool you can use with KWin as a compositor on Wayland, right here:

It currently only knows how to raise a window, but KWin is pretty scriptable so you can hack it to make it do your bidding. The reason it works is because KWin is the compositor, so it can do whatever the føck it pleases.

Has anyone found a solution which works with the Android companion app? Thx

Tasker or ADB Command Maybe?

https://www.reddit.com/r/tasker/comments/kyzbeo/can_i_simulate_button_pressed_without_root/

https://groups.google.com/g/tasker/c/LJhmfxT2mj8?pli=1

https://flows.nodered.org/flow/7f35f7f413c7d4abd983e4ede0100ec7

After update to 2024.04 custom.js is stop refresh page after update.
Replace after === to your language

function refreshOnLovelaceChange() {
    const ha = document.querySelector("home-assistant")
    if (!ha || !ha.shadowRoot) return
    const nm = ha.shadowRoot.querySelector('notification-manager')
    if (!nm || !nm.shadowRoot) return
    const haToast = nm.shadowRoot.querySelector('ha-toast')
    if (!haToast) return

    if (haToast.shadowRoot.firstElementChild.firstElementChild.firstElementChild.textContent === 'Конфигурация панели обновлена. Обновить, чтобы увидеть изменения?') {
        console.log("Refreshing page...")
        location.reload()
    }
    if (haToast.shadowRoot.firstElementChild.firstElementChild.firstElementChild.textContent === 'Home Assistant работает!') {
        console.log("Refreshing page...")
        location.reload()
    }
}
setInterval(refreshOnLovelaceChange, 500);
1 Like

Update to my version of “refresh” to work with HA core v2024.4.2 & frontend v20240404.1:

if (haToast.opened && haToast.text.includes('dashboard was updated')) {

if (haToast.open && haToast.labelText.includes('dashboard was updated')) {

4 Likes

Thanks! This is the only version that doesn’t fill my logs with constant errors, let’s hope it also works on my tablet! :slight_smile:

EDIT: Yes, it works.
To keep it short, if you’re having issues on one of your devices (like I did), clearing the cache on that device (browser/app) should solve your problem.

I’ve just requested such feature: Automatic reload of dashboard

Please vote :slight_smile: (unless they decide to close it if there is other such feature request and I failed to find it).

1 Like

As for me, i don’t use auto-refresh for some time now. The reason is quite simple: before i start “messing” with HA and i’m planning only to do a simple change, i open one tab (in chrome/edge) with dashboard i plan to change and leave it in the background, then i work in another tab. If anythig goes wrong i just save that first one and i’m back. OK, another way is to open raw editor and save contents to a txt file before start, but i do that only for bigger changes i plan to make.

I’ve made all my (manual) refreshes either via rest command when using fully kiosk, or via hass.agent command when using windows. So, when i work on a dashboard i leave all instances except the one i’m working on, and refresh them all only after i’m done (i made a script for that).

Ok, auto-refresh would be usable, but it would definitely had to be selective for each user: with option to have it turned on or off.

Voted good improvement