RGB LED strip and json Topic is solved

Post Reply
siklosi
Posts: 34
Joined: Sunday 06 September 2015 10:50
Target OS: Raspberry Pi
Domoticz version:
Location: Belgrade
Contact:

RGB LED strip and json

Post by siklosi » Sunday 06 December 2015 17:39

Hi,
I made mysensors node for RGB strip. It's working great but I would like to set color through json. I can set it off/on and set level, but I don't see where is color (hue or whatever). Here is my script for mysensors

Code: Select all

#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_LED_TV"
#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 TV", 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)));
    }
  }
}
and here is json info from strip

Code: Select all

{
   "ActTime" : 1449416341,
   "ServerTime" : "2015-12-06 16:39:01",
   "Sunrise" : "06:57",
   "Sunset" : "15:57",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "Off, Level: 16 %",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 7,
         "HardwareName" : "MySensors",
         "HardwareType" : "MySensors Gateway USB",
         "HardwareTypeVal" : 41,
         "HaveDimmer" : true,
         "HaveGroupCmd" : false,
         "HaveTimeout" : false,
         "ID" : "00000002",
         "Image" : "Light",
         "IsSubDevice" : false,
         "LastUpdate" : "2015-12-06 16:34:47",
         "Level" : 16,
         "LevelInt" : 16,
         "MaxDimLevel" : 100,
         "Name" : "RGB TV",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Off",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "RGB",
         "SwitchType" : "Dimmer",
         "SwitchTypeVal" : 7,
         "Timers" : "false",
         "Type" : "Lighting Limitless/Applamp",
         "TypeImg" : "dimmer",
         "Unit" : 0,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "354"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by franzelare » Sunday 13 March 2016 14:15

did you already figure out how to do this?

siklosi
Posts: 34
Joined: Sunday 06 September 2015 10:50
Target OS: Raspberry Pi
Domoticz version:
Location: Belgrade
Contact:

Re: RGB LED strip and json

Post by siklosi » Sunday 13 March 2016 14:24

No :(

Sent from my HUAWEI Y560-L01 using Tapatalk

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

Re: RGB LED strip and json

Post by gizmocuz » Sunday 13 March 2016 14:33

Something like

[url]http://IPADDRESS:PORT/json.htm?type=command&param=setcolbrightnessvalue&idx=224&hex=FF00FF&brightness=100&iswhite=false[/url]
Quality outlives Quantity!

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

Re: RGB LED strip and json

Post by gizmocuz » Sunday 13 March 2016 14:34

Quality outlives Quantity!

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by franzelare » Monday 14 March 2016 16:08

The hex value didn't work, I get an error back
I checked the topic and tested a bit, only had to convert the values from HUE lights before I could feed them back in to domoticz, but now I can set the led strip using json commands and a bash script.

only on a synology I get a timeout when I try to directly execute the command
so I have a work around now by calling a bash script from the lua script to change the led strip

siklosi
Posts: 34
Joined: Sunday 06 September 2015 10:50
Target OS: Raspberry Pi
Domoticz version:
Location: Belgrade
Contact:

Re: RGB LED strip and json

Post by siklosi » Monday 14 March 2016 16:15

gizmocuz wrote:Something like

[url]http://IPADDRESS:PORT/json.htm?type=command&param=setcolbrightnessvalue&idx=224&hex=FF00FF&brightness=100&iswhite=false[/url]
Thanks. It's working great.

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by franzelare » Monday 14 March 2016 16:43

you can also add &saturation= to complete the command set

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by franzelare » Tuesday 15 March 2016 23:48

hmmm, when looking into detail, I don't get the same color on the LED strip when I put in the hue/sat/bri as when I use the rgb values in domoticz
but when I send the same values to the hue lamp, the colors stay the same, so there is no color conversion mistake before i put the data in
and the hex command doesn't seem to work
gizmocuz: is the hex command supported in all versions? since my nas is still running an older version..

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

Re: RGB LED strip and json

Post by gizmocuz » Wednesday 16 March 2016 9:18

I think it is supported in the last 300 versions.... for sure from the latest stable version
Maybe i got the command wrong.. do you get an error when you enter the json url in the browser ?
It should work, it converts internally the hex to hue again...
Quality outlives Quantity!

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by franzelare » Wednesday 16 March 2016 12:11

Ah, that's the trick, from a new release that I run on a Pi I can send hex code
but there is a mistake in the hex string send

when I send FF00FF in the hex string, the string recieved by the device is FF00FBrsion
String hexstring = message.getString();
Serial.println(hexstring);

so Blue is not correct al the time due to the string send
like FF000F will end up as FF0011rsion

now I also see why I get the wrong values when I send hue sat and bri to the RGB strip
(this is now in release 3.4834)

Inso80
Posts: 12
Joined: Thursday 17 May 2018 13:28
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: RGB LED strip and json

Post by Inso80 » Tuesday 05 June 2018 17:47

As the last post is around two years old, and it seems the "bug" is not fixed - is something else wrong with "setcolbrightnessvalue"?

No matter if send through browser or Domoticz script, f.e.

Code: Select all

http://192.168.178.200:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=51&hex=000000
results in

Code: Select all

TSF:MSG:READ,0-0-1,s=1,c=1,t=40,pt=0,l=6,sg=0:FFFFFF
only FFFFFF is transmitted fine, every other hex value is somehow converted. Also tried brightness and so on, does not seem to make a difference.

EDIT: as it is all about JSON:

Code: Select all

http://192.168.178.200:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=51&color={"m":3,"t":0,"r":0,"g":0,"b":50,"cw":0,"ww":0}&brightness=100
f.e results in status "ERR" - it is an exact copy of the JSON example on the Domotics wiki

EDIT 2 :

Also, choosing a value from the color table in Domoticz results in false hex value received by the node -.-

kimot
Posts: 55
Joined: Saturday 25 November 2017 18:18
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: RGB LED strip and json

Post by kimot » Friday 15 June 2018 10:39

One question.
How you send this "http" call from MySensors for example radionode ???

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests