Page 1 of 1
LED Strip Python with colorpicker
Posted: Tuesday 14 May 2019 0:56
by bm33
Hi
I can not find a solution in this forum.
I connected the led strip to raspberry pi by SPI.
Controls work via the Python script (RPi-LPD8806).
Code: Select all
#!/usr/bin/python
from bootstrap import *
led.fill(Color(255,0,0),0,57)
led.update()
The above script works.
I do not know how to make a choice of color with colorpicker.
Re: LED Strip Python with colorpicker
Posted: Saturday 08 June 2019 1:58
by bm33
Hi
Below is a working script.
The script is execute about 8 seconds. Can this time be shortened?
Code: Select all
#!/usr/bin/python
import json
import urllib2
import requests
import ast
import base64
# Settings for the domoticz server
domoticzserver="192.168.1.2:8080"
domoticzusername = "pi"
domoticzpassword = "raspi"
domoticzpasscode = ""
base64string = base64.encodestring('%s:%s'% (domoticzusername, domoticzpassword)).replace('\n', '')
domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&rid=37'
def domoticzrequest (url):
request = urllib2.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
return response.read()
def domoticzstatus ():
json_object = json.loads(domoticzrequest(domoticzurl))
status = 1
return status
def show_data(type):
data = json.loads(domoticzrequest(domoticzurl))
show = data["result"][0][type]
return show
#json_object = json.loads(domoticzrequest(domoticzurl))
#print(json_object)
#print(show_data("Color"))
#print(show_data("Level"))
color= show_data("Color")
print " JSON - Color: ", color
colour_data = ast.literal_eval(color)
red = int(colour_data["r"])
green = int(colour_data["g"])
blue = int(colour_data["b"])
print "RED: ",red
print "GREEN: ",green
print "BLUE: ",blue
level_data = show_data("Level")
level = int(level_data)
print "LEVEL: ",level
redl = int((red /100) * level)
greenl = int((green /100) * level)
bluel = int((blue /100) * level)
print redl
print greenl
print bluel
# send to led strip
from bootstrap import *
led.fill(Color(redl,bluel,greenl),0,10)
led.update()
Re: LED Strip Python with colorpicker
Posted: Saturday 08 June 2019 10:37
by JanJaap
Hi,
Alternatlively you can also write a plugin in python. The api allows you to create any device in domoticz with any control you want (documentation on that part of api ain't brilliant but with some experiments you'll get there). You can check out the code of the zigbee2mqtt plugin, there are examples of colorlights thereI
zigbee2mqtt github
Rewards Jan-Jaap