Sending a video via Telegram: re-sending in case of failure

This code records camera video and sends via telegram, but often fails, sometimes fails to send via telegram. I want when sending via telegram if it fails it will try to send again. How do I edit it? I am new, can someone help me edit it? Thank you for reading the article.

(I mean sometimes when the network is unstable it won’t send, so I want to edit it, so when sending there is an error due to the network or something else. it will resend about 3 times.)


video san 1 (Nhân bản)uu
sequence:
  - alias: biến chứa tên file, file nằm trong thư mục /config/www/snapshots/
    variables:
      filename: >-
        /config/www/snapshots/{{camera}}_{{now().strftime('%b%d_%H%M')}}_{{range(10,99)|random}}.mp4
  - alias: ghi lại video
    data:
      entity_id: "{{camera}}"
      filename: "{{filename}}"
      duration: "{{duratioduration action: camera.record
  - alias: gửi video đến tài khoản telegram mặc định
    data:
      file: "{{filename}}"
      caption: ""
      parse_mode: html
    enabled: true
    action: telegram_bot.send_video
variables:
  camera: camera.cam_o_san_profile000
  duration: 150
fields:
  camera:
    description: entity_id của camera sẽ được ghi
    example: camera.cam_o_san_profile000
  duration:
    description: độ dài video, mặc định 60s
    example: 60
mode: single
icon: mdi:motion
description: ""

I am not sendiing video, just a text with a call like

    - service: notify.some_telegram_chat
      data:
        message: ...

Sometimes I am seeing an error in Log like:

2024-08-09 06:37:39.532 ERROR (MainThread) [homeassistant.components.telegram_bot] Error sending message: Timed out. Args: (-1009917799099, ‘xxxxxxx’), kwargs: {‘parse_mode’: <ParseMode.HTML>, ‘disable_web_page_preview’: False, ‘disable_notification’: False, ‘reply_to_message_id’: None, ‘reply_markup’: None, ‘read_timeout’: None, ‘message_thread_id’: None}

and this message in not actually sent (at least I am not getting it via Telegram).
I have no idea if there any possibility to get an error flag in return after calling that “notify.xxx” service (and then process this flag & re-send the message), only getting an error in Log.

I also get the same error message as you.

So, since a service to send a message via Telegram does not guarantee that this message will be send - than probably we should ask for a possibility like “return a status of sending”. Since some HA version it is possible to get an answer from a service (“responsible services”) - may be smth similar should be provided for Telegram services?

Created a FR: Telegram: acquire a status of sending (success/failed)

I sent camera video via telegram and got this error. Please help me fix it.

Bộ ghi nhật trình: homeassistant.components.telegram_bot
Nguồn: components/telegram_bot/__init__.py:717
bộ tích hợp: Telegram bot (tài liệu, sự cố)
Lần đầu tiên xảy ra: 06:48:49 (6 lần xuất hiện)
Ghi nhật ký lần cuối: 07:45:43

Error sending video: Timed out. Args: (), kwargs: {'chat_id': -4287636754, 'video': <_io.BytesIO object at 0xffff4c10f290>, 'caption': '', 'disable_notification': False, 'reply_to_message_id': None, 'reply_markup': None, 'read_timeout': None, 'parse_mode': <ParseMode.HTML>, 'message_thread_id': None}

alias: Cam o san 1
sequence:
  - alias: biến chứa tên file, file nằm trong thư mục /config/www/snapshots/
    variables:
      filename: >-
        /config/www/snapshots/{{camera}}_{{now().strftime('%b%d_%H%M')}}_{{range(10,99)|random}}.mp4
  - alias: ghi lại video
    data:
      entity_id: "{{camera}}"
      filename: "{{filename}}"
      duration: "{{duration}}"
    action: camera.record
  - alias: chờ 1s sau khi kết thúc ghi để cho video ghi xong
    delay:
      seconds: "{{duration|int + 0}}"
  - alias: gửi video đến tài khoản telegram mặc định
    data:
      file: "{{filename}}"
      caption: ""
      parse_mode: html
    enabled: true
    action: telegram_bot.send_video
variables:
  camera: camera.cam_o_san_profile000
  duration: 150
fields:
  camera:
    description: entity_id của camera sẽ được ghi
    example: camera.cam_o_san_profile000
  duration:
    description: độ dài video, mặc định 60s
    example: 60
mode: parallel
icon: mdi:motion
description: ""
max: 10

People probably wants to see the automation that sends the telegram message rather than the error message.

please help me fix it

Not sure if this is the error, but try to change this.

      filename: >-
        /config/www/snapshots/{{camera}}_{{now().strftime('%b%d_%H%M')}}_{{range(10,99)|random}}.mp4

To this.

      filename: /config/www/snapshots/{{camera}}_{{now().strftime('%b%d_%H%M')}}_{{range(10,99)|random}}.mp4

And then check that you can actually see the file in the folder.

yes. there is mp4 file in that folder. sometimes it gives error like above and doesn’t send video via telegram, 100 times run it gives error about 30 times

:pensive::slightly_smiling_face:‍:arrow_up_down::slightly_smiling_face:‍:arrow_up_down::slightly_smiling_face:‍:arrow_up_down:

Maybe the delay is too short and the file is not there when it tries to send it.

In my case I have a delay 3 sec - i.e. next TM message is send after 3 sec.
And in my case it is a small text.
So, no idea why TM is unable to send.
Happens only sometimes.