Creating controls for McLighting project

Hello!

I’ve started playing with OpenHAB for a few days, taking on the learning curve for someone new to the platform, and so far got MQTT setup, HABPanel that can control an ESP_Easy relay, with the state returning its’ value - As the final setup will include wireless switches that will control a designated relay directly so require the dashboard updating straight away, anyway…

I have McLighting on a D1 mini ESP8266, presently I can turn it on and off with state feedback (toggling remotely), and adjust the brightness but no feedback.

So I’m asking for help/assistance with a couple of points;

  • Updating the slider if the brightness changes from the returning state
  • Mapping the 0-100 to 0-255 required for McLighting
  • Sending colour from the HSB colour picker, and if the value changes, can this be updated?

The McLighting commands are here; https://github.com/toblum/McLighting/wiki/WebSocket-API
Brightness data is sent as : %0 off to full brightness %255
Colour is sent as hex preceded by #

The returning data is, for instance if I send ‘=all’ to turn on LEDs, it’ll return; “OK =all”.
If I send a colour such as “#334455”, it’ll return back to me; “OK #334455

My current items

Switch Mc1 {mqtt=">[mq:McLighting01/in:command:ON:=all],>[mq:McLighting01/in:command:OFF:=off],<[mq:McLighting01/out:state:ON:OK =all],<[mq:McLighting01/out:state:OFF:OK =off"}
Switch Rel1 {mqtt=">[mq:/ESP_Easy/gpio/0:command:ON:1],>[mq:/ESP_Easy/gpio/0:command:OFF:0],<[mq:/ESP_Easy/Light/Switch:state:ON:1],<[mq:/ESP_Easy/Light/Switch:state:OFF:0"}

Dimmer Mc1Dim {mqtt=">[mq:McLighting01/in:command:*:%${command}]"}

String MQTT_data {mqtt="<[mq:McLighting01/out:state:default]"}

Color Mc1Col

MQTT_data is a dummy on HABPanel so I can see what data McLighting returns via MQTT

Any help or pointers for any would be much appreciated!

Hello Welcome to openHAB

For the feedback of brightness change you Dimmer item:

Dimmer Mc1Dim {mqtt=">[mq:McLighting01/in:command:*:%${command}], <[mq:McLighting01/in:state:default]", autoupdate="false"}

This is assuming that the McLighting publishes on the topic McLighting01/in qhen the brightness is changed
You can check what topic the light publishes on by using a MQTT monitor like MQTTfx and subscribe to the topic # (All topic) and change the brightness by hand.

For the scaling from 0-100 to 0-255 it’s a bit more complicated:
Create a javascript file called scale100-255.js in the transform folder
The file will contain:

(function(i) {
    var value = parseInt(i);
    return Math.floor((value * 255) / 100);
})(input)

And change the item as:

Dimmer Mc1Dim {mqtt=">[mq:McLighting01/in:command:*:JS(scale100-255.js)], <[mq:McLighting01/in:state:default]", autoupdate="false"}

For the scaling back from 0-255 to 0-100:
Create a javascript file called scale255-100.js in the transform folder
The file will contain:

(function(i) {
    var value = parseInt(i);
    return Math.floor((value * 100) / 255);
})(input)

And change the item as:

Dimmer Mc1Dim {mqtt=">[mq:McLighting01/in:command:*:JS(scale100-255.js)], <[mq:McLighting01/in:state:JS(scale255-100.js)]", autoupdate="false"}

I haven’t read about the colour yet, but that should get you started

Good luck

Hello Vincent,

Thank you very much for the help, I’ve made the changes, and cursed for a while because I’d missed the closing bracket on the state out section, with just the error MQTT message failed to go on… Anyway the dimmer now updates successfully from external control.

I have been using MQTTbox to keep track on what sends what, so monitoring the to and fro’ing between OpenHAB and the sensors/relays I’ll be adding in.

Had to make a couple of changes because of the brightness command requiring a % at the start, and the returning data including the OK at the start of the string, so for anyone having a play;

.items

Dimmer Mc1Dim {mqtt=">[mq:McLighting01/in:command:*:JS(scale100-255.js)], <[mq:McLighting01/out:state:JS(scale255-100.js)", autoupdate="false"}

scale100-255.js

(function(i) {
    var value = parseInt(i);
    return "%"+Math.floor((value * 255) / 100);
})(input)

scale255-100.js

(function(i) {
    var value = i.slice(4);
    return Math.floor((value * 100) / 255);
})(input)

Hopefully I’ll try and tackle the colour picker through JS!

PS - Install Javascript Transformation through PaperUI for anyone trying it

Well done.
According to the speed at which you picked that up, I am sure that the colour picker won’t be a problem. You could use the colour picker HabPanel linked to a proxy item and use that proxy item to update the command mqtt item with a js script.

I’ve had success with the colour picker, although I’m noticing some problems, and I’m not sure if it’s a setting/bug that is playing havoc;
The McLighting code requires a hex value to change the colour, and as noted the HSL value needs to be converted, so this will convert the colour picker value to a RGB, then to hex before sending out over MQTT. Some colours work fine but quite often the HSL value in the log is different from what is being used. This results in mostly whiter colours unless Lightness is turned down, resulting in darker colours on screen.

For instance, setting colorpicker to H178, S100, L50 results in #ffffff being sent over MQTT but Cyan is displayed in the colour picker;

Command sent: Mc1Col=178,100,100
Updating Mc1Col state from 178,72,78 to 178,100,100
hsl(178, 100%, 50%)

All the attemps are displayed in the browser JS log;

openhab1

mqtt.items

Color Mc1Col "McLighting" {mqtt=">[mq:McLighting01/in:command:*:JS(colour.js)]"}

colour.js

(function (i) {
    var res = i.split(",");

    //var out = hsl2rgb((res[0]),(100),(50));
    var out = hslToRgb((res[0]), (res[1]), (res[2]));
    out2 = rgbToHex((out.r), (out.g), (out.b))
    return out2;
    

})(input)


function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}


function hslToRgb(hue, saturation, lightness) {

    saturation = saturation / 100;
    lightness = lightness / 100;

    // based on algorithm from http://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
    if (hue == undefined) {
        return [0, 0, 0];
    }

    var chroma = (1 - Math.abs((2 * lightness) - 1)) * saturation;
    var huePrime = hue / 60;
    var secondComponent = chroma * (1 - Math.abs((huePrime % 2) - 1));

    huePrime = Math.floor(huePrime);
    var red;
    var green;
    var blue;

    if (huePrime === 0) {
        red = chroma;
        green = secondComponent;
        blue = 0;
    } else if (huePrime === 1) {
        red = secondComponent;
        green = chroma;
        blue = 0;
    } else if (huePrime === 2) {
        red = 0;
        green = chroma;
        blue = secondComponent;
    } else if (huePrime === 3) {
        red = 0;
        green = secondComponent;
        blue = chroma;
    } else if (huePrime === 4) {
        red = secondComponent;
        green = 0;
        blue = chroma;
    } else if (huePrime === 5) {
        red = chroma;
        green = 0;
        blue = secondComponent;
    }

    var lightnessAdjustment = lightness - (chroma / 2);
    red += lightnessAdjustment;
    green += lightnessAdjustment;
    blue += lightnessAdjustment;

    var r, g, b;
    r = (Math.round(red * 255));
    g = (Math.round(green * 255));
    b = (Math.round(blue * 255));
    return {
        r: r,
        g: g,
        b: b
    };
};

Well done,
but i think that the HSL should be HSV.

so here comes my .JS transform file:

(function (i) {
    var res = i.split(",");

    var out = HSVtoRGB((res[0]), (res[1]), (res[2]));
    out2 = rgbToHex((out.r), (out.g), (out.b))
    return out2;
    

})(input)


function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}



//https://stackoverflow.com/questions/17242144/javascript-convert-hsb-hsv-color-to-rgb-accurately
function HSVtoRGB(h, s, v) {
    var r, g, b, i, f, p, q, t;
    if (arguments.length === 1) {
        s = h.s, v = h.v, h = h.h;
    }
	
	h = h / 360;
    s = s / 100;
	v = v / 100;
	
    i = Math.floor(h * 6);
    f = h * 6 - i;
    p = v * (1 - s);
    q = v * (1 - f * s);
    t = v * (1 - (1 - f) * s);
    switch (i % 6) {
        case 0: r = v, g = t, b = p; break;
        case 1: r = q, g = v, b = p; break;
        case 2: r = p, g = v, b = t; break;
        case 3: r = p, g = q, b = v; break;
        case 4: r = t, g = p, b = v; break;
        case 5: r = v, g = p, b = q; break;
    }
    return {
        r: Math.round(r * 255),
        g: Math.round(g * 255),
        b: Math.round(b * 255)
    };
};

with above cfg all works great with 4 items and 4 elements

Switch Clrlight01power “Temple light” (LivingDining, gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command:ON:/0],>[mqtt:CLRLIGHT01/in:command:OFF:=off],<[mqtt:CLRLIGHT01/out:state:ON:OK /0],<[mqtt:CLRLIGHT01/out:state:OFF:OK =off]"}
Dimmer CLRlight01Dim “Temple light Brightness [%d]” (LivingDining, gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command::JS(scale100-255.js)], <[mqtt:CLRLIGHT01/out:state:JS(scale255-100.js)]", autoupdate=“false”}
Dimmer CLRlight01Speed “Temple light Speed [%.0f]” (LivingDining, gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command:
:JS(speedscale100-255.js)], <[mqtt:CLRLIGHT01/out:state:JS(speedscale255-100.js)]", autoupdate=“false”}
Color Clrlight01 “Temple light” (LivingDining, gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command::JS(colour.js)]"}
Number Coloreffects “Temple Effects” (LivingDining, gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command:
:MAP(ColoreffectsJSON.map)]"}

Sitemap:
Colorpicker item=Clrlight01 label=“Temple Color” icon=“colorwheel”
Selection item=Coloreffects
Slider item=CLRlight01Dim
Switch item=Clrlight01power mappings=[ ‘OFF’=‘off’,‘ON’=‘Cont…’ ]
Slider item=CLRlight01Speed
Webview url=“http://192.168.1.25/index2.htm” height=57 visibility=[Clrlight01power!=“OFF”]

only following issue

Openhab Default elements (@ color item) slider , switch & colorpicker-setpoint along does not works .
Only colorpicker gives correct hex color code

It gives mqtt massage like : CLRLIGHT01/in NANNaNNaN

Do these examples work?

Please find the working demo . I have set up 4 different light with 5 th one dummy . 5th is parent and 4 are child .

few rule :
strong text

can I see your configuration files?

Set up consisite of
. item file
.sitemap file
and few Map & JS scripts
coloreeffectjson.map
colour.js
scale transformation - 100-255.js & 255-100.js

Items:
Switch Clrlight01power “Temple light” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:CLRLIGHT01/in:command:ON:/0],>[mqtt:CLRLIGHT01/in:command:OFF:=off],<[mqtt:CLRLIGHT01/out:state:ON:OK /0],<[mqtt:CLRLIGHT01/out:state:OFF:OK =off]"}
Dimmer CLRlight01Dim “Temple light Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:CLRLIGHT01/in:command::JS(scale100-255.js)], <[mqtt:CLRLIGHT01/out:state:JS(scale255-100.js)]"}
Dimmer CLRlight01Speed “Temple light Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:CLRLIGHT01/in:command:
:JS(speedscale100-255.js)], <[mqtt:CLRLIGHT01/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color Clrlight01 “Temple light color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:CLRLIGHT01/in:command::JS(colour.js)]"}
Number Coloreffects “Temple Effects” (gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number Colorname “Temple Color” (gLedstrip) {mqtt=">[mqtt:CLRLIGHT01/in:command:*:MAP(ColoreffectsJSON.map)]"}

//GXRINGa

Switch GXRINGpower “Ganesh” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:GXRING/in:command:ON:/0],>[mqtt:GXRING/in:command:OFF:=off],<[mqtt:GXRING/out:state:ON:OK /0],<[mqtt:GXRING/out:state:OFF:OK =off]"}

Dimmer GXRINGDim “Ganesh Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:GXRING/in:command:*:JS(scale100-255.js)], <[mqtt:GXRING/out:state:JS(scale255-100.js)]"}

Dimmer GXRINGSpeed “Ganesh Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:GXRING/in:command:*:JS(speedscale100-255.js)], <[mqtt:GXRING/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}

Color GXRING “Ganesh color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:GXRING/in:command:*:JS(colour.js)]"}

Number GXRINGeffects “Ganesh Effect” (gLedstrip) {mqtt=">[mqtt:GXRING/in:command:*:MAP(ColoreffectsJSON.map)]"}

Number GXRINGname “Ganesh Col” (gLedstrip) {mqtt=">[mqtt:GXRING/in:command:*:MAP(ColoreffectsJSON.map)]"}

// XRING01
Switch XRING01power “Ganesh One” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING01/in:command:ON:/0],>[mqtt:XRING01/in:command:OFF:=off],<[mqtt:XRING01/out:state:ON:OK /0],<[mqtt:XRING01/out:state:OFF:OK =off]"}
Dimmer XRING01Dim “Ganesh One Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING01/in:command::JS(scale100-255.js)], <[mqtt:XRING01/out:state:JS(scale255-100.js)]"}
Dimmer XRING01Speed “Ganesh One Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING01/in:command:
:JS(speedscale100-255.js)], <[mqtt:XRING01/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color XRING01 “Ganesh One color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING01/in:command::JS(colour.js)]"}
Number XRING01effects “Ganesh One Effect” (gLedstrip) {mqtt=">[mqtt:XRING01/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number XRING01name “Ganesh One Color” (gLedstrip) {mqtt=">[mqtt:XRING01/in:command:*:MAP(ColoreffectsJSON.map)]"}

//XRING02
Switch XRING02power “Ganesh two” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING02/in:command:ON:/0],>[mqtt:XRING02/in:command:OFF:=off],<[mqtt:XRING02/out:state:ON:OK /0],<[mqtt:XRING02/out:state:OFF:OK =off]"}
Dimmer XRING02Dim “Ganesh two Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING02/in:command::JS(scale100-255.js)], <[mqtt:XRING02/out:state:JS(scale255-100.js)]"}
Dimmer XRING02Speed “Ganesh two Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING02/in:command:
:JS(speedscale100-255.js)], <[mqtt:XRING02/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color XRING02 “Ganesh two color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING02/in:command::JS(colour.js)]"}
Number XRING02effects “Ganesh two Effect” (gLedstrip) {mqtt=">[mqtt:XRING02/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number XRING02name “Ganesh two Color” (gLedstrip) {mqtt=">[mqtt:XRING02/in:command:*:MAP(ColoreffectsJSON.map)]"}

//XRING03
Switch XRING03power “Ganesh three” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING03/in:command:ON:/0],>[mqtt:XRING03/in:command:OFF:=off],<[mqtt:XRING03/out:state:ON:OK /0],<[mqtt:XRING03/out:state:OFF:OK =off]"}
Dimmer XRING03Dim “Ganesh three Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING03/in:command::JS(scale100-255.js)], <[mqtt:XRING03/out:state:JS(scale255-100.js)]"}
Dimmer XRING03Speed “Ganesh three Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING03/in:command:
:JS(speedscale100-255.js)], <[mqtt:XRING03/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color XRING03 “Ganesh three color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING03/in:command::JS(colour.js)]"}
Number XRING03effects “Ganesh three Effect” (gLedstrip) {mqtt=">[mqtt:XRING03/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number XRING03name “Ganesh three Color” (gLedstrip) {mqtt=">[mqtt:XRING03/in:command:*:MAP(ColoreffectsJSON.map)]"}

//XRING04
Switch XRING04power “Ganesh four” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING04/in:command:ON:/0],>[mqtt:XRING04/in:command:OFF:=off],<[mqtt:XRING04/out:state:ON:OK /0],<[mqtt:XRING04/out:state:OFF:OK =off]"}
Dimmer XRING04Dim “Ganesh four Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING04/in:command::JS(scale100-255.js)], <[mqtt:XRING04/out:state:JS(scale255-100.js)]"}
Dimmer XRING04Speed “Ganesh four Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING04/in:command:
:JS(speedscale100-255.js)], <[mqtt:XRING04/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color XRING04 “Ganesh four color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XRING04/in:command::JS(colour.js)]"}
Number XRING04effects “Ganesh four Effects” (gLedstrip) {mqtt=">[mqtt:XRING04/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number XRING04name “Ganesh four Color” (gLedstrip) {mqtt=">[mqtt:XRING04/in:command:*:MAP(ColoreffectsJSON.map)]"}

//XSTRIP01

Switch XSTRIP01power “Ganesh line” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XSTRIP01/in:command:ON:/0],>[mqtt:XSTRIP01/in:command:OFF:=off],<[mqtt:XSTRIP01/out:state:ON:OK /0],<[mqtt:XSTRIP01/out:state:OFF:OK =off]"}
Dimmer XSTRIP01Dim “Ganesh line Brightness [%d]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XSTRIP01/in:command::JS(scale100-255.js)], <[mqtt:XSTRIP01/out:state:JS(scale255-100.js)]"}
Dimmer XSTRIP01Speed “Ganesh line Speed [%.0f]” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XSTRIP01/in:command:
:JS(speedscale100-255.js)], <[mqtt:XSTRIP01/out:state:JS(speedscale255-100.js)]", autoupdate=“true”}
Color XSTRIP01 “Ganesh line color” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XSTRIP01/in:command::JS(colour.js)]"}
Number XSTRIP01effects “Ganesh line Effects” (gLedstrip) [“Lighting”] {mqtt=">[mqtt:XSTRIP01/in:command:
:MAP(ColoreffectsJSON.map)]"}
Number XSTRIP01name “Ganesh line Color” (gLedstrip) {mqtt=">[mqtt:XSTRIP01/in:command:*:MAP(ColoreffectsJSON.map)]"}

Sitemap:

sitemap Ganesh label=“Ganesh My Home” {
Frame {
Text item=Date label=“Now Date & Time”
}

Frame { 
   Text label="Temple" icon=hindutemple {
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=Clrlight01 label="Temple Color" icon="colorwheel"
		 Selection item=Coloreffects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=Colorname mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=CLRlight01Dim 
         Switch item=Clrlight01power mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=CLRlight01Speed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    }
	}

	Frame { 
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=GXRING icon="colorwheel"
		 Selection item=GXRINGeffects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=GXRINGname mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=GXRINGDim 
         Switch item=GXRINGpower mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=GXRINGSpeed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    }
	
	Text label="Ganapti One" icon=hindutemple {
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=XRING01  icon="colorwheel"
		 Selection item=XRING01effects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=XRING01name mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=XRING01Dim 
         Switch item=XRING01power mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=XRING01Speed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    }
	Text label="Ganapti Two" icon=hindutemple {
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=XRING02 icon="colorwheel"
		 Selection item=XRING02effects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=XRING02name mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=XRING02Dim 
         Switch item=XRING02power mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=XRING02Speed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    }
	Text label="Ganapti Three" icon=hindutemple {
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=XRING03  icon="colorwheel"
		 Selection item=XRING03effects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=XRING03name mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=XRING03Dim 
         Switch item=XRING03power mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=XRING03Speed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    }
	Text label="Ganapti Four" icon=hindutemple {
       // Default item=LivingDining_Ledstrip label="Living & Dining Room"
         
         Colorpicker item=XRING04  icon="colorwheel"
		 Selection item=XRING04effects mappings=[201='TV' ,3='Static',4='Blink',5='Breath',6='ColorWipe',7='ColorWipeInverse',8='ColorWipeReverse',9='ColorWipeReverseInverse',10='ColorWipeRandom',11='RandomColor',12='SingleDynamic',13='MultiDynamic',14='Rainbow',15='RainbowCycle',16='Scan',17='DualScan',18='Fade',19='TheaterChase',20='TheaterChaseRainbow',21='RunningLights',22='Twinkle',23='TwinkleRandom',24='TwinkleFade',25='TwinkleFadeRandom',26='Sparkle',27='FlashSparkle',28='HyperSparkle',29='Strobe',30='StrobeRainbow',31='MultiStrobe',32='BlinkRainbow',33='ChaseWhite',34='ChaseColor',35='ChaseRandom',36='ChaseRainbow',37='ChaseFlash',38='ChaseFlashRandom',39='ChaseRainbowWhite',40='ChaseBlackout',41='ChaseBlackoutRainbow',42='ColorSweepRandom',43='RunningColor',44='RunningRedBlue',45='RunningRandom',46='LarsonScanner',47='Comet',48='Fireworks',49='FireworksRandom',50='MerryChristmas',51='FireFlicker',52='FireFlicker(soft)',53='FireFlicker(intense)',54='CircusCombustus',55='Halloween',56='BicolorChase',57='TricolorChase',58='ICU' ]
		 Selection item=XRING04name mappings=[ 60='WHITE',61='SILVER',62='GRAY',63='BLACK',64='RED',65='MAROON',66='YELLOW',67='OLIVE',68='LIME',69='GREEN',70='AQUA',71='TEAL',72='BLUE',73='NAVY',74='FUCHSIA',75='PURPLE' ]
         Slider item=XRING04Dim 
         Switch item=XRING04power mappings=[ 'OFF'='off','ON'='Cont..' ]
         Slider item=XRING04Speed
         //Webview url="http://192.168.1.25/index2.htm" height=57 visibility=[Clrlight01power!="=off"]
    
	}

}

rules:

//colorlight rule

rule “colorserver restart”
when
Time cron " 0 0/30 * 1/1 * ? *"
then
sendHttpGetRequest(“http://192.168.1.41:80/restart”)
sendHttpGetRequest(“http://192.168.1.42:80/restart”)
sendHttpGetRequest(“http://192.168.1.43:80/restart”)
sendHttpGetRequest(“http://192.168.1.44:80/restart”)
sendHttpGetRequest(“http://192.168.1.45:80/restart”)
end

rule PublishOnGXRINGChangeOnly
when
Item GXRING changed
/* Item GXRINGpower changed or
Item GXRINGDim changed or
Item GXRINGSpeed changed or
Item GXRINGname changed or
Item GXRINGeffects changed*/
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“JS”, “colour.js”, GXRING.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“JS”, “colour.js”, GXRING.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“JS”, “colour.js”, GXRING.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“JS”, “colour.js”, GXRING.state.toString))
postUpdate(XRING01, GXRING.state.toString)
postUpdate(XRING02, GXRING.state.toString)
postUpdate(XRING03, GXRING.state.toString)
postUpdate(XRING04, GXRING.state.toString)
end
//transform(“JS”, “colour.js”, GXRING)
//transform(“MAP”, “ColoreffectsJSON.map”, GXRINGpower.state.toString)

rule PublishOnGXRINGpowerChangeOnly
when
Item GXRINGpower changed
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGpower.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGpower.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGpower.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGpower.state.toString))
postUpdate(XRING01power, GXRINGpower.state.toString)
postUpdate(XRING02power, GXRINGpower.state.toString)
postUpdate(XRING03power, GXRINGpower.state.toString)
postUpdate(XRING04power, GXRINGpower.state.toString)
end

rule PublishOnGXRINGDimChangeOnly
when
Item GXRINGDim changed
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“JS”, “scale100-255.js”, GXRINGDim.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“JS”, “scale100-255.js”, GXRINGDim.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“JS”, “scale100-255.js”, GXRINGDim.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“JS”, “scale100-255.js”, GXRINGDim.state.toString))
postUpdate(XRING01Dim, GXRINGDim.state.toString)
postUpdate(XRING02Dim, GXRINGDim.state.toString)
postUpdate(XRING03Dim, GXRINGDim.state.toString)
postUpdate(XRING04Dim, GXRINGDim.state.toString)
end

rule PublishOnGXRINGSpeedChangeOnly
when
Item GXRINGSpeed changed
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“JS”, “speedscale100-255.js”, GXRINGSpeed.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“JS”, “speedscale100-255.js”, GXRINGSpeed.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“JS”, “speedscale100-255.js”, GXRINGSpeed.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“JS”, “speedscale100-255.js”, GXRINGSpeed.state.toString))
postUpdate(XRING01Speed, GXRINGSpeed.state.toString)
postUpdate(XRING02Speed, GXRINGSpeed.state.toString)
postUpdate(XRING03Speed, GXRINGSpeed.state.toString)
postUpdate(XRING04Speed, GXRINGSpeed.state.toString)
end

rule PublishOnGXRINGNameChangeOnly
when
Item GXRINGname changed
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGname.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGname.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGname.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGname.state.toString))
postUpdate(XRING01name, GXRINGname.state.toString)
postUpdate(XRING02name, GXRINGname.state.toString)
postUpdate(XRING03name, GXRINGname.state.toString)
postUpdate(XRING04name, GXRINGname.state.toString)
end

rule PublishOnGXRINGeffectChangeOnly
when
Item GXRINGeffects changed
then
Thread::sleep(100)
publish(“mqtt”,“XRING01/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGeffects.state.toString))
publish(“mqtt”,“XRING02/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGeffects.state.toString))
publish(“mqtt”,“XRING03/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGeffects.state.toString))
publish(“mqtt”,“XRING04/in”, transform(“MAP”, “ColoreffectsJSON.map”, GXRINGeffects.state.toString))
postUpdate(XRING01effects, GXRINGeffects.state.toString)
postUpdate(XRING02effects, GXRINGeffects.state.toString)
postUpdate(XRING03effects, GXRINGeffects.state.toString)
postUpdate(XRING04effects, GXRINGeffects.state.toString)
end

coloreffectJason.map

1==off
2==all
OFF==off
ON=/0
3=/0
4=/1
5=/2
6=/3
7=/4
8=/5
9=/6
10=/7
11=/8
12=/9
13=/10
14=/11
15=/12
16=/13
17=/14
18=/15
19=/16
20=/17
21=/18
22=/19
23=/20
24=/21
25=/22
26=/23
27=/24
28=/25
29=/26
30=/27
31=/28
32=/29
33=/30
34=/31
35=/32
36=/33
37=/34
38=/35
39=/36
40=/37
41=/38
42=/39
43=/40
44=/41
45=/42
46=/43
47=/44
48=/45
49=/46
50=/47
51=/48
52=/49
53=/50
54=/51
55=/52
56=/53
57=/54
58=/55
159=/56
160=/57
161=/58
162=/59
163=/60
201==tv
60=#FFFFFF
61=#C0C0C0
62=#808080
63=#000000
64=#FF0000
65=#800000
66=#FFFF00
67=#808000
68=#00FF00
69=#008000
70=#00FFFF
71=#008080
72=#0000FF
73=#000080
74=#FF00FF
75=#800080

Colour.js

(function (i) {
var res = i.split(",");

var out = HSVtoRGB((res[0]), (res[1]), (res[2]));
out2 = rgbToHex((out.r), (out.g), (out.b))
return out2;

})(input)

function componentToHex© {
var hex = c.toString(16);
return hex.length == 1 ? “0” + hex : hex;
}

function rgbToHex(r, g, b) {
return “#” + componentToHex® + componentToHex(g) + componentToHex(b);
}

//https://stackoverflow.com/questions/17242144/javascript-convert-hsb-hsv-color-to-rgb-accurately
function HSVtoRGB(h, s, v) {
var r, g, b, i, f, p, q, t;
if (arguments.length === 1) {
s = h.s, v = h.v, h = h.h;
}

h = h / 360;
s = s / 100;
v = v / 100;

i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
    case 0: r = v, g = t, b = p; break;
    case 1: r = q, g = v, b = p; break;
    case 2: r = p, g = v, b = t; break;
    case 3: r = p, g = q, b = v; break;
    case 4: r = t, g = p, b = v; break;
    case 5: r = v, g = p, b = q; break;
}
return {
    r: Math.round(r * 255),
    g: Math.round(g * 255),
    b: Math.round(b * 255)
};

};

DimScale100-255.js

##scale100-255.js for tranforming value from 0 -255 scale to 0 -100 scale for maclightining project

(function(i) {
var value = parseInt(i);
return “%”+Math.floor((value * 255) / 100);
})(input)

Speedscale100to255.js

(function(i) {
var value = parseInt(i);
return “?”+Math.floor((value * 255) / 100);
})(input)

Speedscale255-100.js
(function(i) {
var value = i.slice(4);
return “?”+Math.floor((value * 100) / 255);
})(input)

Dimscale255-100.js

(function(i) {
var value = i.slice(4);
return +Math.floor((value * 100) / 255);
})(input)

1 Like

Wow. I will try. and be sure to write the results. many thanks.

I get in the log: 2018-10-02 23:54:09.161 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

but everything works.

and the strange thing is that, when I move the dimmer speed, the dimmer Brightness moves too.

2018-10-03 00:06:07.802 [ome.event.ItemCommandEvent] - Item ‘Clrlight01Dim’ received command 33

2018-10-03 00:06:07.813 [vent.ItemStateChangedEvent] - Clrlight01Dim changed from 91.0 to 33

2018-10-03 00:06:07.884 [vent.ItemStateChangedEvent] - Clrlight01Dim changed from 33 to 32.0

==> /var/log/openhab2/openhab.log <==

2018-10-03 00:06:07.910 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

==> /var/log/openhab2/events.log <==

2018-10-03 00:06:13.071 [ome.event.ItemCommandEvent] - Item ‘Clrlight01Speed’ received command 45

2018-10-03 00:06:13.080 [vent.ItemStateChangedEvent] - Clrlight01Speed changed from 92 to 45

2018-10-03 00:06:13.141 [vent.ItemStateChangedEvent] - Clrlight01Dim changed from 32.0 to 44.0

==> /var/log/openhab2/openhab.log <==

2018-10-03 00:06:13.164 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

BIG Thanks I am happy that you tried this and used. I will place it nicely in Git hub shortly . Yesterday I just did copy - paste. I am sure you must have scratched your head multiple time to make it work, as code is without comments .

@ Brightness and Speed I also faced same issue but some how I managed to fix the issue . I will let you know .

try this :
Update Dimscale255-100.js with “%”

(function(i) {
var value = i.slice(4);
return “%”+Math.floor((value * 100) / 255);
})(input)

@ Speed can not be updated : Post update rule takes care of this issue.

Many a times I face issue with copy - paste issue for ’ " ’ char

it worked!

everything works as it should, except for openhab errors.

2018-10-03 22:15:37.885 [ome.event.ItemCommandEvent] - Item ‘Clrlight01Power’ received command OFF

2018-10-03 22:15:37.890 [vent.ItemStateChangedEvent] - Clrlight01Power changed from ON to OFF

==> /var/log/openhab2/openhab.log <==

2018-10-03 22:15:37.935 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Dim’

2018-10-03 22:15:38.081 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

I did not understand your rules. I don’t use them.

This rule will update the status change. So even if the status is changed using web UI / any interface the Openhab will get updated with latest status .

no result yet:

rule "McLighting"

when
    Item Clrlight01Power changed
then
    publish("mosquitto", "McLighting01/in", Clrlight01Dim.state.toString)
end

2018-10-04 22:50:07.845 [ome.event.ItemCommandEvent] - Item ‘Clrlight01Power’ received command ON

2018-10-04 22:50:07.855 [vent.ItemStateChangedEvent] - Clrlight01Power changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2018-10-04 22:50:07.860 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘McLighting’: The name ‘publish’ cannot be resolved to an item or type; line 9, column 1, length 70

2018-10-04 22:50:07.888 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Dim’

2018-10-04 22:50:07.921 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

==> /var/log/openhab2/events.log <==

2018-10-04 22:50:15.207 [ome.event.ItemCommandEvent] - Item ‘Clrlight01Power’ received command OFF

2018-10-04 22:50:15.224 [vent.ItemStateChangedEvent] - Clrlight01Power changed from ON to OFF

==> /var/log/openhab2/openhab.log <==

2018-10-04 22:50:15.230 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘McLighting’: The name ‘publish’ cannot be resolved to an item or type; line 9, column 1, length 70

2018-10-04 22:50:15.264 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Dim’

2018-10-04 22:50:15.299 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn’t post update for ‘Clrlight01Speed’

I fixed it

1 Like

I did it all. thank you so much

sujitrp