Camera: Record error

So I have post in the “Developer tools” section in “Services” to test if the camera will record and I get the error
Failed to call service camera.record. Error rendering data template: UndefinedError: 'entity_id' is undefined

Here’s the yaml

service: camera.record
target:
  entity_id: camera.computer_camera
data:
  duration: 30
  lookback: 0
  filename: /tmp/{{ entity_id.name }}_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4

Any idea what I’m doing wrong?

Check that this entity id is correct:

Also please format your whole config correctly, not just each line individually. See https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Sorry about that, I fixed it. Also, the entity_id is correct.

Does Home Assistant have permission to write to:
/tmp/

https://www.home-assistant.io/docs/configuration/basic/#allowlist_external_dirs

Also this:

{{ entity_id.name }}

Should be:

{{ state_attr(entity_id, 'name' }}

Or maybe this depending on your entity’s attributes (look in developer tools states):

{{ state_attr(entity_id, 'friendly_name' }}

I get this error
Failed to call service camera.record. template value should be a string for dictionary value @ data['sequence'][0]['data']. Got {'duration': 30, 'lookback': 0, 'filename': '/tmp/{{ state_attr(entity_id, \'computer_camera\' }}_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4'}

with this
{{ state_attr(entity_id, 'name' }}

When I load with the example data in HA, it fills in this
filename: /tmp/snapshot_{{ entity_id.name }}.mp4

You’ve hit a long-standing bug, but there is a workaround: lg_netcast platform fails to load if no channels defined · Issue #4024 · home-assistant/core · GitHub.

So this worked for me.

service: camera.record
target:
  entity_id: camera.computer_camera
data:
  filename: /media/mnt/recordings{{ computer_camera }}.mp4 

What does this actually resolve to? I’ve never seen this kind of usage. Or do you have a variable defined elsewhere?

This is the name of my camera in the configuration file.