hi,
I guess this problem has been fixed before. Unfortunately I can’t get my head around it.
Goal:
I want to save a file in the fomat myfile-yyyymmdd-hhmmss.jpg
I found: myfile-{{ now().year }}{{ now().month }}{{ now().day }}-{{ now().hour }}{{ now().minute }}{{ now().second }}.jpg"
Problem:
Those conversions do not add leading 0’s. e.g. for the month September, now().month returns 9, where I would need (expect) 09
I tried with: now() | datetimeformat('...'), but the filter datetimeformat is not allowed for “now()”. Frankly, it is not clear to me what the format is of “now()”
I also tried with: {{now().month|pad(2)}, but that seems also to be an invalid statement
wel I’ll be d*
as simple as that… and it worked right away
I was searching for jinja2 filters, …and I did read the documentation, both of them: the HomeAsistant docs and the Jinja2 docs.
Now this turns out to be python ?
How does that work?
Anyway. A big thank you Phil @pnbruckner
I can’t explain it fully, other than to say that Jinja is implemented in Python. I’ve just found over time that if you have a Python object (which is what now() returns – specifically, a datetime object), then you can use its Python methods.
I guess to do it the “official” way would be something like this: