7h30n3
(The One)
February 24, 2017, 7:19am
1
I would be cool if there would be a built-in feature which enables you to easily save images of a attached webcam at local storage or in the cloud (e.g. owncloud, nextcloud) when motion is detected…
I know there is camera.local_file, but with saving the image only when necessary you could reduce read/write access to local/external storage.
mikenolet
(Mikenolet)
February 28, 2017, 6:15pm
2
I have something like this already setup via script. If you are interested let me know and I can shed more details as it is a little involved.
7h30n3
(The One)
February 28, 2017, 6:17pm
3
Sure, I’m highly interested
mikenolet
(Mikenolet)
February 28, 2017, 6:18pm
4
what type of camera do you have?
7h30n3
(The One)
February 28, 2017, 6:20pm
5
I’m using an USB camera attached to the rPi running Hass.
camera:
- platform: ffmpeg
input: -i /dev/video0
mikenolet
(Mikenolet)
February 28, 2017, 6:48pm
6
Was hoping you were going to say foscam or amcrest. I leverage the camera api to handle motion and poll the camera using a command line sensor to detect if the camera has detected motion. This may not work in your case if the USB camera does not have a means of detecting motion.
7h30n3
(The One)
February 28, 2017, 7:20pm
7
I have a motion sensor (PIR) right underneath the camera. In case I can also use:
mikenolet
(Mikenolet)
February 28, 2017, 7:29pm
8
Here is the script I use:
I grab the images from the camera these commands:
snapshot: wget “http://192.168.1.73:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=admin&pwd=pwd ” -O {{filename}}
fix_snapshot: convert {{filename}} {{filename}}
The cameras are PTZ so I move them to grab other images with the ptz commands.
Then use them in this script:
################
## HOME ALARM ##
################
alarm:
alias: 'Run alarm when motion is detected'
sequence:
- delay:
seconds: 1
# FAMILY ROOM - POOL
- service: shell_command.snapshot
data:
filename: /home/hass/.homeassistant/snaps/snapshot.jpg
- service: shell_command.fix_snapshot
data:
filename: /home/hass/.homeassistant/snaps/snapshot.jpg
- delay:
seconds: 1
# GARAGE
- service: shell_command.snapshot1
data:
filename: /home/hass/.homeassistant/snaps/snapshot1.jpg
- service: shell_command.fix_snapshot1
data:
filename: /home/hass/.homeassistant/snaps/snapshot1.jpg
- delay:
seconds: 1
#FRONT DOOR
- service: shell_command.snapshot2
data:
filename: /home/hass/.homeassistant/snaps/snapshot2.jpg
- service: shell_command.fix_snapshot2
data:
filename: /home/hass/.homeassistant/snaps/snapshot2.jpg
- delay:
seconds: 1
#KITCHEN
- service: shell_command.snapshot3
data:
filename: /home/hass/.homeassistant/snaps/snapshot3.jpg
- service: shell_command.fix_snapshot3
data:
filename: /home/hass/.homeassistant/snaps/snapshot3.jpg
- delay:
seconds: 1
#FAMILY ROOM - FAMILY ROOM
- service: shell_command.familyroom_ptz_familyroom
- delay:
seconds: 2
- service: shell_command.snapshot4
data:
filename: /home/hass/.homeassistant/snaps/snapshot4.jpg
- service: shell_command.fix_snapshot4
data:
filename: /home/hass/.homeassistant/snaps/snapshot4.jpg
- delay:
seconds: 1
# FRONT DOOR - FOYER
- service: shell_command.frontroom_ptz_foyer
- delay:
seconds: 2
- service: shell_command.snapshot5
data:
filename: /home/hass/.homeassistant/snaps/snapshot5.jpg
- service: shell_command.fix_snapshot5
data:
filename: /home/hass/.homeassistant/snaps/snapshot5.jpg
- delay:
seconds: 1
#KITCHEN - FAMILY ROOM
- service: shell_command.kitchen_ptz_family
- delay:
seconds: 2
- service: shell_command.snapshot6
data:
filename: /home/hass/.homeassistant/snaps/snapshot6.jpg
- service: shell_command.fix_snapshot6
data:
filename: /home/hass/.homeassistant/snaps/snapshot6.jpg
- delay:
seconds: 1
#FAMILY ROOM - UPSTAIRS
- service: shell_command.familyroom_ptz_upstairs
- delay:
seconds: 2
- service: shell_command.snapshot7
data:
filename: /home/hass/.homeassistant/snaps/snapshot7.jpg
- service: shell_command.fix_snapshot7
data:
filename: /home/hass/.homeassistant/snaps/snapshot7.jpg
- delay:
seconds: 1
#FRONT DOOR - DINING ROOM
- service: shell_command.frontroom_ptz_dining
- delay:
seconds: 2
- service: shell_command.snapshot8
data:
filename: /home/hass/.homeassistant/snaps/snapshot8.jpg
- service: shell_command.fix_snapshot8
data:
filename: /home/hass/.homeassistant/snaps/snapshot8.jpg
- delay:
seconds: 1
#KITCHEN - PATIO
- service: shell_command.kitchen_ptz_patio
- delay:
seconds: 2
- service: shell_command.snapshot9
data:
filename: /home/hass/.homeassistant/snaps/snapshot9.jpg
- service: shell_command.fix_snapshot9
data:
filename: /home/hass/.homeassistant/snaps/snapshot9.jpg
- delay:
seconds: 1
- service: notify.emailer
data:
title: 'Intruder alert'
message: 'Motion detected at Home'
data:
images:
- /home/hass/.homeassistant/snaps/snapshot.jpg
- /home/hass/.homeassistant/snaps/snapshot1.jpg
- /home/hass/.homeassistant/snaps/snapshot2.jpg
- /home/hass/.homeassistant/snaps/snapshot3.jpg
- /home/hass/.homeassistant/snaps/snapshot4.jpg
- /home/hass/.homeassistant/snaps/snapshot5.jpg
- /home/hass/.homeassistant/snaps/snapshot6.jpg
- /home/hass/.homeassistant/snaps/snapshot7.jpg
1 Like
7h30n3
(The One)
February 28, 2017, 8:08pm
9
Thanks for the code, although it’s a little hard to read without proper formatting
I think I can use some of your ideas.
Anyway, what does?
convert {{filename}} {{filename}}
I know the command can convert from one file type into another, but there are now file endings.
So do you just compress them?
mikenolet
(Mikenolet)
March 6, 2017, 6:45pm
10
Have a look here: https://partofthething.com/thoughts/?p=1037 This is where I got the idea. I modified the code to include PTZ defined points.
7h30n3
(The One)
March 6, 2017, 7:21pm
11
I have solved it as follows:
configuration.yaml
shell_command:
take_snapshot_webcam: 'bash /home/pi/.homeassistant/scripts/take_snapshot_webcam.sh'
transfer_snapshot: 'scp -r -p /tmp/webcam_images user@server:/var/media/backup'
take_snapshot_webcam.sh
#!/bin/bash
outdir=/tmp/webcam_images
if [[ ! -d "$outdir" ]]; then
mkdir -p "$outdir"
fi
ffmpeg -f v4l2 -video_size 1280x720 -i /dev/video0 -vframes 5 -vf fps=1 -strftime 1 "$outdir"/%Y-%m-%d_%H-%M-%S.jpg
script.yaml
webcam_snapshot:
alias: Take Webcam Snapshots
sequence:
- service: shell_command.take_snapshot_webcam
- service: shell_command.transfer_snapshot
automation.yaml
- alias: Take Webcam Snapshots
trigger:
platform: state
entity_id: binary_sensor.pir_hall
to: 'on'
action:
- service: homeassistant.turn_on
data:
entity_id: script.webcam_snapshot
I hope this will help others, too.
4 Likes
pembo
March 6, 2017, 7:29pm
12
I’ve done similar also but used sendmail to email the grabs
as follows. Get the list of files:
files=`ls /scripts/alerts/* | sed ':a;N;$!ba;s/\n/ -a /g'`
then send the email with the files
sendEmail .......... -a $files > /scripts/email.txt
Is this really the best way?
If homeassistant has access to all my cameras, why do I need an external script to grab an image. Seems like unnecessary duplication
1 Like
7h30n3
(The One)
March 20, 2017, 9:47pm
14
You are free to make a new feature request or if you already have a solution even a pull request
naren8642
(Naren Salem)
April 29, 2017, 3:31pm
15
So to clarify, @7h30n3 are you stating that there is no current way within HASS to get a current snapshot from the camera entity? Which I think was the question that @brucealdridge asked.
7h30n3
(The One)
April 29, 2017, 5:43pm
16
Yes, it seems that there is no built-in way to easily capture images or videos.
7h30n3
(The One)
October 10, 2017, 5:21pm
17
During some research I discovered that the foscam.component uses the snapPicture2 CGI-Command from the Foscam API, as it can be seen here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/camera/foscam.py#L65
Where is the snapped picture stored and is it possible to save it in case it’s needed?
pembo
October 10, 2017, 7:38pm
18
Picking this back up, I’ve tweaked this, and now the images go via my telegram bot, with buttons on the message sent to request an additional set of images if needed!
This works much better than email!
jevy
October 28, 2017, 2:07pm
19
arsaboo
(Arsaboo)
October 28, 2017, 2:12pm
20
@pvizeli indicated some time back that @fabaff was working on a snapshot service, but there are no updates on it. See this PR by @tchellomello for some context.
1 Like