Light percentage sensor

Post Reply
Posts: 198
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi
Domoticz version: V3.6028
Location: Greece

Light percentage sensor

Post by korniza » Saturday 03 December 2016 20:51

Looking a way to maximize the data that my cameras are getting, I found a script that can measure the percentage of light that camera can read using the following pyhton script and a virtual percentage sensor.
You have to change/remove username:password on what you have saved on your camera interface for user access.
Also <DEVICEID> is the idx of percentage sensor.

You will also install imagemagick.
The mechanism is to resize image to 1 pixel and measure the percentage of light on this pixel.

credits go here: ... camera-ip/

Code: Select all

import os, sys
import requests
from subprocess import Popen, PIPE

process = Popen(['wget','-O','/home/pi/shot'+'cam'+'.jpg','http://username:password@'+'/image/jpeg.cgi'], stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
process = Popen(["convert /home/pi/shot"+'cam'+".jpg -colorspace hsb -resize 1x1 txt: | grep \",*%)\" | cut -f 6 -d ',' | cut -c -5"], stdout=PIPE, shell=True)
(output, err) = process.communicate()
exit_code = process.wait()
value = str(output).replace('\n','')
url = '<DEVICEID>&nvalue=0&svalue=' + value
r = requests.get(url)
cam_light.png (78.67 KiB) Viewed 494 times
>>>> Google Home <<<<<
SBC: Odroid XU4 * Raspberry Pi2 * banana Pi v1
Peripherals: rfxtrx433E, aeon z-stick gen5, bluetooth dongles
Extended Software packages: Xeoma (video NVR), FHEM (extra home automation software)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest