I have a problem sending pictures to a Telegram channel using a Telegram Bot from the core.
My automation, which sends pictures to a telegram channel stopped working with the following error message in logs:
Logger: homeassistant.components.telegram_bot
Source: components/telegram_bot/__init__.py:756
Integration: Telegram bot (documentation, issues)
First occurred: 10:11:33 AM (20 occurrences)
Last logged: 10:48:48 AM
Error sending photo: urllib3 HTTPError ('Connection aborted.', TimeoutError('The write operation timed out')). Args: (), kwargs: {'chat_id': -1001963003364, 'photo': <_io.BytesIO object at 0xffff662c2430>, 'caption': 'car camera1 1685000590.548033', 'disable_notification': False, 'reply_markup': None, 'timeout': None, 'parse_mode': 'Markdown'}
I assume this is an error the telegram_bot
integration trying to reach the telegram API api.telegram.org
, so I test it from Home Assistance SSH console:
$ curl https://api.telegram.org/bot<token>/getUpdates
{"ok":true,"result":[]}
So I can reach the telegram bot!
I tried to manually send the photo using the service call:
service: notify.camera_people
data:
data:
photo:
- url: >-
http://localhost:8123/api/frigate/notifications/1685001437.322383-o86h2i/snapshot.jpg
caption: test
message: test1
and get the same message in logs:
Logger: homeassistant.components.telegram_bot
Source: components/telegram_bot/__init__.py:756
Integration: Telegram bot (documentation, issues)
First occurred: 11:04:47 AM (3 occurrences)
Last logged: 11:04:56 AM
Error sending photo: urllib3 HTTPError ('Connection aborted.', TimeoutError('The write operation timed out')). Args: (), kwargs: {'chat_id': -1001963003364, 'photo': <_io.BytesIO object at 0xffff66352020>, 'caption': 'person camera1 1685001881.999579', 'disable_notification': False, 'reply_markup': None, 'timeout': None, 'parse_mode': 'Markdown'}
The picture under URL is perfectly reacheable:
curl -v http://localhost:8123/api/frigate/notifications/1685001437.322383-o86h2i/snapshot.jpg
* Trying 127.0.0.1:8123...
* Connected to localhost (127.0.0.1) port 8123 (#0)
> GET /api/frigate/notifications/1685001437.322383-o86h2i/snapshot.jpg HTTP/1.1
> Host: localhost:8123
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.22.1
< Date: Thu, 25 May 2023 08:08:53 GMT
< Content-Length: 1288918
< Connection: keep-alive
< Cache-Control: private, max-age=31536000
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
< Content-Type: image/jpeg
<
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
* Failure writing output to destination
* Closing connection 0
I use standard Telegram Bot integration from Core Telegram bot - Home Assistant
I can send plain text messages to the chat without problems using the following call:
service: notify.camera_people
data:
message: The garage door has been open for 10 minutes.
title: Your Garage Door Friend
Sending over send_photo
also does not work, results in the same error log message:
service: telegram_bot.send_photo
data:
url: >-
http://localhost:8123/api/frigate/notifications/1685001437.322383-o86h2i/snapshot.jpg
My telegram bot configuration in configuration.yaml
:
telegram_bot:
- platform: broadcast
api_key: secret_key
allowed_chat_ids:
- -1001963003364
notify:
- platform: telegram
name: camera_people
chat_id: -1001963003364
My full automation configuration:
alias: Frigate to Telegram Snapshot
description: Send snapshot to telegram
trigger:
- platform: mqtt
topic: frigate/events
condition:
- condition: template
value_template: "{{ trigger.payload_json.after.end_time != None }}"
enabled: true
action:
- service: notify.camera_people
data_template:
message: A{{trigger.payload_json["after"]["label"]}}
data:
photo:
- url: >-
http://localhost:8123/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/snapshot.jpg
caption: >-
{{trigger.payload_json["after"]["label"]}}
{{trigger.payload_json["after"]["camera"]}}
{{trigger.payload_json["after"]["end_time"]}}
mode: queued
max: 3