glendower
(Glendower)
July 21, 2021, 5:45pm
1
I have searched extensively on the net and the forum but I am unable to solve my problem.
I want to produce log files where the filename starts with the month and year ie.
0721logextra.txt
I have played around with the template on the developer option and came up with
- name: logextra
platform: file
filename: {{now().strftime('%b%y')}}logextra.txt
which produces
- name: logextra
platform: file
filename: Jul21logextra.txt
which is exactly what I require, however when I paste that into the configuration.yaml I get an error
notify:
- name: logextra
platform: file
filename: {{now().strftime('%b%y')}}logextra.txt
can not read an implicit mapping pair a colon is missed
I am stumped, can anybody help?
GlennHA
(Glenn)
July 21, 2021, 5:54pm
2
Maybe I’m missing something but if you want month why don’t you use
%m
lower case m is month, upper case M is minutes.
https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
tom_l
July 22, 2021, 2:53am
3
If this accepts templates, and I’m not sure it does, you need to put single line templates in quotes:
filename: "{{now().strftime('%b%y')}}logextra.txt"
tom_l
July 22, 2021, 2:55am
4
They seem to want the three letter abbreviation, not the month number.
1 Like
GlennHA
(Glenn)
July 22, 2021, 4:33pm
5
I read it as that was his example that he wanted which is two digit month and two digit year.
glendower
(Glendower)
July 22, 2021, 7:06pm
6
This question, in one form or another, has been asked many times with no resolution.
It does seem however, as tom_I suggested, filename: cannot be used in a template. So dynamic filenames cannot be created in HA at present.
As this problem does keep coming up perhaps its something that can be added in the future.