Light percentage sensor

Moderator: leecollings

Post Reply
korniza
Posts: 157
Joined: Thursday 27 August 2015 18:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6028
Location: Greece
Contact:

Light percentage sensor

Post by korniza »

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: https://matdomotique.wordpress.com/2016 ... 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:[email protected]'+'/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 = 'http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=<DEVICEID>&nvalue=0&svalue=' + value
r = requests.get(url)
Attachments
cam_light.png
cam_light.png (78.67 KiB) Viewed 779 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