I had the same until I cleared my caches. Once I did that, everything showed up as it should.
Sorry, it’s indented properly, that post was from my mobile phone.
automation.*:
custom_ui_state_card: state-card-custom-ui
extra_data_template: >-
return attributes.last_triggered ? window.hassUtil.relativeTime(new Date(attributes.last_triggered)) : null;
Tried that, still the same.
If I use your config.
With the following, all cards on the front end, show up blank.
#
# Global.
#
"*.*":
custom_ui_state_card: state-card-custom-ui
#
# Automations.
#
automation.*:
extra_data_template: >-
return attributes.last_triggered ? window.hassUtil.relativeTime(new Date(attributes.last_triggered)) : null;
And with the following, extra_data_template, shows up in the automaton attributes, with no change on the frotnend.
Yes, I did, I’m actually using it for other things
Any errors in your log file? Any errors in the browser’s developer tools console?
No errors in log or developer tools/console
This is a great idea !
Here is my vision, I changed it to display the detail of last triggered. Default display is ‘x day’ if it’s more than 24hours, and I wanted to have more details. This displays days, hours, minutes and seconds (rounded) from last triggered, only if different from 0. (ex : 13h 24m 15s, or 1d 24m 30s) :
automation.*: extra_data_template: "if(!attributes.last_triggered)return null; var d,h,m,s=(new Date()-new Date(attributes.last_triggered))/1e3; d=Math.floor(s/86400); s=s-(d*86400); h=Math.floor(s/3600); s=s-(h*3600); m=Math.floor(s/60); s=Math.floor(s-(m*60)); return((d>0?d+'d ':'')+(h>0?h+'h ':'')+(m>0?m+'m ':'')+(s>0?s +'s':''));"
Tried to do the same with script.* but I can’t make it work ?
At this point I’d suggest trying on a virgin Docker installation of Home Assistant to minimize all other possible problems and interferences with your configuration.
Very nice @Mister_Slowhand! Indeed, sometimes it can be useful to get a more precise idea of when exactly something happened.
As for script state cards, alas I cannot get extra_data_template for work with them, for time display or for anything else either.
Do you think it’s a bug ?
Hi, very useful!
Is it possible to use this formula in sensors or other domains like light, binary sensors …?
I’m not a programmer, how can I change this code to replace the one of “deault value”.
Thank you very much.
Since HASS 0.70.1 I got the error:
ERROR (MainThread) [frontend.js.latest.201805310] https://xxx.xxx.xx/local/custom_ui/state-card-custom-ui.html:27:14429 Uncaught TypeError: Cannot read property ‘relativeTime’ of undefined
Anyone got a solution?
relativeTime
is not available now. I am using the following in my customize_glob.yaml to obtain the same information:
automation.*:
custom_ui_state_card: state-card-custom-ui
extra_data_template: >-
if(!attributes.last_triggered)return null;
var t,s=(new Date()-new Date(attributes.last_triggered))/1e3;
return(
(t=Math.floor(s/86400))?t+(t>1?" days":" day"):
(t=Math.floor(s/3600))?t+(t>1?" hours":" hour"):
(t=Math.floor(s/60))?t+(t>1?" minutes":" minute"):
(t=Math.floor(s))!==1?t+" seconds":" second"
)+" ago";
Is this available only for automation or for other classes ? I ask this because using this template for device trackers i get errors in log…
Any idea why the logged time is off by +4hrs?
My current time is 2:47pm and the logged time is:
last_triggered: 2018-06-05T18:47:26.942125+00:100
I think the internal time is in UTC.
It should work for other classes as well, but I wasn’t able to get it working for device_tracker
.
Any idea how I can rectify that?
Current default time zone: 'America/New_York'
Local time is now: Tue Jun 5 15:05:34 EDT 2018.
Universal Time is now: Tue Jun 5 19:05:34 UTC 2018.