Can't attach static image from webcam to telegram using Dlink DCS-935L

Hi,

I got lucky today at my local Staples and snagged two Dlink DCS-935L IP Cameras. I have them up and running, and I can see them in HA with a static image that is changed every 10 seconds using the generic MJPEG stream. I am now trying to add Telegram in, as one of the webcams I have in my porch and would like it to send a message/picture when my doorbell is pressed. I have the automation working, and can successfully send a text only notification with Telegram and syncs to my devices. But, when I try to add the photo, I get this error in my HA log:

16-09-10 19:35:23 homeassistant.core: BusHandler:Exception doing job
Traceback (most recent call last):
  File "/home/hass/.homeassistant/deps/telegram/inputfile.py", line 90, in __init__
    self.mimetype = InputFile.is_image(self.input_file_content)
  File "/home/hass/.homeassistant/deps/telegram/inputfile.py", line 170, in is_image
    raise TelegramError('Could not parse file content')
telegram.error.TelegramError: Could not parse file content

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/core.py", line 852, in job_handler
    func(*args)
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/core.py", line 717, in _execute_service
    service(call)
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/core.py", line 572, in __call__
    self.func(call)
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/components/notify/__init__.py", line 106, in notify_message
    data=data)
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/components/notify/telegram.py", line 102, in send_message
    self.send_photo(photo_data)
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/components/notify/telegram.py", line 126, in send_photo
    photo=photo, caption=caption)
  File "/home/hass/.homeassistant/deps/telegram/bot.py", line 121, in decorator
    result = func(self, *args, **kwargs)
  File "/home/hass/.homeassistant/deps/telegram/bot.py", line 147, in decorator
    result = request.post(url, data, timeout=kwargs.get('timeout'))
  File "/home/hass/.homeassistant/deps/telegram/utils/request.py", line 227, in post
    data = InputFile(data)
  File "/home/hass/.homeassistant/deps/telegram/inputfile.py", line 94, in __init__
    self.mimetype = mimetypes.guess_type(self.filename)[0] or DEFAULT_MIME_TYPE
  File "/usr/lib/python3.5/mimetypes.py", line 289, in guess_type
    return _db.guess_type(url, strict)
  File "/usr/lib/python3.5/mimetypes.py", line 114, in guess_type
    scheme, url = urllib.parse.splittype(url)
  File "/usr/lib/python3.5/urllib/parse.py", line 861, in splittype
    match = _typeprog.match(url)
TypeError: expected string or bytes-like object

This is my lines in automation.yaml

- alias: 'Back Door Notify'
  trigger:
      platform: state
      entity_id: binary_sensor.2_door_chime_sensor_2_1
      state: 'on'
  action:
    service: notify.webcam_telegram
    data:
      message: "Someone is at the back door!"
      title: "Home Assistant"
      data:
        photo:
          - url: http://192.168.86.130/image/jpeg.cgi
            username: xxxxxx
            password: xxxxxx

Does anyone have any idea what I am doing wrong, or can’t I parse the URL to get the snapshot?

Thanks,

1 Like

Finally I’m able to help somebody! I made this yesterday. I doesn’t win any prizes, but it does the job. The next thing I want to do is create 5 pics, 1 second apart and telegram it. Should be easy with copy/paste but that not very elegant.

cfg/shell_commands.yaml
take_pic: curl -o /home/hass/snapshot.jpg -A cgi http://admin:[email protected]/image/jpeg.cgi

cfg/automation/test_telegram.yaml:

  • alias: ‘Test Telegram’
    trigger:
    • platform: state
      entity_id: input_boolean.test_telegram
      to: ‘on’
      action:
    • service: shell_command.take_pic
    • delay 00:00:10
    • service: notify.telegram
      data:
      title: Send
      message: Send Image
      data:
      photo:
      - file: /home/hass/snapshot.jpg
3 Likes

Hi @jilsx

Thank you for your help. I was able to get it to work wonderfully with my camera. I ended up for ease of use placing the shell_command right into my configuration.yaml file for now, but it works. Telegram seems to be sending me the message about 10 minutes later for some reason though; i’ll have to look into that.

I was able to get the automation to work with with this:

- alias: 'Back Door'
  trigger:
      platform: state
      entity_id: binary_sensor.2_door_chime_sensor_2_1
      state: 'on'
  action:
    - service: shell_command.take_pic_porch
    - delay: 0:02
    - service: notify.webcam_telegram
      data:
        title: Home Assistant
        message: Someone is at the back door!
        data:
          photo:
            - file: /home/hass/.homeassistant/snapshots/snapshot_porch.jpg
              caption: Back Porch Doorcam

Did you ever get your consecutive telegram’ed pictures working? I was thinking of doing the same thing and linking it to a motion sensor and automation rule.

1 Like

I’ve ended up with the following:

  • Send 1 pic via telegram
  • Send 10 pics (on second apart) via mail. I found this a little more elegant (to use my prior words). Probably can do it with Telegram and HASS alone, but I’m already spending way to much time figuring out how that would work. Still getting used to the syntax.

The shell command I’m using is:

#!/bin/bash

month=$(date +"%m")
day=$(date +"%d")

hour=$(date +"%H")
minute=$(date +"%M")
second=$(date +"%S")

folder=/mnt/sda/hass/camera1/$day$month-$hour$minute$second

mkdir -p “$folder”

for num in {1…10}
do
curl -o $folder/$num.jpeg -A cgi http://admin:[email protected]/image/jpeg.cgi
sleep 1
done

mutt -s “Motion Detected” [email protected] -a $folder/*.jpeg < /tmp/mailmessage.txt

1 Like

Just an update. Still haven’t figured out why there is such a huge delay between when the doorbell is pressed and the picture is taken and when I get the message. One thing I did do though that seems to “speed” up the process a bit is I have my automation set to send me a text notification of someone at the door, and then a second one for the picture. The text one comes in instantly and the photo about a minute later.