I was expecting output filename to be:
/tmp/snapshot_camera.mjpeg_camera.jpg
Instead I get:
/tmp/snapshot_<Entity Mjpeg Camera: idle> .jpg
Am I missing something in the templating? Instead of substituting the entity_id variable it seems to be rendering a version of the entity ID and the state of the entity.
{{ “states.component.entity.attribute” }} returns the state value of the component. You’ll need to explicitly name your file “snapshot_camera.mjpeg_camera” or find the correct attribute of the entity to grab the state value you want.
Use the template tester in the front end if you’re ever unsure or want to test the output.
In the template tester: {{ states.camera.mjpeg_camera.state }} returns “idle” as that is the current state of the component.
Try {{ states.camera.mjpeg_camera.attributes.friendly_name }} or look in the states tab for the entity for the exact attribute. This returns the friendly name of the entity
Ah, OK, I thought I might be able to use the entity_id variable defined in the data as part of the filename using a template rather than repeat it in the filename.
The example I gave is literally from the docs, and I thought it might do something different.
Well, almost. That gives me a filename of “snapshot_Mjpeg Camera.jpg”, so it’s converting the name to capitalise the words and convert the underscore to a space (I assume that’s a default name because I haven’t set one explicitly in the camera definition)
I’m capturing a snapshot on an event (in particular the doorbell ringing) and then I have a local file camera defined that uses the snapshot. I’ve got that in a group that I hide by default and then show when the event occurs.
I wrote it up without the snapshot service here, and then updated it to replace the shell command with the new service here.
I was just experimenting with getting the entity ID in the filename as well, and the method of using {{ entity_id.entity_id }} does the job - I’ve just tried it, and it works fine.
I assume that’s because the filename is just data and the backend service is treating the value of the data as a template so it doesn’t have to be explicitly defined as a data_template.
@robmarkcole, just had a look and my version had single quotes around the filename, otherwise the parser thinks the first quotes in the strftime function are closing the string. Checking it now, that didn’t work - it appears that within an automation yaml file, single quotes are allowed in the JSON, but not in the front end.
However, it looks like you can use single quotes in the strftime function, so try it with single quotes around the time format. I’ve just tried it with my camera from the front end and it worked.
I want to send a pic to my phone but it has a huge delay. So how do you guys send the screenshot with time and entity_id to your phone. Can you share your automation.yaml?
I’ve been using a similar automation as yours and recently I started getting an warning about a deprecated template variable.
Detected use of deprecated template variable
Warning ⸱ Reported by Camera
This stops working in version 2025.6.0. Please address before upgrading.
The pre-defined template variable entity_id was used when performing action camera.snapshot targeting camera entity camera.doorbell. The pre-defined template variable entity_id is being removed from the filename parameter of camera.snapshot.
I’m not sure to understand exactly what the warning means - will the template {{ entity_id }} not be usable in the “filename” of camera.snapshot service? (and why not?)
When I call the camera.snapshot service, I pass this in the data (from Node Red) {"filename":"/config/www/tmp/snapshot_{{ entity_id.entity_id }}.jpg"}