MySensors S_RGB_LIGHT WS2812 ledstrip

Moderator: leecollings

User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

yugoos wrote:
gizmocuz wrote:This is stated in the code (in the remarks)

You need the latest domoticz beta as there have been many changes to the mysensors implementation lately
I missed that line, sorry.

I am running a beta release for mysensors stuff so i can use rgb switches...i am however a bit hesitant to upgrade to latest beta because of some problems with counter values and a corrupt database..

Thanx,
Yuri
you should fix/check your database.

There are no problems with counters, unless you implemented something 'wrong/different' in your sketches.

Stable = beta published as stable, so if you encounter any issues, its best to find them now before we release a new stable
Quality outlives Quantity!
yugoos
Posts: 19
Joined: Tuesday 15 September 2015 21:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3072
Location: Spijkenisse, NL
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by yugoos »

Nothing was changed in my sketches and things were running fine for weeks, but after updating beta (cant remember the version, i think it was the first version with power/energy choise) powerpulsecounter values were devided by thousand and written in the database that way, this was the only change!
I posted my counter problem in http://www.domoticz.com/forum/viewtopic.php?f=6&t=8163

My database is fixed by export/import, temperature and meter tables were corrupt and had to be recreated...not sure what caused corruption...



P.s. We're getting a bit offtopic ...
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

This is outside the OP topic...

Anyway, good it runned for weeks, but it could have been weeks wrong.
See the good discussion about the correct implementation of kwh counters in mysensors.
It means you have to update your sketch, as this is not going to change
Quality outlives Quantity!
TheoL
Posts: 11
Joined: Tuesday 22 September 2015 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.3530
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by TheoL »

yugoos wrote:
gizmocuz wrote:This is stated in the code (in the remarks)

You need the latest domoticz beta as there have been many changes to the mysensors implementation lately
I missed that line, sorry.

I am running a beta release for mysensors stuff so i can use rgb switches...i am however a bit hesitant to upgrade to latest beta because of some problems with counter values and a corrupt database..

Thanx,
Yuri
I tried the example of Gizmocuz as well. And indeed you'll need the latest Beta as it gives me the same result on my production, as your sketch ;-)

I'm waiting for some parts, so that I can make my MySensors ethernet gateway. I want to use that to share it between my production Domoticz and a separat Beta Domoticz version on another Pi.
adamnmcc
Posts: 2
Joined: Saturday 14 November 2015 11:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by adamnmcc »

Hi,

i just implemented this in my living room and have the colour picker and slider working.

What i wondered is if the sketch could be expanded to accept effects like Hyperion? With Christmas coming up i'd like to setup some nice blinking colours or a fire effect.

is this within the realms of possibility?
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

adamnmcc wrote:Hi,

i just implemented this in my living room and have the colour picker and slider working.

What i wondered is if the sketch could be expanded to accept effects like Hyperion? With Christmas coming up i'd like to setup some nice blinking colours or a fire effect.

is this within the realms of possibility?
You can make your own sketch for this (maybe share it *g*), that has 1 normal on/off light switch
then internally you do your magic with the colors if the light switch is on
Quality outlives Quantity!
richardtrip
Posts: 5
Joined: Wednesday 09 September 2015 21:12
Target OS: -
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by richardtrip »

adamnmcc wrote:Hi,

i just implemented this in my living room and have the colour picker and slider working.

What i wondered is if the sketch could be expanded to accept effects like Hyperion? With Christmas coming up i'd like to setup some nice blinking colours or a fire effect.

is this within the realms of possibility?
Check this project: http://forum.mysensors.org/topic/2169/w ... od-light/8
You can enhance it with extra effects and control it with domoticz :-)

Verstuurd vanaf mijn SM-G925F met Tapatalk
adamnmcc
Posts: 2
Joined: Saturday 14 November 2015 11:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by adamnmcc »

Awesome,

thanks for that, i'm sure i can make something out of this. i've got two strips of 51 leds so might take a bit of fiddling.
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by deennoo »

Really great !

Can be cool if the sketch allow a smooth fadding from a color to another to make it less "computer change"
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
franzelare
Posts: 139
Joined: Thursday 19 February 2015 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by franzelare »

I'm currently testing a mysensor node with RGB led attached to it, works fine so for.
through the color picker of domoticz I can change the setting, but I like to update the color based on other inputs on my server
or drive the color through scenes I select for my Hue lighting

any way to send the RGB code through lua script or json?
macieiks
Posts: 36
Joined: Tuesday 07 July 2015 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by macieiks »

Hello,

Is there any way to convert "old version" of the code from 1st page, to the newest MySensors 2.0 API?

Code: Select all

[spoiler]/*
 PROJECT: MySensors / RGB test for Light & Sensor
 PROGRAMMER: AWI/GizMoCuz
 DATE: september 27, 2015/ last update: October 10, 2015
 FILE: AWI_RGB.ino
 LICENSE: Public domain

 Hardware: Nano and MySensors 1.5
    
 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.
*/

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


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

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

#define NODE_ID 254                       // fixed MySensors node id

#define CHILD_ID 0                  // Child Id's

CRGB leds[numPixel];

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

MySensor gw;

MyMessage lastColorStatusMsg(CHILD_ID,V_VAR1);

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

  gw.begin(incomingMessage, NODE_ID, false);      // initialize MySensors
  gw.sendSketchInfo("AWI RGB Light", "1.1");
  gw.present(CHILD_ID, S_RGB_LIGHT);        // present to controller

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

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

void loop() {
  gw.process();                       // wait for incoming messages
}

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);
  gw.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();
}

 
[/spoiler]
Maciek
RPI2 + RFLink + PiFace D2 + Aeon Z-Wave Gen5 + Foscams FI9821P&R2 + MySensors + UPS APC Back-UPS 950VA
RPI2 + RFXtrx433e + Foscams FI9821P + MySensors + UPS APC Back-UPS 950VA
RPIB+ + TP-Link MR3420 + Huawei E173 GarageDomoticz :)
toreandre
Posts: 91
Joined: Tuesday 19 January 2016 12:51
Target OS: -
Domoticz version:
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by toreandre »

macieiks wrote:Hello,

Is there any way to convert "old version" of the code from 1st page, to the newest MySensors 2.0 API?

Maciek
Take a look at this document.
https://docs.google.com/document/d/1NKq ... qf1v763257
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 have just installed on a test system MySensors with USB connection. (Arduino Nano V3.0)
Is it possible to send from Domoticz LED effects (patterns) to this LED WS2812B LED strip with MySensors

Example:
When the doorbell rings I want a white (walking) effect on this LED strip.
When a door is open I want the LED strip to be red and white per LED (pixel)

And more.
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

You can program your mysensor node like you this.
For example , have 4 'mode' switches in the sketch, when the doorbell rings, you activate this switch (and thus the effect)
Quality outlives Quantity!
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 »

Hi gizmocuz,

I understand that this is for you easy to make, but not for me and I think more people it is not. Is it possible that you make a basic sketch with two “mode” switches so that I can understand what happen in this sketch?

If I understand the basic sketch, than I can extend the sketch with my own patterns and switches.

It would be really nice if you , or someone else, can make such a sketch with good comments in the sketch.
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

For an example how to get a switch working, see the 'RelayWithButtonActuator' example
Try extending this to two switches

To get better insight what you can do with MySensors, it is also good to play with the 'MockMySensors' example
Quality outlives Quantity!
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 »

Is there someone who has converted the sketch from gizmocus to MySensors 2.0?

viewtopic.php?t=8039#p57521
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 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.

When I upload this sketch to the Arduino Nano and run it, I see in Domoticz this:
2016-08-16_13-49-22.png
2016-08-16_13-49-22.png (171.93 KiB) Viewed 7469 times
I have made a dimmer switch in Domoticz and I see the “colorwheel”
2016-08-16_13-50-22.png
2016-08-16_13-50-22.png (263.47 KiB) Viewed 7469 times
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();
}
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 »

gizmocuz wrote:You can program your mysensor node like you this.
For example , have 4 'mode' switches in the sketch, when the doorbell rings, you activate this switch (and thus the effect)
Ok, this I understand. I have it working with a I/O board (MCP23S17). I have made two switches in Domoticz and every switch presents a “mode”.

Now I want it to be handled by MySensors OTA and with ONE switch.

I really don’t know where to start because I can’t understand HOW signals from a switch goes Over The Air to my node.

- What kind of switch I have to make?
- How do I program the switch to send commands?

I search in this forum at the MySensors forum but I can’t find an answer to get understand this.
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MySensors S_RGB_LIGHT WS2812 ledstrip

Post by gizmocuz »

its very easy, maybe you are thinking WAY to diffucult

Make a mysensors sketch

Add 4 V_LIGHT in it

in the receive function, handle the lights, and control your real rgb
Quality outlives Quantity!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest