Notify.telegram message element not sending

Can anyone spot an issue with this code from an automation?
It sends the picture and caption but not the message element for notify.telegram.

  - service: notify.telegram
    data:
      message: '{% if states.sensor.facebox_detection.state != "unknown" %}  Facebox triggered. {{ states("sensor.facebox_detection") }} is at the door {% else %} Facebox triggered. {% endif %}'
      data:
        photo:
          file: '/config/www/facebox/tmp/image.jpg'
          caption: '{{now().strftime("%d.%m.%Y-%H:%M:%S")}}'
1 Like

I do believe for what you are trying to do with your message, you need to use a data_template for your message. I’m not 100% sure on this, but that is the direction I would go in.

@TinyDoT, thanks, changed to data_template but still no change.
From looking at other notify.telegram examples in forum, it seems I have correct format but still no message element.

  - service: notify.telegram
    data_template:
      message: >-
        {% if states.sensor.facebox_detection.state != "unknown" %}  
          Facebox triggered. {{ states("sensor.facebox_detection") }} is at the door 
        {% else %} 
          Facebox triggered. 
        {% endif %}
      data:
        photo:
          file: '/config/www/facebox/tmp/image.jpg'
          caption: '{{now().strftime("%d.%m.%Y-%H:%M:%S")}}'

I have a hazy memory that you can only send a picture OR a message in one go, and if you send both the picture overrides the message. I think it’s because if you want a message and a picture it has a different format (so the text gets overlaid on the picture) that isn’t supported by something or other. It’s been a long time.

The workaround is to send the picture, and then send the message separately straight after.

Hope this helps.

1 Like

@fergalom, mf_social might be on to something, you could split it up like mf_social said or you could send it in the caption, because you said that comes through. Just sent this:

'Facebox triggered. {{ states("sensor.facebox_detection") }} is at the door, {{now().strftime("%d.%m.%Y-%H:%M:%S")}}'

Forget about all the rest, it will tell you who or unknown is at the door, or just send the 2 messages.  One of these ways should make you a Happy Camper, I hope.
1 Like

Change the word unknown to “A stranger” and that seems like a pretty neat solution tbh.

1 Like

Thanks, agree it can be done through using the caption for the text.

Although even with a straightforward message element using “data:” instead of “data_template”, it does not work as per the documentation here.
https://www.home-assistant.io/components/notify.telegram/

Yeah, I think that bit of the docs are wrong. I should probably fix it :+1:

Not sure if something changed lately, but for Home Assistant version 0.104.2 I can’t send a message and a picture on the same Telegram message. But sending both separetely worked fine with the following:

For a script editing yourself the scripts.yaml file:

'1579459908654':
  alias: script_telegram_foto
  sequence:
  - data:
      caption: CĂ mera
      file: /config/www/snapshots/aaa.jpg
    service: telegram_bot.send_photo

For the Home Assistant interface (Config / Scripts / New):

  • Name: your_script_name
  • Call service: telegram_bot.send_photo
  • Data:
caption: camera
file: /config/www/snapshots/aaa.jpg