Can't send video with Telegram?

I keep getting the following error:
Can’t send file with kwargs: {‘file’: ‘/var/lib/motion/20-20180423100425.avi’, ‘caption’: ‘Garage Camera’}
2:15 PM components/telegram_bot/init.py (ERROR)
‘/var/lib/motion/20-20180423100425.avi’ are not secure to load data from!
2:15 PM components/telegram_bot/init.py (WARNING)

The directory is white listed.
whitelist_external_dirs:
- /var/lib/motion

Automations file:

  - alias: New file alert
    trigger:
      event_data: {"event_type":"created"}
      event_type: folder_watcher
      platform: event
    action:
      - service: telegram_bot.send_video
        data:
          file: /var/lib/motion/20-20180423100425.avi #' {{ trigger.event.data.path }} '
          #username: admin
          #password: !secret garagecam_password
          caption: Garage Camera

No one? :frowning:

Can you properly format code? Select your code and use preformatted text button.

Updated - could have sworn I did that…

Side note - the video file is currently hard-coded to rule out any problem with getting the file name dynamically, or permissions.

Try to send it like this:

  action:
    - service: notify.YOUR_TELEGRAM_NAME
      data:
        title: 'File'
        message: 'Created'
        data:
          video:
            - file: /var/lib/motion/20-20180423100425.avi
              caption: Garage Camera
1 Like

Unfortunately the same thing

Can’t send file with kwargs: {‘file’: ‘/var/lib/motion/20-20180423100425.avi’, ‘caption’: ‘Garage Camera’, ‘title’: ‘File’, ‘message’: ‘Created’}
16:54 components/telegram_bot/init.py (ERROR)
‘/var/lib/motion/20-20180423100425.avi’ are not secure to load data from!
16:54 components/telegram_bot/init.py (WARNING)

Just for test. Try to create new folder in your home directory. Whitelist it. And move avi file to that directory.

1 Like

Progress - that works… video doesn’t open in telegram, but it does in VLC, so it’s probably a codec thing.

It’s probably problem with permissions. Compare permissions in those two folders.

I think you might be right, it looks like even though its inheriting the group from the parent folder, its still creating the file under the motion user - which seems to be causing the problem.

Public and the home-assistant group of read to the newly created files, but it doesn’t seem enough.

It looks like it’ll only work if the home assistant user owns the file - if another user owns the file it doesn’t work…even if the group and public are given full access to the file.

EDIT: nevermind, that’s also not it.

After trying various combinations - this seems to be the least restrictive to get it working…764. Only problem is I can’t get motion to create files with those permissions.

pi@hass:/home/homeassistant/security $ sudo chmod -R 766 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 666 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 766 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 764 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 664 /home/homeassistant/security

pi@hass:/home/homeassistant/security $ sudo chmod -R 664 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 664 /home/homeassistant/security
pi@hass:/home/homeassistant/security $ sudo chmod -R 764 /home/homeassistant/security

A bit dependent on the platform your running HA on but you can do what you want with ACL’s

1 Like

Thanks - running Rasbiaan at the moment, but might change in the future.

I got it working with 764 - and then when I changed it to use the below I started getting the error again, if I changed to a hardcoded file name of the one derived from the event, it worked.
action:

  • service: telegram_bot.send_video
    data:
    file: ’ {{ trigger.event.data.path }} '
    #username: admin
    #password: !secret garagecam_password
    caption: Garage Camera

My work-around, which worked, was to assigned the value to a input_text field - then use the input_text field as the input for above action. Not the neatest solution, but its working.

I now need to just get the correct encoding for Telegram to play the video in app. mpeg and mp4 aren’t working

1 Like

Interesting problem, home-assistant grabs the file and sends it while it’s being recorded - so you only get a few seconds on the video - I think when I get back from leave I’ll have to have it write to a location, then somehow have it picked up and moved on completion to the location home-assistant monitors.

Then - still can’t get Telegram to natively play the video - tried various codecs, same error - but at least they all open in VLC.

I use mp4. And it works.

In Telegram? Interesting - maybe it has something to do with the motion settings - I’ve set the video to the size specified in the telegram api docs. Tried on both my tablet and phone - neither play the video in app. I just get a blank video.

Have a look at the on_movie_end and similar options in motion to copy it after it’s done.

1 Like

I use ffmpeg in script. And use delay to get 10 seconds of mp4 video.

Definitely think there’s something wrong with the motion encoding of videos then - I can only open them in VLC. Even on my PC, directly of the server.