Title as variable

First thank you to all the community for this great software that is Home Assistant,

I would try to find a way to write a Title of what song is playing on a device, on a file (txt).
And all seems work well (!),

I would try to improve the behavior:

  • first the trigger (check for the media player —> if it is ON)
    every 2 minute pick the title and write it.

Of course the songs with a length >2 mins create an issue:
appears 2 times or more on the output file.

I would implement a simple check condition BUT how to make it ?

I was looking :Scripts - Home Assistant
but not really help me
even this :
Two input_text passed to an automation
I can execute the script or pressing the button fire the script,
but no notify was shows…

Hope someone could put me in the right direction…
Thank you !

P.s.
Please note :
on my HA last stable version at the moment.
NO HACS (it run on docker container)
NO file editor (configuration.yaml edit using external editor)

I would not advise a timetrigger for this. Have a look at the folder watcher trigger.

If you do not need an automation, you could also use the File Sensor

Thank you for reply
I solved writing again all the logic of this simple automation.
Now it is triggered by “changes” of the title. (no more needed retain in memory the previous track/song before write the title) And it seems work !
Thank you.