Camera.record and send video with telegram

Hi,

I am trying to record a video from my hacked dafang camera and send it with Telegram.
The video gets recorded and saved but it never gets send because the video file only gets created after the recording is done and even than it takes around 1 second per recorded second to build up the file (the file gets bigger and bigger till it’s saved completely).

This is my automation:

- alias: notify_1_dafang_1_get_current_video
  initial_state: true
  trigger:
    - platform: event
      event_type: telegram_callback
      event_data:
        command: '/dafang_1_get_video'

  action: 
    - service: notify.notify_1
      data_template:
        title: "VIDEO Recording is in Progress"
        message: "{{now().strftime('%Y-%m-%d %H:%M:%S')}}"  
    - service: camera.record
      data_template: 
        entity_id: camera.dafang_1_generic
        filename: '/config/www/dafang_1/test.mp4'
        duration: '{{trigger.event.data.args[1] | int}}'
        lookback: '{{trigger.event.data.args[0] | int}}'
    - service: notify.notify_1
      data_template:
        message: "Front Door Video from Door open"
        data:
          video:
            file: "/config/www/dafang_1/test.mp4"
            caption: "{{now().strftime('%Y-%m-%d %H:%M:%S')}}"
          inline_keyboard: 
            - 'Vid  5::/dafang_1_get_video 5 30, 5 30:/dafang_1_get_video 5 30, 5 60:/dafang_1_get_video 5 60, 5 120:/dafang_1_get_video 5 120'
            - 'Vid 10::/dafang_1_get_video 10 30,10 30:/dafang_1_get_video 10 30, 10 60:/dafang_1_get_video 10 60, 10 120:/dafang_1_get_video 10 120'
            - 'Home:/home'

I get this error:

2020-03-19 22:45:12 ERROR (SyncWorker_3) [homeassistant.components.telegram_bot] Can't load data into ByteIO: [Errno 2] No such file or directory: '/config/www/dafang_1/test.mp4'
2020-03-19 22:45:12 ERROR (SyncWorker_3) [homeassistant.components.telegram_bot] Can't send file with kwargs: {'message': 'Front Door Video from Door open', 'inline_keyboard': ['Vid  5::/dafang_1_get_video 5 30, 5 30:/dafang_1_get_video 5 30, 5 60:/dafang_1_get_video 5 60, 5 120:/dafang_1_get_video 5 120', 'Vid 10::/dafang_1_get_video 10 30,10 30:/dafang_1_get_video 10 30, 10 60:/dafang_1_get_video 10 60, 10 120:/dafang_1_get_video 10 120', 'Home:/home'], 'file': '/config/www/dafang_1/test.mp4', 'caption': '2020-03-19 22:45:12'}

I also tried to split the automation into two:

  1. records the video
  2. triggered with folder_watcher to send the video: Here I have the same problem because it triggers the second the file gets created, but it isn’t created completely.

I know I can use a delay between the recording and the sending but I record videos with variable lengths and would like a solution without a delay. I would like to give the video the current time as a filename and if I do so I have no chance to get the filename in order to send it.

Anyone has an idea how this is possible?

Why don’t you send the video directly from camera to telegram. I have configured like that and it works fine.

Can you show my your automation to do that?

isn’t an automation. You do that on the configuration of the camera. You have to do a search on web. One for configuration of telegram on camera, and other how to creat a bot on telegram.
1º First you do the creatiationof the bot on telegram (to receive camera messages) because you will need a token.
2º go to config/telegram.conf, (if it doesn’t exist you copy telegram.conf.dist and after remove “.dist” from the copy name. then you add or change the following lines:
apiToken=“YOUR_TOKEN_HERE”
userChatId=“YOUR_CHAT_ID_HERE”
3º Change the motion.conf file to send telegram on motion and what type of notification, video or image
If you need more assistance please say so

surely this is a niche though. I haven’t heard of any cameras that support such a feature??

1 Like

Hi Drthanwho,

I did this with Xiaomi Dafang camera, where i change the firmware to this:

I can controlo the camera with HA and send motion alarm videos to telegram directy.

you need add a delay.

1 Like

Hi. I am testing a telegram bot to upload video and other files from camera or other devices to telegram through FTP without any additional software or hardware. t.me/ftp2bot

Hi,
I post here, because, i did the similar thing and i solved the pb with replacing { video_filename }} with text only in caption entry…
vars are mandatory for caption??!!
i was parse_mode indeed! mandatory because i use _. :wink:

  - action: notify.telegram
    metadata: {}
    data:
      title: "🎥: Motion capture"
      data:
        parse_mode: html
        video:
          - file: /media/videos/{{ video_filename }}
            caption: "{{ video_filename }}"
      message: Mvt detected!
variables:
  date: "{{ now().strftime(\"%Y%m%d-%H%M%S\") }}"
  video_filename: e1zoom_{{ date }}.mp4
mode: single