for example will return an error stating that the object str does not have a method called strftim.
I would really like someone who got datetimes working in HA answer here. I have had my fair share of trouble with datetimes and till this day not got it working.
My main problem seems to be that all the datetimes are strings…even after using filters like “timestamp_local” in Jinja. And all the templating functions expect me to deliver datetime objects.
at least now i know it wasnt something simple i have overseen.
i tried what @PhyberApex wrote before. that returns unavailable.
i know i have read somewhere that someone used a temp variable.
i guess i need to use something like that, but i still have problems making the right code from it.
must be somthing like: VAR=states.sun.sun.attributes.next_setting and then VAR.strftime(’%H:$M’)
sometimes i feel a bit …
the language between the {{ and the }} is python?’
Hey,
you know you can test the templates in the developer tools before using them right? It’s the next to last icon in the bar on the bottom of the left side panel in HA iirc.
The language between the {{}} is jinja 2 a templating engine for Python. To set variables is jinja you would use
{% set time = states.sun.sun.attributes.next_setting %}
And then you could use time in between {{}} again. But this gives me the exact same results.
thx for reminding me @PhyberApex
I knew it but had forgotten it. so i restarted HA every time
i’m getting old. so many languages to learn in such a short amount of time and they all are somewhat the same, but all so different.
i would think this shouldnt be that hard. i have switches that are goiing on 1 hour before sunset, i just want that same time displayed as a sensor in the gui, so my wife doesnt have to ask me: “why arnt the light switched on?” 2 minutes before they switch on
As the sun attribute and the existing custom filters don’t seem to output datetime but strings or floats, a new custom filter is needed, as far as I can tell.
Yeah my bad. I copied it from my config where I use it to display a time which is offset by a certain amount by a slider to enable variable home automation.
See it the example here:
@ReneTode: I revived this topic since I was struggling as well with the same issue and found the timestamp_custom function very useful also for my automation (see the link above)