Add day and month to filename

Tags: #<Tag:0x00007fc40bfc91b8>

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?

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/

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"

They seem to want the three letter abbreviation, not the month number.

I read it as that was his example that he wanted which is two digit month and two digit year.

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.