Telegram send photo problems

I have this automation to send through telegram some weather infos including the icon showing the actual weather.

- alias: Telegram - weather forecast
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: /meteo
  action:
  - service: telegram_bot.send_photo
    data_template:
      target: '{{ trigger.event.data.user_id }}'
      disable_notification: true
      file: '/local/icons/weather_icons/animated/{{ states.sensor.dark_sky_icon.state }}.svg'
      caption: '{{ states.sensor.dark_sky_summary.state }}'
  - service: telegram_bot.send_message
    data:
      disable_notification: false
      message: '{{ states.sensor.dark_sky_hourly_summary.state }}

But, when i send the command /meteo i get only the second action of the automation (the service telegram_bot.send_message). About the first action i don’t get anything…
Hints? Solutions?

Does the telegram_bot.send_photo service support svg files?

Try with a jpg to test.

No way, i tried .jpg, .jpeg, .png. I always get the response from the second action and never from the first…

Try changing data_template: to data:

Already tried… i tried everything i can know about telegram integration.

The keys (trigger.event.data) of the telegram component has changed a bit over time. This action should work:

    - service: telegram_bot.send_photo
      data_template:
        target: '{{ trigger.event.data.chat_id }}'
        disable_notification: true
        file: '/var/homeassistant/config/www/climacons/{{ states.sensor.dark_sky_icon.state }}.png'
        caption: '{{ states.sensor.dark_sky_summary.state }}

If you want to define a target a the send_message service it looks like this:

    - service: telegram_bot.send_message
      data_template:
        target: '{{ trigger.event.data.chat_id }}'
        disable_notification: true
        message: >
          {{ states('sensor.dark_sky_hourly_summary') }}

I tried also to remove the target option as I read in this case it use the first or the default chat_id, but with the same result… I have only one chat Id.
When at home I will try your advice and let you know.

Sorry, i made the changes but the service still doesn’t work.

After testing many times in the developers tool services i see that only .jpg or .jpeg files are supported, so now i am asking how you have your automation working with .png files?

PNG is supported too. I guess your (relative?) path doesn’t work. May be the leading / is the issue. Could you try to use the url key instead of file to send a public available image?

If you want to use an absolute path like me, you have to whitelist this path:

homeassistant:
  [...]
  unit_system: metric
  time_zone: Europe/Berlin
  allowlist_external_dirs:
    - /var/homeassistant-sebastian/config/www

Ok, i tried without the '/ ’ at the beginning of the path, i have this in configuration.yaml:

  allowlist_external_dirs:
    - /config/ 

Is it enough?

I tried with a .jpeg photo in the same directory ‘www’ and it worked…
I tried also with a .png but still nothing…

Do you have a weather icon pack with png files? now i see finally .png files are supported… no .svg

I did convert the SVGs to PNG. Please check your PM.

Did you solve the problem and could you share your learnings?

Yes of course. First of all the service doesn’t support .svg files.
About the automation I solved using the complete path to the file to send i.e. using ‘/config/www/path_to_the_file’ and not ‘/local/path_to_the_file’.
About the target option, having only one chat id, i can omitt it…
Hope this help others with the same problem.