homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'entity_id' is undefined
What is quite strange to me, is that I can manually execute what’s in the data: section via the developer tools on the UI but even there if I then call either of the scripts it fails.
Triggering this script with service script.test_snapshot or service script.turn_on and providing entity_id: script.test_snapshot both fails with the previously reported error.
But, using what’s in the data: section above works when calling the camera.snapshot service from the UI.
I’m happy to report this as a bug but I want to be sure I’m not doing anything silly.
Note: The filename example in the docs also fails for me.
I think you are correct that something has changed in the processing of such templates.
Using this: trigger.device_tracker.attributes.friendly_name
in the template of an automation used to work perfectly up to 0.116. I had to change it to: state_attr(trigger.entity_id, 'friendly_name')
My hunch is ‘entity_id.entity_id’ might need rephrasing as well, but I’m sorry I don’t know how to rephrase it.
Edit: you might want to raise a bug report anyway since the documentation you linked to is also faulty right now, needs fixing anyway
I answered on the Github issue. The workaround is to hardcode the specific information you want to extract from the entity, as previously stated. You can’t use entity_id or any of its attributes in templates.
Notice the {{ '{{ entity_id.entity_id }}' }} in the filename string. The service helper template will first render the entire filename as /media/{{ entity_id.entity_id }}/20220818-163758.jpg and pass it on to the camera service (snapshot/record), which will then render appropriately as /media/camera.backyard_camera/20220818-163758.jpg and /media/camera.doorbell_camera/20220818-163758.jpg, etc.