Simple button to take a snapshot of each camera

I find a simple way to take a snapshot of each camera integrated in home assistant.

  1. Create an automation to set a group of all your cameras when HA starts
alias: Survillance - Create cams group
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - service: group.set
    data_template:
      object_id: all_cams
      entities: |-
        {%- for s in states.camera
          if ('camera' in s.entity_id or 'cam' in s.entity_id)%}
          {{s.entity_id}}{% if not loop.last %}, {% endif %}
        {%- endfor %}
mode: single
  1. Create a button card in lovelace that call the camera.snapshot service for the group above
show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: camera.snapshot
  target:
    entity_id: group.all_cams
  data:
    filename: /media/cams/snaps/snaptk_{{ entity_id.name }}.jpg
entity: input_button.all_cams_snapshot
show_state: false

Everytime you use this button, a snapshot of each camera will be created in your favourite path.
Cheers

  target:
    entity_id: expand('group.all_cams')

You can’t directly act on the group in this way, but by expanding it you’re making it a list that the snapshot service can deal with.

Also mind this bug: Camera.record service not working with entity_id.name in template, says entity_id is undefined · Issue #40241 · home-assistant/core · GitHub.

Your group set won’t work either: You need to actually give the service a list, e.g.:

entities: "{{ states.camera | map(attribute='entity_id') | list }}"

Unless you’re going to use the group for other things, you don’t really need the extra complexity of the automation, so you can just use the above in your snapshot service call.

Next time, include your logs/errors.

You can’t directly act on the group in this way, but by expanding it you’re making it a list that the snapshot service can deal with.

Yes you can via lovelace card… your example doesn’t work…

Unless you’re going to use the group for other things, you don’t really need the extra complexity of the automation, so you can just use the above in your snapshot service call.

you are right but my example is an inspiration to create sub-categories of cameras such as internal or external replacing the loop criteria:

if ('camera' in s.entity_id or 'cam' in s.entity_id)