Intruder Alert Notification with Pictures from MJPEG Stream

You’ll have to quote the URL, so:

wget -q -O /home/homeassistant/.homeassistant/front2.jpg 'http://192.168.1.113:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=[USERNAME]&pwd=[PASSWORD]'

@b10m Why would I need to do that? It isn’t required with the D-Link camera.

The issue, as explained, is that the Foscam is producing multiple images per time the command is run, and HA doesn’t seem to know how to grab just one.

You need to do that, because the ampersand sign is interpreted as ‘send the process to the background’. So, what you’re really doing is:

The first command is now lacking the usr and pwd values (so probably fails to download due to a lack of permissions). The second and third command are just setting variables, which will work, but are fairly pointless.

By quoting the URL, you’re quoting the ampersands, telling the shell “hey, the stuff following this quotation mark until the next one is pretty much something I’d like to pass in, so don’t interpret it as shell commands, mkay?” and the shell will do so.

Looking at your pasted output, it looks like you somehow manage to start 41 processes (instead of 1 wget process). It also calls cmd=snapPicture2, which is different from your wget example later (not sure if it’s a typo, I don’t know the device).

@b10m Thanks for the explaination, unfortunately this does not help though.

As mentioned in both posts, the Foscam camera is taking multiple stills each tie the command is run, and HA doesn’t seem to be able to take just 1 of those.

As also mentioned, the same code (adjusted for the D-Link camera) works perfectly and produces an image, and is saved. No apersand is needed, and the code works.

Each time I run the command for the Foscam, the numbers change in numerical order, up to 60, making me think that these are still captured each second. It goes back to 1,2,3 after 60.

Could you share youre HA code for this?

so here is my issue:

I don’t have HA code to create amimated gifs but I do have python code. The use cronsjob to run the python script every hr. The script collects images off a ftp server and remove duplicates and then stitch the files into a animated gif. I then get HA to point to this animated gif.

Hello, I have followed your tutorial, it works well and it sends me the photos, but in the background in the folder snapshots the system does not stop taking pictures every 10 seconds and I do not know how to correct it. any solution? thaks!

Hi @Dawi.Es, if it’s the VLC command you are using are you including –run-time 5? This is the parameter that stops the command after 5 seconds.

Does the same thing happen if you run that command in the command line directly (rather than via a Home Assistant shell_command)?

Hi!

is the same code that you used, by command line I am doing well, in HA it is not going well. I have to stop the motion service to stop taking pictures.

Sorry for answering late, I’ve been traveling

Very cool! I stumbled upon this while trying to set this up myself. I was trying to see if the html5 notifications supported animated gifs. I currently have mine doing this well with 1 static image, but an animation would be great. Sometimes the static image misses the person.

Does anyone know if the HTML5 Push notifications support animated gifs or mp4??

Hi @RobDYI . I’m trying to do this using imageio as well. I’m trying to run it in appdaemon, but the library fails to install. How do you have yours set up?

here is the relevant python script to combine images, i find the size increases exponentially with # of images. I run this every 10 mins and it checks to see if 3 or more images are available to combine before combining.

from PIL import Image
from glob import glob
from hashlib import md5
import sys, shutil, os, argparse
import imageio as io
from PIL import ImageFile
import filecmp
import fnmatch
ImageFile.LOAD_TRUNCATED_IMAGES = True

c1 =  len([f for f in os.listdir('/Users/xxx/ram/ftp/ch1')
                if os.path.isfile(os.path.join('/Users/xxx/ram/ftp/ch1', f))])

if c1 > 3:
    os.chdir('/Users/xxx/ram/ftp/ch1')  
    with io.get_writer('/Users/xxx/ram/ftp/work/CAM1.gif', mode='I', duration=1.0) as writer:
        for filename1 in file_names1:
            image = io.imread(filename1)
            writer.append_data(image)
    writer.close()
    filelist1 = [ f for f in os.listdir("/Users/xxx/ram/ftp/ch1") if f.endswith(".gif") ]
    for f in filelist1:
        os.remove(f)
1 Like

I’m very interested in this. I’ve just been sending still images to pushbullet for a while and am generally happy. I’m running HA in a python VENV on ubuntu 16.04.

Are they any dependicies I need to install for this to work? Any chance I could get you to provide a simple step by step?

Thanks!

I can help but it takes a little python programming. I would start with using the command prompt and creating a simple script like the one above. Put a couple of images into a directory and try to get a python script to run to combine them. If the above script fails to run properly, simply install the dependency that is causing the error like

pip install imageio

This thread has been super useful to me. I have a cheap Xiaomi camera with the Dafang Hacks on it, so it only has a RTSP stream. So adjusted the setup here slightly to work for my needs, not sure if its the right way, but it works, kinda :smiley:

script.yaml

gif_picture_script:
  alias: gif Picture
  sequence:
  - data:
      entity_id: camera.have_i_got_mail
      filename: /home/homeassistant/.homeassistant/www/tmp/frontdoor1.png
    service: camera.snapshot
  - data:
      entity_id: camera.have_i_got_mail
      filename: /home/homeassistant/.homeassistant/www/tmp/frontdoor2.png
    service: camera.snapshot
  - data:
      entity_id: camera.have_i_got_mail
      filename: /home/homeassistant/.homeassistant/www/tmp/frontdoor3.png
    service: camera.snapshot
  - service: shell_command.snapshot_letterbox_gif
  - delay: '00:00:15'
  - data:
      title: You got Animated Mail!!
      message: is it anything inresting ?
      data:
        file: /home/homeassistant/.homeassistant/www/tmp/a.gif
    service: notify.pushbullet

configuration.yaml

shell_command:
  snapshot_letterbox_gif: /home/homeassistant/.homeassistant/www/tmp/gif.sh

gif.sh

rm -rf a.gif
#!/bin/bash
convert -loop 0 -delay 100 /home/homeassistant/.homeassistant/www/tmp/frontdoor1.png /home/homeassistant/.homeassistant/www/tmp/frontdoor2.png /home/homeassistant/.homeassistant/www/tmp/frontdoor3.png /home/homeassistant/.homeassistant/www/tmp/a.gif

On testing, it seems to work, the snapshots are a little bit apart from each other, don’t think there is a super easy way to grab a still from a RTSP stream, but I also don’t know much :wink: but its only on my letterbox, for a stupid notification when I get mail, so nothing important, just for fun :smiley:

3 Likes

I got this working kinda, I can run the .sh script manually, but when I run is via HA I get the following error. I’m sure its a permissions kind of thing

Fri Aug 17 2018 18:14:07 GMT-0400 (Eastern Daylight Time)

Error running command: `/home/homeassistant/.homeassistant/www/tmp/gif.sh`, return code: 1

NoneType: None


Lastly, pushbullet does send the gif (after I manually created the gif via the script), but it just looks like a picture. Do animated Gifs work in iOS pushbullet?

Thanks, very easy to follow and get set up, so far

Same error I got, sorry, should have posted about it. You need to change the owner of the script to your home assistant user. I am using Hassbian, so it

sudo chown homeassistant:homeassistant gif.sh

I am pretty sure it was that, if you do a ls -l in the home assistant directory, will tell you the owner and group of the files.

Edit: they should work in Pushbullet, I have only tried in testing, but it seems to work for me. Its only three frames thrown together, but yeah it displays fine in the iOS app.

So i got some mail today, and this where the automation is setup, and it seems the animated gif only plays in the preview in pushbullet. When you open it, it doesn’t play, and every time i go to download it, its get to 100% and crashes out the app. Honestly, for me, it doesn’t matter at the moment, as it just a stupid notification for when I get mail.

I tried to make a gif from jpgs running HASSIO with:

convert -delay 100 -loop 0 /config/www/dafang_1/dafang_1_snapshot_door_open_1.jpg /config/www/dafang_1/dafang_1_snapshot_door_open_2.jpg /config/www/dafang_1/dafang_1_snapshot_door_open_3.jpg /config/www/dafang_1/dafang_1_snapshot_door_open_4.jpg /config/www/dafang_1/dafang_1_snapshot_door_open_5.jpg /config/www/dafang_1/saved/dafang_1_snapshot_door_open.gif

When I run this in SSH I get:

convert: command not found

Is there a way to get this working and get a gif in HASSIO?