Video in telegram notification?

Can i send 10 seconds mkv video with telegram notification? I tried with telegram image and document but it doesn’t work.

@vladosam did you solve your problem? if yes, please share your config.

Yes i did. I save 10 seconds of mp4 video with shell_command and ffmpeg.

shell_commands.yaml

snapshotv: !secret snapv

secret.yaml

snapv: ffmpeg -rtsp_transport tcp -r 25 -i rtsp://USER:PASS@IP:10554/tcp/av0_0 -an -t 10 -c copy -map 0 -y -update 1 {{filename}}

script.yaml

telegram_video:
  alias: "10 sec mp4"
  sequence:
    - service: shell_command.snapshotv
      data:
          filename: /tmp/shot1.mp4
    - delay:
        seconds: 12
    - service: telegram_bot.send_video
      data_template:
        file: "/tmp/shot1.mp4"
2 Likes

thanks for input, @vladosam but i run homeassistant on hassio.it is works on hassio?
and i dont use rtsp, i use http
i see my stream cam with the ip http://192.168.1.101:8081/
how i can to do that?

Hi, I’m getting this msg with your script

'/tmp/shot1.mp4' are not secure to load data from!

Can you tell me what’s wrong?

Then I get this msg, but I think he says that because he did not create the file.
Can’t send file with kwargs: {‘file’: ‘/tmp/shot1.mp4’}

when I try the separate command, I get this error.

Sat Jul 28 2018 21:18:30 GMT-0300 (Horário Padrão de Brasília)

Error running command: `ffmpeg -rtsp_transport tcp -r 25 -i rtsp://192.168.1.20:7447/5b58e81dfec23eb308075784_0 -an -t 10 -c copy -map 0 -y -update 1 {{filename}}`, return code: 1
NoneType: None

I checked that I had to set the secure directory on the telegram.

homeassistant:
whitelist_external_dirs:
- /tmp

I have now I have another different error.

Error sending file: Timed out. Args: (543056216, <_io.BufferedReader name='/tmp/shot1.mp4'>), kwargs: {'caption': None, 'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}
21:36 components/telegram_bot/__init__.py (ERROR)

New erro

Error sending file: urllib3 HTTPError ('Connection aborted.', timeout('The write operation timed out',)). Args: (543056216, <_io.BufferedReader name='/tmp/shot1.mp4'>), kwargs: {'caption': None, 'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}
21:52 components/telegram_bot/__init__.py (ERROR)

I do not know what happened … But it worked … Actually does not send a video and yes animated gif … does not come audio … LOL

I had the same problem again.

Log Details (ERROR)
Sun Jul 29 2018 18:33:47 GMT-0300 (Horário Padrão de Brasília)

Error sending file: urllib3 HTTPError ('Connection aborted.', timeout('The write operation timed out',)). Args: (543056216, <_io.BufferedReader name='/tmp/shot1.mp4'>), kwargs: {'caption': 'Campainha', 'parse_mode': 'Markdown', 'disable_notification': False, 'disable_web_page_preview': None, 'reply_to_message_id': None, 'reply_markup': None, 'timeout': None}

It seems that this is your problem:

Try to shrink you file to < 500 kb to test it.

I don’t use hassio but i think that ffmpeg is installed by default.
Try to find correct ffmpeg command for your camera. Something like this

ffmpeg -i http://192.168.1.101:8081 -t 10 -c:v mjpeg -qscale 10 -y -update 1 {{filename}}

Internet is your friend :wink:

2 Likes

Thanks for answering. I actually get an animated gif when it works. But how are you saying that the telegram can not send a file bigger than 500kb. That’s the best we can get a gif.

I just saw that you have same issue as other people. And that issue is not affecting everybody. It seems that 10MB is limit for autoplay gif in telegram, 50MB without autoplay.

@vladosam when a try to run shell command i receive this:

Error running command: ffmpeg -i http://192.168.1.101:8081 -t 10 -c:v mjpeg -qscale 10 -y -update 1 {{filename}}, return code: -11
NoneType: None

Where is the video saving you have access to?

Yes. I have acess

Show us all your code for this. Shell command, scripts, configuration…

I’m using Hassio version 0.93 and the camera.record function works pretty good with Telegram.

Example automation.yaml:

- alias: 'TEST'
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d0001
    to: 'on'
  action:
    - service: camera.record
      data:
        entity_id: camera.xiaomi_ants_cam
        filename: '/config/www/test.mp4'
        duration: 10
        lookback: 30
    - service: notify.telegram
      data:
        title: "Test"
        message: This is a Testvideo
        data:
          video:
            - file: '/config/www/test.mp4'
              caption: This is a test
1 Like

just wanted to say thinks for posting this, it’s working great for me!

1 Like