Intruder Alert Notification with Pictures from MJPEG Stream

Was testing without sudo only. Got it working :slight_smile: thanks

1 Like

Is there any way to show the animated GIF in the HASS web GUI? I’d like to be able to go there and see the last GIF rather than have it emailed. I’m running Blue Iris and have a duplicate exterior camera with a hot spot near my front door. I have alerts working based on this but would like to be able to view this from the GUI rather than getting it sent via email or pushbullet.

how do i do this in hassio?

1 Like

Wondering if anyone could help with this issue.

I have this working a D-Link 2132L, but can not get the Picture to snap correctly with a Foscam FI9853EP. The issue seems to be that the Foscam creates multiple stills each time the command is run, and produces the following;

[39] 28842
[40] 28843
[41] 28844
[37]   Done                    sudo wget -q -O /home/homeassistant/.homeassistant/front2.jpg http://192.168.1.113:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2
[38]   Done                    usr=admin

This is a command I am running to produce the image;

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

When I paste the http link into my browser, it correctly displays a still image, so I’m a little stuck.

Any ideas?

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