What's wrong with my repeat script?

Hi everybody,

I am trying to create a script that will send a variable number of still images from one of my cameras when triggered. The script should allow me to pass the amount of pictures, the amount of delay in seconds in between sending those pictures, and the camera entity.

When I trigger the script via another script passing on the data, nothing happens. Can you please tell me what’s wrong with it? Thank you in advance for your ideas :slight_smile:

script:
  cam_tg_template:
    sequence:
      - alias: "x mal wiederholen"
        repeat:
          count: "{{ count | int }}"
          sequence:
            - delay: "{{ delay | int }}"
            - service: notify.tg_me
              data:
                message: "{{ cam }}"
                data:
                  photo:
                    - url: >
                        http://home:8123{{state_attr("{{ cam }}", "entity_picture")}}
  cam_tg_template_trigger:
    sequence:
      - alias: "Rufe das cam_tg_template Script x mal auf"
        service: script.cam_tg_template
        data:
          count: '{{ states("input_number.cam_anzahl_bilder_home") | int }}'
          delay: '{{ states("input_number.cam_pause_bilder_home") | int }}'
          cam: 'camera.dach'

The only thing that looks questionable is the url. What is the url supposed to be for that camera? I’m not 100% sure, but I’m guessing the template should be:

http://home:8123/{{ state_attr(cam, "entity_picture") }}
1 Like

Thank you. The issue was that I had those curly brackets around cam.

Using the camera’s URL does not work, as it doesn’t provide a still image. So I am using the entity_picture attribute of the camera entitiy inside Home Assistant. This works much better (with all my cameras) than any other attempt (for example, some cameras don’t seem to be compatible to camera.snapshot, yet using the entity_picture works every time.

The old trying to use a template inside a template trick! :stuck_out_tongue_winking_eye: Not an uncommon mistake.

It would be helpful for others that might come across this topic in the future if you would post the working automation.

Sure thing, this is the actual code that works fine:

script:
  cam_tg_template:
    sequence:
      - alias: "x mal wiederholen"
        repeat:
          count: "{{ count | int }}"
          sequence:
            - delay: "{{ delay | int }}"
            - service: notify.tg_me
              data:
                message: "{{ cam }}"
                data:
                  photo:
                    - url: >
                        http://<HASS-URL>:<HASS-PORT>{{state_attr(cam, "entity_picture")}}
  cam_tg_template_trigger:
    sequence:
      - alias: "Rufe das cam_tg_template Script x mal auf"
        service: script.cam_tg_template
        data:
          count: '{{ states("input_number.cam_anzahl_bilder_home") | int }}'
          delay: '{{ states("input_number.cam_pause_bilder_home") | int }}'
          cam: 'camera.dach'
1 Like