RGB Led strip / My sensors / Python

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
peerkersezuuker
Posts: 70
Joined: Monday 14 December 2015 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Mierlo
Contact:

RGB Led strip / My sensors / Python

Post by peerkersezuuker »

Hello,
After a while tinkering with Domoticz including Z-Wave and RFLink i thought it would be time for something challenging.
So on to My Sensors.
I build a RGB Led Strip controller with the help from http://www.engineerathome.com/elektroni ... troller/11 and http://www.jerome-bernard.com/blog/2013 ... n-arduino/
I used this sketch :
Spoiler: show
#include <MySensor.h>
#include <SPI.h>

#define RED_PIN 3
#define GREEN_PIN 5
#define BLUE_PIN 6

#define NODE_ID 2
#define CHILD_ID 0
#define SKETCH_NAME "RGB_STRIP"
#define SKETCH_VERSION "1.0.0"
#define NODE_REPEAT false

MySensor gw;

long RGB_values[3] = {0, 0, 0};
float dimmer;

void setup() {


pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);

gw.begin(incomingMessage, NODE_ID, NODE_REPEAT);
gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
gw.present(CHILD_ID, S_RGB_LIGHT, "RGB Strip", false);
gw.request(CHILD_ID, V_RGB);
}

void loop() {
gw.process();
}

void incomingMessage(const MyMessage &message) {

if (message.type == V_RGB) {

String hexstring = message.getString();
long number = (long) strtol( &hexstring[0], NULL, 16);
RGB_values[0] = number >> 16;
RGB_values[1] = number >> 8 & 0xFF;
RGB_values[2] = number & 0xFF;
}
if (message.type == V_DIMMER) {
dimmer = message.getInt();
analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
}

if (message.type == V_LIGHT) {
if (message.getInt() == 0) {
digitalWrite(RED_PIN, 0);
digitalWrite(GREEN_PIN, 0);
digitalWrite(BLUE_PIN, 0);

}
if (message.getInt() == 1) {
analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
}
}
}
http://forum.mysensors.org/topic/816/se ... sensors/21

After connecting and configuring in Domoticz i got a dimmable RGB switch with a color picker.
Not happy with the functions it provided, I was reading in to RGB control from Domoticz i understood that this is in re-design and may be available in March.
viewtopic.php?f=6&t=10458&p=76600#p76600
So for as i understood, domoticz is only sending hue information and no RGB.
Then I created a dummy switch, which triggers a script when on, and in the script i check if the switch is set to off to end the script, so i created a light show from my RGB strip.

Code: Select all

#!/usr/bin/python

from random import randint
import json
import urllib2
import time
off = True

while (off):
    color = randint(1,800)
    brightness = randint(50,100)
    urlrgb = "http://domoticzurl:port/json.htm?type=command&param=setcolbrightnessvalue&idx=178&hue=%d&brightness=%d&iswhite=false" % (color, brightness)
    urlswitch = "http://domoticzurl:port/json.htm?type=devices&rid=179"
    data = json.load(urllib2.urlopen(urlrgb))
    data = json.load(urllib2.urlopen(urlswitch))
    time.sleep(1)
    if (data["result"][0]["Status"] == "Off"):
        urlswitch = "http://domoticzurl:port/json.htm?type=command&param=switchlight&idx=178&switchcmd=Off"
        data = json.load(urllib2.urlopen(urlswitch))
		off = False
	
I randomly select a number for the hue value, and for the brightness value, and it is working like a charm.
I don't know the range of the hue value's so i picked 1 through 800, and it seems that I get a lot of colors.

To do : add sound detection, and react on that.

Any feedback is appreciated.
Regard's Peer
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: RGB Led strip / My sensors / Python

Post by Derik »

Great option!!! .....
seems to me what I am looking/waiting for ...
Just a pity that my vacation is over ... So it takes a while before I can test / build, unfortunately.

Is there perhaps an option possible to build the RGBW color in it ..
Then you have even better light towards the philips hue. :-)
https://www.youtube.com/watch?v=NeFfVtdk6gw


Or perhaps te ws2811 strip/light...
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
peerkersezuuker
Posts: 70
Joined: Monday 14 December 2015 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Mierlo
Contact:

Re: RGB Led strip / My sensors / Python

Post by peerkersezuuker »

Maybe in the next version when i get the clearing for buying a RGBW strip :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest