Trying to format date and time and conducted some research but to me jinja is so foreign compared to just python or javascript or C++.
Can anyone help me find:
a good learning site or video for basic jinja (I’m thinking like W3 schools etc)
how do I use the datetime.strftime
?
finity
October 1, 2020, 10:20pm
2
I can help with the second question:
After seeing many threads on the forum asking for help with time conversions and calculations using time and realizing I generally had no real understanding of how time worked in HA I decided to dig in and try to figure it out.
After over a week of internet and forum searches I think I’ve now got a lot of it figured out. I’m sure there is more that I don’t have here because sometimes “you don’t know what you don’t know”.
So, since I didn’t know this stuff and because of the number of other pos…
Thanks! Upon a further Google I found the strftime.org page but this thread is much more comprehensive.
nickrout
(Nick Rout)
October 1, 2020, 10:56pm
4
But it basically formats like python does.
ehh kinda I mean i just did it in python on how i want the message of my notification to be and this is the output. Granted i would obviously import specifically datetime
from the module datetime
which would greatly simplify what i have below, but this is the gist and I don’t see the syntax the same using jinja…
print("Garage remained opened " + datetime.datetime.now().strftime("%I:%M %p %b %d"))
Garage remained opened 11:49 PM Oct 01
Ok got it figured out now!
The garage was {{ states('cover.garage') }} on {{ now().strftime("%I:%M %p %b %d") }}
renders:
The garage was closed on 11:53 PM Oct 01
Thanks!
nickrout
(Nick Rout)
October 2, 2020, 6:14am
7
In answer to your original question, I assume you have looked in the documentation, but if not https://jinja.palletsprojects.com/en/master/templates/ and https://www.home-assistant.io/docs/configuration/templating/
Sorry if I am preaching to the converted, but some people just don’t look in the docs
Actually i did the time wrong, had to change it a bit, but got it working now like this:
{{ as_local(states.cover.garage.last_changed).strftime("%I:%M %p %b %d") }}