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
my apps.yaml:
navigate_to_main:
module: navigate
class: Navigate
target: main # the dashboard name
timeout: 25 # the amount of time the dashboard stays visible
navigate.py:
import appdaemon.plugins.hass.hassapi as hass
class Navigate(hass.Hass):
def initialize(self):
# Listen for the hadashboard event to be fired.
self.listen_event(self.navigate,"hadashboard")
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)
else:
self.dash_navigate("/" + target)
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.
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)
clearTimeout(my_timer);
my_timer = setTimeout(TimeOut, TIMEOUT);
}
function TimeOut(){
console.log("TIMEOUT OCCURRED")
window.location.href = "http://192.168.1.45:5050/Home?skin=my_custom_skin" // 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.
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.