Why does this not work when it works in developer service call?

If used in automation I get the data but not the attached picture. Service call does work with picture and it has the exact same code/indentation.

Telegram complaining in logs about:

First occurred: 13:05:29 (31 occurrences)
Last logged: 13:52:42

* Error while executing automation automation.send_telegram_using_main: extra keys not allowed @ data['url']
* Error while executing automation automation.send_telegram_using_main: extra keys not allowed @ data['caption']
* Error while executing automation automation.send_telegram_using_main: required key not provided @ data['message']

Telegram call in developer tools:

service: notify.telegram_main
data:
  data:
    photo:
      - url: >-
          http://homeassistant.local:3000/api/storage/matches/565756d0-9cb4-4d02-8b03-00b2a6b874e0.jpg?box=true
        caption: test
  message: test1

Telegram call in automation:

action:
  - service: notify.telegram_main
    data:
      message: ""
      data:
        photo:
          - url: >-
              {% if trigger.to_state.attributes.match is defined %}
              http://homeassistant.local:3000/api/storage/matches/{{trigger.to_state.attributes.match.filename}}?box=true
              {% elif trigger.to_state.attributes.unknown is defined %}
              http://homeassistant.local:3000/api/storage/matches/{{trigger.to_state.attributes.unknown.filename}}?box=true
              {% endif %}
            caption: >-
              {% if trigger.to_state.attributes.match is defined %}
              {{trigger.to_state.attributes.friendly_name}},
              {{trigger.to_state.attributes.unknown.gender.value}}, age
              {{trigger.to_state.attributes.unknown.age.low}} -
              {{trigger.to_state.attributes.unknown.age.high}} and {{
              trigger.to_state.attributes.unknown.mask.value.replace('_',' ')}}
              is near the {{trigger.to_state.state.replace('_',' ')}} @
              {{trigger.to_state.attributes.match.confidence}}% by
              {{trigger.to_state.attributes.match.detector}}:{{trigger.to_state.attributes.match.type}}
              taking {{trigger.to_state.attributes.attempts}} attempt(s) @
              {{trigger.to_state.attributes.duration}} sec {% elif
              trigger.to_state.attributes.unknown is defined %} unknown,
              {{trigger.to_state.attributes.unknown.gender.value}}, age
              {{trigger.to_state.attributes.unknown.age.low}} -
              {{trigger.to_state.attributes.unknown.age.high}} and {{
              trigger.to_state.attributes.unknown.mask.value.replace('_',' ')}}
              is near the {{trigger.to_state.state.replace('_',' ')}} @
              {{trigger.to_state.attributes.unknown.confidence}}% by
              {{trigger.to_state.attributes.unknown.detector}}:{{trigger.to_state.attributes.unknown.type}}
              taking {{trigger.to_state.attributes.attempts}} attempt(s) @
              {{trigger.to_state.attributes.duration}} sec {% endif %}
mode: single
max: 2

Have you tried it with an actual message string? message is usually required for notification service calls and an empty string may not satisfy the requirement.

Trying that now, i picked up in another post that i needed an empty message string, but i just noticed that difference as well. Just waiting for it to trigger now :slight_smile:

So yeah, that didn’t work either strangely enough. This is the output of the trace:

Executed: 16 November 2023 at 20:30:42
Result:
params:
  domain: notify
  service: telegram_main
  service_data:
    message: test1
    data:
      photo:
        - url: >-
            http://homeassistant.local:3000/api/storage/matches/25f4052f-1dfa-4ec0-bbe2-453db3b8e66d.jpg?box=true
          caption: >-
            unknown, male, age 32 - 32 and without mask is near the diningroom
            camera 1 @ 25.78% by compreface:snapshot taking 23 attempt(s) @ 4.42
            sec
  target: {}
running_script: false

I thought that would be it as well, as that’s the one thing different from the service call and the action in my automation…

YAML is really picky about formatting, so try to indent your lines in the if scopes.
Also try to use
{%- -%} and {{- -}}
The minus will affect the return characters in your text area, so they are ignored as characters. Without the minus the return characters might be splitting the values up in multiple lines.

I’ll try that. I have a feeling it has to do with how Telegram handles special characters so this might do the trick.

It is not telegram.
It is complaining about the YAML text.
It says there are multiple lines and that is not allowed.