Hadashboard, navigate after last touch


I would like to add a script that move to the main dashboard after last touch (and after some timeout). I’ve tried to implement what it is detailed here but does not work for me :frowning:

my apps.yaml:

  module: navigate
  class: Navigate
  target: main # the dashboard name
  timeout: 25 # the amount of time the dashboard stays visible


import appdaemon.plugins.hass.hassapi as hass

class Navigate(hass.Hass):
    def initialize(self):
        # Listen for the hadashboard event to be fired.

    def navigate(self, entity, attribute, old, new, kwargs):
        # Get the target from the args.
        target = self.args["target"]
        # Get the timeout from the args, if supplied.
        if 'timeout' in self.args:
            timeout = self.args['timeout']
            self.dash_navigate("/" + target, timeout=timeout)
            self.dash_navigate("/" + target)

any idea what could happen?


there is no event for hadashboard that is fired when a dashboard is touched.
so listening to an event called hadashboard will never trigger.

and the timeout is for AFTER the navigate, so even when you could listen to that event it would cause that the main dashboard would show up immediatly and would go back after 25 minutes.

so to make it short: what you want is not possible.

the only way that you could do such a thing is when you write a custom javascript function that gets triggered on DOM events.

1 Like

And as per @ReneTode’s suggestion, this is what the DOM event code could look like:

TIMEOUT = 30000 // 30 seconds

document.addEventListener("click", reset_timer.bind(this))
document.addEventListener("touchstart", reset_timer.bind(this))
document.addEventListener("touchmove", reset_timer.bind(this))
my_timer = setTimeout(TimeOut.bind(this), TIMEOUT);

function reset_timer(e){
    console.log("RESETTING TIMER DUE TO EVENT:", e.type)
    my_timer = setTimeout(TimeOut, TIMEOUT);

function TimeOut(){
    console.log("TIMEOUT OCCURRED")
    window.location.href = "" // URL to your home dashboard

Place the code in a folder named custom_javascript in the config folder. Restart Appdaemon to pick up the custom_javascript folder if it did not exist.

You will need to add some logic to avoid race conditions so that the page does not reload when you are in the “Home” dashboard.

1 Like

you miss out on the newest fuction @tjntomas.
you can create a folder called custom_javascript, and the files inside there will automaticly included as in the head.

so there is no need anymore to use skins to include JS.

1 Like

Great! I have to read up on that.

restart shouldnt be needed. it looks for the folder everytime a dashboard is loaded :wink:

Got “file not found”, but it worked after a restart, so I guess its needed when you first create the folder.

hmm, yeah i gues your right. if the path isnt found it isnt added to server.

thanks @ReneTode and @tjntomas, it works!
to avoid reload main panel when I’m already on it I’ve edited the TimeOut() function like this:

function TimeOut(){
    var current_page = window.location.href;
    var main_page = "";
        window.location.href = main_page;
    console.log("TIMEOUT OCCURRED")

Thanks again