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

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

I might just be thick, but I don’t seem to have a config/www directory, so no custom JS file. Any reason why?

Do you have HACs installed?

I do indeed, it runs my Octopus Energy addon.

What editor are you using? For example with File Editor you should see WWW in the homeassistant folder

I’m using Studio Code, I will have try another editor if you think that might be the problem?

www folder is available in Studio Code Server

anyone else getting this error?

Uncaught error from Chrome 124.0.0.0 on Linux x86_64 TypeError: Cannot read properties of undefined (reading 'includes') refreshOnLovelaceChange (/local/refresh.js:8:22)

this is the file how it is now.

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.text.includes('dashboard was updated')) {
        console.log("Refreshing page...")
        location.reload()
    }
};

setInterval(refreshOnLovelaceChange, 500);

@foxsam I believe I was getting the same error when I was fighting with it, my solution was to clear the cache on browser used on that device.