Logic Machine Forum
Hue ledstrip with RGB and Tunable white - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Hue ledstrip with RGB and Tunable white (/showthread.php?tid=1970)



Hue ledstrip with RGB and Tunable white - DanielB - 15.03.2019

Hi,

I have managed to get rgb control work with scripting towards the KNX, but still cant find any script to control Tunable white.
Can somebody help me? or is it impossible? Confused

Best regards
Daniel


RE: Hue ledstrip with RGB and Tunable white - Daniel - 15.03.2019

Hi
How do you control the light? Here is script which might help
https://forum.logicmachine.net/showthread.php?tid=890&pid=11326#pid11326
BR


RE: Hue ledstrip with RGB and Tunable white - DanielB - 15.03.2019

(15.03.2019, 12:36)Daniel. Wrote: Hi
How do you control the light?  Here is script which might help
https://forum.logicmachine.net/showthread.php?tid=890&pid=11326#pid11326
BR

I allready checked on that link, but i cant find anything how to control the "kelvin in the white colour" 
hmmm. I have allready got the RGB control to work but that does not include the control of the white colour.

Daniel


RE: Hue ledstrip with RGB and Tunable white - Daniel - 15.03.2019

And this is what this script meant to do. It takes color temperature from an 2 byte object and converts it to RGB value.


RE: Hue ledstrip with RGB and Tunable white - admin - 15.03.2019

Have a look here: http://rsmck.co.uk/hue

It looks like you can send both brightness and color temperature by a single request, you just need to add a new function to the user library.
Code:
{"ct": 500, "bri": 254}



RE: Hue ledstrip with RGB and Tunable white - FatMax - 15.03.2019

HUE uses CT, not the other one you are familiar with. It’s a simple conversion.

https://forum.logicmachine.net/showthread.php?tid=1529&highlight=Hcl


RE: Hue ledstrip with RGB and Tunable white - DanielB - 19.03.2019

(15.03.2019, 20:15)FatMax Wrote: HUE uses CT, not the other one you are familiar with. It’s a simple conversion.

https://forum.logicmachine.net/showthread.php?tid=1529&highlight=Hcl

Can you give me an example on how i should put this function in user libraries? and how to set it up in event based?. (Just so i can control Kelvin and brightness from knx)
I still dont understand this conversion thing:-)

Best regards
Daniel


RE: Hue ledstrip with RGB and Tunable white - admin - 19.03.2019

Add to user library:
Code:
function setBrightnessCT(Light_num,brightness,ct)
  if brightness == 0 then
    body_msg = '{"on":false}'
    response = sendToLight(lamp_id,body_msg)
    return response
  else
    brightness = math.floor((brightness / 1) + 0.5)
    brightness = math.floor((brightness * 2.54) + 0.5)
  
    ct = math.floor(1000000 / ct)
    ct = math.min(500, ct)
    ct = math.max(154, ct)

    --HTTP request send
    body_msg = '{"on":true,"bri":'..brightness..',"ct":'..ct..'}'
    return sendToLight(Light_num,body_msg)
  end
end

You will need to map an event script to both brightness and color temperature values:
Code:
require('user.hue)
lamp_id = 123
bri = grp.getvalue('1/1/1') -- 0..100%
ct = grp.getvalue('1/1/2') -- 2000K..6500K
setBrightnessCT(lamp_id, bri, ct)



RE: Hue ledstrip with RGB and Tunable white - DanielB - 19.03.2019

(19.03.2019, 09:13)admin Wrote: Add to user library:
Code:
function setBrightnessCT(Light_num,brightness,ct)
 if brightness == 0 then
   body_msg = '{"on":false}'
   response = sendToLight(lamp_id,body_msg)
   return response
 else
   brightness = math.floor((brightness / 1) + 0.5)
   brightness = math.floor((brightness * 2.54) + 0.5)
 
   ct = math.floor(1000000 / ct)
   ct = math.min(500, ct)
   ct = math.max(154, ct)

   --HTTP request send
   body_msg = '{"on":true,"bri":'..brightness..',"ct":'..ct..'}'
   return sendToLight(Light_num,body_msg)
 end
end

You will need to map an event script to both brightness and color temperature values:
Code:
require('user.hue)
lamp_id = 123
bri = grp.getvalue('1/1/1') -- 0..100%
ct = grp.getvalue('1/1/2') -- 2000K..6500K
setBrightnessCT(lamp_id, bri, ct)

Thank you very much :-)

Now it works like a charm:-)

Daniel


RE: Hue ledstrip with RGB and Tunable white - DanielB - 20.03.2019

Last question:-)

Can anybody help me get feedback for colour temperature for this?

I use this script today and get values for on/off, brightness and colour for rgb

-- Set name (Lookup in HUE app under light configuration) and feedback adresses (don't change statevalue, brivalue and colorvalue as they are used as memoryfield)
addressmapping = {
-- Name -- On/Off FB -- Bright FB -- Color FB
['KjkGangstripe'] = {state = '1/5/16', bri = '1/3/20', rgb = '1/7/16', statevalue = '', brivalue = '', colorvalue = ''},
['Kjkinnredning'] = {state = '1/5/17', bri = '1/6/17', rgb = '1/7/17', statevalue = '', brivalue = '', colorvalue = ''},
-- ['Hue color lamp 3'] = {state = '1/3/3', bri = '1/4/3', rgb = '1/5/3', statevalue = '', brivalue = '', colorvalue = ''},
-- ['Hue color lamp 4'] = {state = '1/3/4', bri = '1/4/4', rgb = '1/5/4', statevalue = '', brivalue = '', colorvalue = ''}
}

-- Set polling interval in seconds
interval = 1

-- Use logging
logging = true

require('user.hue')
require('json')
-- loop indefenitly
while true do
reply = getHueLights()
mylamps = json.decode(reply)
for _, item in pairs(mylamps) do

-- Check if lamp is found by bridge otherwise it make no sense to send commands
-- if item.state.reachable == true then

-- On/Off
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['state']
if addr and addr ~= '' then
currentvalue = addressmapping[item.name]['statevalue']
if currentvalue ~= item.state.on then
grp.update(addr, item.state.on)
addressmapping[item.name]['statevalue'] = item.state.on
if logging == true then
log('lamp ' .. item.name .. ' state is: ' .. tostring(item.state.on))
end
end
end
end

-- Brightness
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['bri']
if addr and addr ~= '' then
-- Check if lamp is on otherwise overrule BRI value to 0
if item.state.on == false then
item.state.bri = 0
end
currentvalue = addressmapping[item.name]['brivalue']
if currentvalue ~= item.state.bri then
grp.update(addr, math.floor((tonumber(item.state.bri)/2.55) + 0.5))
addressmapping[item.name]['brivalue'] = item.state.bri
if logging == true then
log('lamp ' .. item.name .. ' brightness is: ' .. math.floor((tonumber(item.state.bri)/2.55) + 0.5) .. ' %')
end
end
end
end

-- Color
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['rgb']
if addr and addr ~= '' then
-- Check if lamp is on otherwise overrule color value to 0
if item.state.on == false then
colorvalue = 0
end
if item.state.colormode == 'xy' then
currentvalue = addressmapping[item.name]['colorvalue']
colorvalue = xy_to_rgb(item.state.xy[1],item.state.xy[2],item.state.bri)
--colorvalue = xyz_to_rgb((item.state.xy[1] * 100), (item.state.xy[2] * 100))
if currentvalue ~= colorvalue then
grp.update(addr, colorvalue)
addressmapping[item.name]['colorvalue'] = colorvalue
if logging == true then
log('lamp ' .. item.name .. ' color is: ' .. colorvalue)
end
end
elseif item.state.colormode == 'ct' then
currentvalue = addressmapping[item.name]['colorvalue']
--colortemp = math.floor((item.state.ct / 0.0769) + 0.5) --0.0769230769230769
colortemp = math.abs((item.state.ct - 500) / 2)
colortemp = math.floor(colortemp + 0.5)
colortemp = 80 + colortemp
if colortemp > 255 then
colortemp = 255
end
r = lmcore.inttohex(255, 1)
g = lmcore.inttohex(255, 1)
b = lmcore.inttohex(colortemp, 1)
rgb = r .. g .. b
colortemp = lmcore.hextoint(rgb,3)
if currentvalue ~= colortemp then
--colortempconverted = ct_to_rgb(colortemp)
grp.update(addr, colortemp)
addressmapping[item.name]['colorvalue'] = colortemp
if logging == true then
log('lamp ' .. item.name .. ' color is: ' .. colortemp)
end
end
end
end
end

--end

--log('manufacturername = ' .. item.manufacturername)
--log('swversion = ' .. item.swversion)
--log('type = ' .. item.type)
--log('ct = ' .. item.state.ct)
--log('reachable = ' .. item.state.reachable)
--log('alert = ' .. item.state.alert)
--log('on = ' .. item.state.on)
--log('bri = ' .. item.state.bri)
--log('colormode = ' .. item.state.colormode)
--log('hue = ' .. item.state.hue)
--log('sat = ' .. item.state.sat)
--log('effect = ' .. item.state.effect)
--log('x = ' .. item.state.xy[1])
--log('y = ' .. item.state.xy[2])
--log('uniqueid = ' .. item.uniqueid)
--log('modelid = ' .. item.modelid)
--log('name = ' .. item.name)

end
-- Delay loop
os.sleep(interval)
end

Thank you for all help :-)


RE: Hue ledstrip with RGB and Tunable white - admin - 20.03.2019

Calculate the reverse color temp like this:
Code:
colortemp = math.floor(1000000 / item.state.ct)

Keep in mind that there might be a difference between set and status values due to precision loss during when converting between Mireks and Kelvins.


RE: Hue ledstrip with RGB and Tunable white - DanielB - 20.03.2019

(20.03.2019, 08:04)admin Wrote: Calculate the reverse color temp like this:
Code:
colortemp = math.floor(1000000 / item.state.ct)

Keep in mind that there might be a difference between set and status values due to precision loss during when converting between Mireks and Kelvins.

still dont understand how to get this working in my resident script Huh

Sorry for all my questions, but i still got a bit to learn about scripting .-)

Daniel