Send camera snapshot to Telegram

Hi all

I have a question regarding Telegram. I don’t get it working. It’s really strange.

What do I want: I want a motion image to be send through Telegram to my phone. This is my flow

alias: Send Telegram Motion Screenshot (test)
description: Source Dahua Camera 
trigger:
  - type: motion
    platform: device
    device_id: aaaaaaaaaaaaaaaaaaaaaaaa
    entity_id: binary_sensor.00000_motion_alarm
    domain: binary_sensor
condition: []
action:
  - service: camera.snapshot
    data:
      filename: /screenshot/dahua_snapshot.jpg
    target:
      entity_id: camera.dahua_mediaprofile_channel1_mainstream
  - service: notify.telegram_aaa
    data:
      message: test
      data:
        photo:
          - file: /screenshot/dahua_snapshot.jpg
            caption: Movement
mode: single

I also tried this:

action:
  - service: notify.telegram_aaa
    data:
      title: Send an image
      message: ''
      data:
        photo:
          - url: http://192.168.168.168/cgi-bin/snapshot.cgi
            username: username
            password: password
            authentication: digest
            caption: Movement

The normal part:

  • If I start the flows manually, the snapshot will be send. Even if I click it every 5 seconds. ALL THE TIME
  • If in developer tools I change the state from the binary_sensor.00000_motion_alarm to on: The flow triggers and works. ALL THE TIME
  • If I make a flow with only text to be send. This works always, also when the motion sensor has been triggered by onvif.

Now the strange part:

  • Bot actions are NEVER working when the motion sensor has been triggered by a real event. Truly NEVER.
  • When the sensor has been triggered by a real event, the snapshot in /screenshot/dahua_snapshot.jpg is ALWAYS updated to the new image.

I want to focus on the first option (saving the file to /screenshot/dahua_snapshot.jpg). If I look in the logging, I get these messages all the time if it fails.

2022-02-17 16:40:54 ERROR (SyncWorker_11) [homeassistant.components.telegram_bot] Error sending photo: Image_process_failed. Args: (), kwargs:{'chat_id': 1111111, 'photo': <_io.BufferedReader name='/screenshot/dahua_snapshot.jpg'>, 'caption': 'Movement', 'disable_notification': False, 'reply_markup': None, 'timeout': None, 'parse_mode': 'Markdown'}

Can anyone point me in a direction where I can solve this? I am just new with Home Assistant, but I can’t wrap my head around what I am doing wrong here.

1 Like

I haven’t been able to solve this. I moved on to Signal, which is working fine for me.

Use the telegram_bot.send_photo service

1 Like

I just saw this thread.
Using the OP configuration waht needs to be changed.
I am unsure of where to put the telegram_bot.send_photo
Thanks

I have it placed in automation

  - service: telegram_bot.send_photo
    data:
      file: /config/www/kamerafoto/xxxxxxx.jpg
      caption: xxxxxxxxx
3 Likes

Thanks now I understand

how can I handle, that the actual picture will be send.
My picture get there name from date and time.
Like
20221205-173525.jpg
20221205-173528.jpg

any idea ? thx

1 Like

I use on my automation

  - service: camera.snapshot
    data:
      entity_id: camera.cam2
      filename: >-
        /config/www/camera_snapshots/mysnap_{{ now ().year }}_{{ now ().month
        }}_{{ now ().day }}_{{ now ().hour }}_{{ now ().minute }}.jpg
    entity_id: camera.cam1
    enabled: true

scusate qualcuno ha risolto? come?

Can someone share the full config on how to sent a camera motion snapshot image to a telegram group?

1 Like

Looking for the same… :wink:

Hello everyone!
For those who googled this topic and are delving into telegram notifications, I will describe my configuration.

First of all, you must have a telegram bot installed and configured correctly for HA.
That’s my part of configuration.yaml for tg:

telegram_bot:
  - platform: polling
    api_key: 1234567890:ABCD-01235-ABCDE # fake api, redacted for this message
    parse_mode: html
notify:
  - platform: telegram
    name: Maxim
    chat_id: 198765432  # fake id, redacted for this message

Next is setting up automation. This can be done more clearly through the GUI, but below I will provide the code that is obtained in my automations.yaml.
Pay attention to the file paths. Depending on your HA installation, the folder to which the automation has rights to write snapshots may differ. Always check whether an image file is created on a motion event.
The name of action notify.maxim related to lowercased name: Maxim of notify block from configuration.yaml.

This is a part of automations.yaml regarding notifications from my motion alarm automation.
The first action is to take snapshot and saves it to file. The second one is to send this file.

- id: '1692823845703'
  alias: Dooreye Motion
...
...
  actions:
  - data:
      filename: /config/screenshots/dooreye_1.jpg
    target:
      entity_id:
      - camera.nvt_mainstream
    action: camera.snapshot
  - action: notify.maxim
    data:
      message: Motion detected!
      data:
        photo:
        - file: /config/screenshots/dooreye_1.jpg
          caption: Motion detected!
  mode: single

That’s all. Don’t forget to run test runs of the automation and then check the tracing.

2 Likes

I found this very easy to follow and at up!

is anyway i can send same snapshot file to telegram bot with the same action block ?