MySensors S_RGB_LIGHT WS2812 ledstrip

Moderator: leecollings

Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by Ritmeester »

I’m sorry, but if I don’t understand or see it, than I get questions. Maybe it is simple, if you know HOW to make it, …. Yes than it is very simple. :-)

I was really happy that I made a sketch with “wires” and that this is working with two (or more) mode’s. I have a little bit of programing experience.

I will see if I can figure out what is: 4 V_LIGHT
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by tlpeter »

He means that you need to program 4 different "lights"
Read this page and see why it uses these names:

https://www.mysensors.org/download/serial_api_20

It defines which type to use like light is for light and V_TEMP orcourse for temperature.
Domoticz than knows which type of sensor is used.
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by Ritmeester »

Thanks for your answers. But I still do not understand what kind of switch I have to make in my sketch.

This switch I have made:
2016-08-17_14-01-09.png
2016-08-17_14-01-09.png (22.2 KiB) Viewed 6604 times
The mode buttons must change the pattern in the sketch.

How my “signals” from this Selector Switch will arrive in my node and the node is switching to a different pattern. (Mode)
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by Ritmeester »

Ok , I will go to a wired connection for my question to use the Selector Switch for my situation. Unfortunately it seems not be possible to send a self-chosen command (variable) to an Mysensors node to handle this. With Wires it works very well.

Can I “combine” two or more switches in a JSON command?

Example:
I have two switches with IDX 50 and 51. In one command I want to switch them off like this:

Code: Select all

/json.htm?type=command&param=switchlight&idx=50&switchcmd=Off 
But then for two switches, or more in the same rule. Or can I make some group of switches to turn them off by one command?
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by Flopp »

Ritmeester wrote:I’m trying to get the sketch from gizmocuz to work with MySensors 2.0. I have made the necessary conversion from MySensors 1.5 to 2.0. It compiles without errors.

If I run the sketch the “SendColor2AllLEDs” works. And then it stops because I don’t get any information from Domoticz to this Node. So, Domoticz is not sending commands, or it is not receiving commands.
Maybe (pretty possible) that I have overlooked something but I don’t know what.

Sketch:

Code: Select all

// PROJECT: MySensors / RGB test for Light & Sensor
// PROGRAMMER: AWI/GizMoCuz
// DATE: september 27, 2015/ last update: October 10, 2015
// LAST UPDATE: August 16, 2016 by Ritmeester
// FILE: AWI_RGB.ino
// LICENSE: Public domain

// Hardware: Nano and MySensors 2.0

// Special:
//  uses Fastled library with NeoPixel (great & fast RBG/HSV universal library)       https://github.com/FastLED/FastLED

// Remarks:
//  Fixed node-id
//  Added option to request/apply last light state from gateway

// Domoticz typicals - 2015 10 10:
//  - Domoticz is using HUE values internally, there might be a slight difference then using direct RGB colors.


// Enable debug prints to serial monitor
// #define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE

#include <MySensors.h>
#include <SPI.h>
#include <FastLED.h>

#define LED_PIN 4                                            // Pin to connect WS2812B (strip)
#define NUM_LEDS 10
#define COLOR_ORDER GRB                                      // It's GRB for WS2812B
#define LED_TYPE WS2812B                                     // What kind of strip are you using (APA102, WS2801 or WS@2812B

#define NODE_ID 254                       // fixed MySensors node id
#define CHILD_ID 0                        // Child Id's

CRGB leds[NUM_LEDS];

char actRGBvalue[] = "000000";                // Current RGB value
uint16_t actRGBbrightness = 0xFF ;            // Controller Brightness
int actRGBonoff = 0;                          // OnOff flag

MyMessage lastColorStatusMsg(CHILD_ID, V_VAR1);

void presentation()  {
  sendSketchInfo("AWI RGB Light", "1.1");
  present(CHILD_ID, S_RGB_LIGHT);        // present to controller
}

void setup() {
  LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2812B - initialize led strip

  // Flash the "hello" color sequence: R, G, B, black.
  colorBars();

  //Request the last stored colors settings
  request(CHILD_ID, V_VAR1);
}

void receive(const MyMessage &message) {
}

void loop() {

}

void colorBars()
{
  SendColor2AllLEDs( CRGB::Red );   FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Green ); FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Blue );  FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Black ); FastLED.show(); delay(500);
}

void SendColor2AllLEDs(const CRGB lcolor)
{
  for (int i = 0 ; i < NUM_LEDS ; i++) {
    leds[i] = lcolor;
  }
}

void SendLastColorStatus()
{
  String cStatus = actRGBvalue + String("&") + String(actRGBbrightness) + String("&") + String(actRGBonoff);
  send(lastColorStatusMsg.set(cStatus.c_str()));
}

String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length() - 1;
  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void incomingMessage(const MyMessage &message) {
  if (message.type == V_RGB) {            // check for RGB type
    actRGBonoff = 1;
    strcpy(actRGBvalue, message.getString());    // get the payload
    SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
    SendLastColorStatus();
  }
  else if (message.type == V_DIMMER) {           // if DIMMER type, adjust brightness
    actRGBonoff = 1;
    actRGBbrightness = map(message.getLong(), 0, 100, 0, 255);
    FastLED.setBrightness( actRGBbrightness );
    SendLastColorStatus();
  }
  else if (message.type == V_STATUS) {           // if on/off type, toggle brightness
    actRGBonoff = message.getInt();
    FastLED.setBrightness((actRGBonoff == 1) ? actRGBbrightness : 0);
    SendLastColorStatus();
  }
  else if (message.type == V_VAR1) {          // color status
    String szMessage = message.getString();
    strcpy(actRGBvalue, getValue(szMessage, '&', 0).c_str());
    actRGBbrightness = atoi(getValue(szMessage, '&', 1).c_str());
    actRGBonoff = atoi(getValue(szMessage, '&', 2).c_str());
    SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
    FastLED.setBrightness((actRGBonoff == 1) ? actRGBbrightness : 0);
  }
  FastLED.show();
}
I am using AWI and Gimoz example on 1.5.1 and it is working fine.
I only changed type to Dimmer and then clicked on the three cubes to see color wheel, as soon as I selected a color it changed on my LEDs.
I don't know how 2.x is working but don't you need gw.process( or equal) in LOOP?
NiklasO
Posts: 67
Joined: Friday 16 August 2013 18:34
Target OS: -
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by NiklasO »

I don't know how 2.x is working but don't you need gw.process( or equal) in LOOP?
Nope. It will process automatically. :)

I am in the process to put up my ws2812b. Is there a sketch out there that works with 2.x or do I need to convert the older script?
Thanks!
NiklasO
Posts: 67
Joined: Friday 16 August 2013 18:34
Target OS: -
Domoticz version:
Location: Stockholm, Sweden
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by NiklasO »

Sketch for 2.x, working here. Add the new device, change to dimmer.

Code: Select all

/*
 PROJECT: MySensors / RGB test for Light & Sensor
 PROGRAMMER: AWI/GizMoCuz
 DATE: september 27, 2015/ last update: May 3, 2017
 FILE: AWI_RGB.ino
 LICENSE: Public domain

 Hardware: Nano and MySensors 2.x
    
 Special:
  uses Fastled library with NeoPixel (great & fast RBG/HSV universal library)       https://github.com/FastLED/FastLED
 
 Remarks:
  Fixed node-id
  Added option to request/apply last light state from gateway
  Converted to work on 2.x
  
 Domoticz typicals - 2015 10 10:
  - Domoticz is using HUE values internally, there might be a slight difference then using direct RGB colors.
*/

#define MY_RADIO_NRF24
#define MY_REPEATER_FEATURE
#define MY_DEBUG

#include <MySensors.h>
#include <SPI.h>
#include <FastLED.h>


const int stripPin = 4 ;                  // pin where 2812 LED strip is connected

const int numPixel = 25 ;                  // set to number of pixels

#define CHILD_ID 0                  // Child id

CRGB leds[numPixel];

char actRGBvalue[] = "000000";               // Current RGB value
uint16_t actRGBbrightness = 0xFF ;         // Controller Brightness 
int actRGBonoff=0;                        // OnOff flag

MyMessage lastColorStatusMsg(CHILD_ID,V_VAR1);

void presentation()  
{ 
  sendSketchInfo("AWI RGB Light", "1.2");
  present(CHILD_ID, S_RGB_LIGHT);        // present to controller
}

void before() {
  FastLED.addLeds<NEOPIXEL, stripPin >(leds, numPixel); // initialize led strip

  // Flash the "hello" color sequence: R, G, B, black. 
  colorBars();
}

void setup() {
  //Request the last stored colors settings
  request(CHILD_ID, V_VAR1);
}

void loop() {

}

void colorBars()
{
  SendColor2AllLEDs( CRGB::Red );   FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Green ); FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Blue );  FastLED.show(); delay(500);
  SendColor2AllLEDs( CRGB::Black ); FastLED.show(); delay(500);
} 

void SendColor2AllLEDs(const CRGB lcolor)
{
  for(int i = 0 ; i < numPixel ; i++) {
    leds[i] = lcolor;
  }
}

void SendLastColorStatus()
{
  String cStatus=actRGBvalue+String("&")+String(actRGBbrightness)+String("&")+String(actRGBonoff);
  send(lastColorStatusMsg.set(cStatus.c_str()));
}

String getValue(String data, char separator, int index)
{
 int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;
  for(int i=0; i<=maxIndex && found<=index; i++){
  if(data.charAt(i)==separator || i==maxIndex){
  found++;
  strIndex[0] = strIndex[1]+1;
  strIndex[1] = (i == maxIndex) ? i+1 : i;
  }
 }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void receive(const MyMessage &message) {
  if (message.type == V_RGB) {            // check for RGB type
    actRGBonoff=1;
    strcpy(actRGBvalue, message.getString());    // get the payload
    SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
    SendLastColorStatus();
  }
  else if (message.type == V_DIMMER) {           // if DIMMER type, adjust brightness
    actRGBonoff=1;
    actRGBbrightness = map(message.getLong(), 0, 100, 0, 255);
    FastLED.setBrightness( actRGBbrightness );
    SendLastColorStatus();
  }
  else if (message.type == V_STATUS) {           // if on/off type, toggle brightness
    actRGBonoff = message.getInt();
    FastLED.setBrightness((actRGBonoff == 1)?actRGBbrightness:0);
    SendLastColorStatus();
  }
  else if (message.type==V_VAR1) {            // color status
    String szMessage=message.getString();
    strcpy(actRGBvalue, getValue(szMessage,'&',0).c_str());
    actRGBbrightness=atoi(getValue(szMessage,'&',1).c_str());
    actRGBonoff=atoi(getValue(szMessage,'&',2).c_str());
    SendColor2AllLEDs(strtol(actRGBvalue, NULL, 16));
    FastLED.setBrightness((actRGBonoff == 1)?actRGBbrightness:0);
  }
  FastLED.show();
}
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by sincze »

Anything I should take in considiration to modify this great example to RGBWW strip ??
So I see normal values travelling to Mysensors like 000000 for RGB and 000000FF for white.

I am currently working from:

Code: Select all

// Modified strandtest sketch to support also RGBW strips like SK6812 based:
// http://www.szledcolor.com/download/SK6812RGBW.pdf
// Should be used with Adafruit NeoPixel version 1.0.3
// Hacked by G. Knauf 2015-12-06
RGB is working however, still have some problems with the White Part. (it simply switches all leds off)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by sincze »

I'll answer my own question :D ;-)

If the received color starts with '#'. It is white. Just modify that in the mysensor code and it works fine.

Code: Select all

 if (received_message.startsWith("#")) 
    {
      color =  WHITE_LED;
    }
    else
    {
      color = strtol(message.getString(), NULL, 16);
    }
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by Flopp »

This has been working for a long time now, but today I noticed one small thing, it is not problem.

If the LED is ON and I restart my node, the LED will turn on after restart but in DZ it shows that the LED is OFF.
I think it be OFF when the node is presenting the Child.
mickaelr30
Posts: 1
Joined: Monday 21 September 2015 22:01
Target OS: Windows
Domoticz version:
Location: France
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by mickaelr30 »

Hello,
since the update of domoticz in version 4.10157 I have a problem
I set the lighting of the leds every night at 18:30 and level at 25% in domoticz the order is well given but the brightness remains at 0 I am forced by imperihome to increase it.
do you have this problem?
thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests