Yaml loop for directory files list

Hello

I am trying to send by email a list of pictures taken by a camera with an automation.
My automation is OK if I send only one file by using the complete name for a file, or few file if I provide a list

  - service: notify.gandi
    data:
      title: Warning Motion detected
      message: a motion has been detected inside the living room
      data:
        images:
        - /tmp/garage0.jpg
        - /tmp/salon0.jpg
        - /tmp/front0.jpg

How to proceed to get all the files.jpeg inside a directory ?

Something like (in principle} :

{% for file in directory %}
 {% if file like *.jpeg %}
  {{ pictures= pictures+ {{"\n"}} + "-" +{{file}}}}
{% endfor %}}
  - service: notify.myemail
    data:
      title: Warning Motion detected
      message: a motion has been detected inside the living room
      data:
        images: {{pictures}}

There’s no current way to get all pictures in a directory. You most likely can get this information from a python script, or pyscript. That’s about it. Or make a custom integration.

Second, you can’t template in yaml outside a field. It has to be templated inside the field. I.e. your template needs to go in the field images:

OK, thanks Petro.

I am familiar with python, but a newbe with Homeassistant.
I didn’t know it was possible to mix language for automation.
I am going to dig around.

The code was just for described the idea but, sure not usable :grin:
I was asking advises from my phone without access to home assistant.