Get entity name from multiple entities?

Hi!
How can I get the name of an entity, while using multiple entities in scripts?
I have created an script to make a snapshot from 2 (or more) cameras. This is my action snipet:

service: camera.snapshot
data:
  filename: /config/www/tmp/snapshot_{{entity_id}}.jpg
target:
  entity_id:
    - camera.cam_garagem
    - camera.cam_poste_garagem

But this create only a single file, called snapshot_.jpg.
I have tried {{entity_id.name}}, but no success at all, no images are created and got an error about entity_id is not a valid value.

You need to use quotes around your “templated” part, otherwise this will be parsed as yaml, and not as a template. Like so:

data:
  filename: "/config/www/tmp/snapshot_{{entity_id}}.jpg"

I have tried with quotes (first, with single quote)…no success, even with double quotes, like you sugested.

Failed to call service script/snapshot_camera_garagem. Error rendering data template: UndefinedError: 'entity_id' is undefined

Exactly code:

alias: Snapshot Camera Garagem
sequence:
  - service: camera.snapshot
    data:
      filename: "/config/www/tmp/snapshot_{{entity_id}}.jpg"
    target:
      entity_id:
        - camera.cam_garagem
        - camera.cam_poste_garagem
mode: single
icon: mdi:cctv

NOTE: I’m editing this script as YAML file, using Web GUI. After inserting double-quotes and save script, no errors are displayed…but after going back do script list, then opening this script for editing, the quotes are done!
what am I doing wrong here?

you need to declare the variable “entity_id” somewhere first:

filename: >
    {% set entity_id = some.thing_here %}
    '/config/www/tmp/snapshot_{{entity_id}}.jpg'

What method are you using to run the script?

Manually or from an automation?

If it is from an automation you can pass data to the script then use that data to set the “entity_id” variable.

This isn’t pre-defined?
I thought it was based on this message (filename field):

Basicly, I’m trying to make a script that take a snapshot of two cameras and send notification (with pictures) to my android phone (running companion app). I know that I must send two notifications.
I can make a static script, but I would like to use the feature that enable to select multiple target devices/entities…what I don’t know is how to identify each item in script (or in automation). How can I get the entity ID when multiple targets are selected?

Note1: I’ll create an automation that will call this script if some conditions are met, but first I need to make this script to work. Also, this script will be possible called by more than one automation in the future.

TBH, I have no idea. I only ever call the camera snaphot service for one camera entity and create the filename based on what triggered it from the automation.

But I do know that the {{entity_id}} part is expecting a variable called “entity_id” to be declared somewhere before it is used in that template.

The snapshot service docs are little lacking on explaining that field descriptor.

I never use the UI to write automations so I have no idea what that might mean.