LED Strip Python with colorpicker

Python and python framework

Moderator: leecollings

Post Reply
bm33
Posts: 2
Joined: Tuesday 14 May 2019 0:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

LED Strip Python with colorpicker

Post 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.
Image

Image

I do not know how to make a choice of color with colorpicker.
bm33
Posts: 2
Joined: Tuesday 14 May 2019 0:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LED Strip Python with colorpicker

Post 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()
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

Re: LED Strip Python with colorpicker

Post 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
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest