Is it possible to use variable for a location to read a file in YAML?

Hello guys, im new.
Sorry if i don’t post it in the right topic.

I have a question about if this is possible?

Can i use variables to call a file in the YAML config?

like this :


camera:
  - platform: local_file
    file_path: "{{ states('sensor.ai_front_image') }}"
  • sensor.ai_front_image contains the location of the image received from mqtt (/local/images/Front.jpg)
    this was to test if i can use this variable to show the picture, but did not work.

What i would like to achieve is this:

- ('sensor.ai_front_name') contains the name like: Front  
- ('sensor.ai_front_date') contains date like: 9-8-2021
- ('sensor.ai_front_time') contains time like: 12:01

The image that i put in the folder by detecting a person used by a different server with the AI plugin of blueiris.
it saves the image in /local/images directory of HASS, like this : Front-TIME-DATE.jpg

How can i let it read the file everytime it changes the filename?

camera:
  - platform: local_file
    file_path: "{{ states('sensor.ai_front_name') }}{{ states('sensor.ai_front_time') }}{{ states('sensor.ai_front_date') }}"

If i copy the filepath into the template tester it prints out perfectly…

Regards and many thanks.

It’s not possible to use a template there, according to the documentation.
You might be able to achieve something similar with an automation and the local_file.update_file_path service, though

thank you for your reply,

Can you maybe show me some code how to do it, i really don’t know how.
I did check that on github.
Is there no easy way to do it, becasue many camera’s save a file with a specific name… if i change it to a name like front.jpg it overwrites it and i loose the old ones…

regards

I got it,

i created an automation with that service , and i can use templates with that.

thanks for the help !