Send color data to sensors


  • Plugin Developer

    Hi Guys,

    This is one to think of and it would be nice to have input from the users.

    A this moment there is no V_* available (as far as i have understood it) to hold a color string/code. I have seen code passing by sending three vars (VAR_1 to VAR_3) with percentages.

    I'm getting questions if it is able to use the color picker to send colors to nodes. So here is the question:
    I can send one of the following three vars to nodes (without the ()-characters of course):
    RGB as hex (000000 to FFFFFF),
    RGB as int (0-255,0-255,0-255),
    or HSL as floats (0-360, 0-100,0-100).

    It would not matter which V_TYPE you would be using, but the data containing it does. Because i would like to support it, what would be the optimal data format you guys prefer?


  • Admin

    Maybe a candidate for a new data / variable type?


  • Plugin Developer

    @tbowmo
    That would be handy for creators, PiDome does not care about the V_* types, only the datatype it contains 😉 which is defined in the server's device editor.


  • Contest Winner

    @John

    nice idea

    an (unsigned) long would allow us to bit shift the three values easily and allow an extra byte for something else (e.g led ID, state, etc). We could add a function to decode in the library.

    I worked on (a while back) a concept of "broadcasting" a number that each node could use to show a 'system status' with one RGB led (i.e. alarm armed/unarmed, doors locked, unlocked). I like the idea of having a "transmit to all listening" function.


  • Plugin Developer

    @BulldogLowell
    That would of course also be possible, By using this there would then be some information needed for users for the bit shifting code on the MySensor node side. Because when implemented it would become a global message for MySensors nodes.

    P.S. wouldn't an int be enough?

    [EDIT]Scrap my P.S.[/EDIT]


  • Contest Winner

    @John

    an int array, you mean?

    can you fit your RGB 3bytes into arduino's 16bit int?


  • Plugin Developer

    @BulldogLowell
    Was thinking 32bit, sorry....


  • Contest Winner

    yup, you gotta think small!


  • Plugin Developer

    @BulldogLowell
    Yup, i'm spoiled.....

    I will take this option in consideration. It does depends on what users would prefer the most.


  • Admin

    In the next version RGB values it will be transmitted as a 3 byte binary value over the air.
    On the serial line it will probably be split into decimal json like: {red:<0-255>;green:<0-255>;blue:<0-255>}.

    If you want to add this to 1.4.1 i would suggest sending data as RGB hex string (to make survive over serial interface).


  • Plugin Developer

    Then to make sure there is as less data as possible over the air then this would mean to send data as: "000000" to "ffffff" (so no "#" char)

    This also has my personal preference, but want to know how the community would like it to handle it on the node side.


  • Admin

    Using something like:

    string hexstring = "FF3Fa0";
    int number = (int) strtol( &hexstring, NULL, 16);
    int r = number >> 16;
    int g = number >> 8 & 0xFF;
    int b = number & 0xFF;
    

  • Plugin Developer

    @hek
    Understood, i meant how they want to receive the data. @BulldogLowell would like to receive a long instead of an hex string (if i understood it correctly).

    That's the part i'm interested in.


  • Contest Winner

    @John

    The 3byte message works here.

    Like I mentioned, a little function to put a bow in it.



  • I agree on the 6 character hex text value. Who will implement this when in 1.4.2?
    I have build a RGB neopixel led strip actuator and I would like to control the colours with V_RGB.
    Thanks in advance. 😉


  • Plugin Developer

    @arendst
    Together with an user this is implemented in the current PiDome version available on the build server. He has posted a little tutorial on how to do this. So if you are a PiDome user: http://forum.pidome.org/viewtopic.php?id=58

    It is only available in the serial version for testing purposes.

    If all goes well, it will be extended to the MQTT version.

    [EDIT]It sends hex values which can be extracted as posted above[/EDIT]



  • @John
    Thanks for the response. I use Domoticz as controller which just started to support MySensors. It works great for V_Light and V_Dimmer but lacks RGB color support as the MySensors library lacks color support too.

    @hek
    Why not update the MySensors library with S_Color and V_RGB. That way Domoticz and other controllers can support color natively.


  • Admin

    @arendst said:

    Why not update the MySensors library with S_Color and V_RGB. That way Domoticz and other controllers can support color natively.

    Wanted to add this in the next major release. But if this drags out (time-wise) I might add it to the next minor as well.



  • Hi guys,
    Any news about that ?
    Is it now possible to use domoticz's rgb module to control an rgb led strip through an arduino mysensor node ?
    Thanks for your help.



  • up !
    Could anyone help me to configure domoticz & mysensors in order to control analog RGB led strip ?



  • @davy39
    I just made RGB controller for domoticz. So if it's not to late...

    
    #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)));
        }
      }
    }
    
    


  • @davy39 said:

    up !
    Could anyone help me to configure domoticz & mysensors in order to control analog RGB led strip ?

    Is this option working?
    Or perhaps a RGBW strip...


Log in to reply
 

Suggested Topics

18
Online

11.2k
Users

11.1k
Topics

112.5k
Posts