Wednesday, January 03, 2018

Network camera as motion sensor for lights


Here's a guide to use an old network cctv feed as a motion sensor for lights.

https://motion-project.github.io/


Here's what we need

1. URL for jpg feed from the network camera

The URL varies for different brands and models.

Example URL: http:///cgi-bin/net_jpeg.cgi?ch=0 


2. Raspberry pi with domoticz (already integrated with lights, e.g. hue) 

On the raspberry pi, download Motion

$ sudo apt-get motion

Modify the /etc/motion/motion.conf file (Refer to the motion documentation)

I removed the following from the motion.conf create a new thread file for each video source

comment out in /etc/motion/motion.conf

; videodevice /dev/video0
; target_dir /var/lib/motion
; stream_port 8081

I also changed the webcontrol_port to 8000 as 8080 conflicts with the default domoticz port.

;webcontrol_port 8080
webcontrol_port 8000


I added a thread file for each video source

thread /etc/motion/camera.conf


The following is an example of a tread file called camera.conf. You need to create a new thread file for each camera

netcam_userpass : user:password
text_left Camera
netcam_url http://netcam_ip/cgi-bin/net_jpeg.cgi?ch=0
target_dir /mnt/nas/camera
stream_port 8001
on_event_start /usr/bin/curl -s "http://domoticz_ip:8080/json.htm?type=command&param=switchlight&idxswitch_id=&switchcmd=On"
on_event_end /usr/bin/curl -s "http://domoticz_ip:8080/json.htm?type=command&param=switchlight&idx=switch_id&switchcmd=Off"


The variables you need to replace are:

user:password: if needed
netcam_ip and URL
domoticz_ip: IP address of the rasberry pi running domoticz
switch_id is the switch id of your light that you want.
Make sure that the steam_port is not already used on the pi and for each camera, to change the stream port.


Optional

If you want to have a bit more smarts for the motion sensor rather than having to keep turning on and off the motion process at night, create a Motion detection dummy virtual device on domoticz and replace that lightswitch id with the motion sensor.

It is possible to use the apple homekit/homebridge to add the virtual motion sensor to apple home and created an automation to set it for only turn on the light at night and when someone is home.



No comments:

Splitting the home network

Who wouldn't want to separate the traffic at home for security reasons. The more common ones include wireless guest and wireless users. ...