This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Philips HUE Lamps state
#1
Hi,

I am using Schneider Philips HUE Libraries ( https://www.se.com/it/it/download/document/AN2_002/) with LM to control HUE Lamps.

It works fine,but... there is no mention of how to get the status of the lamps.

This is very important because in this way there is no correspondence of the states between those indicated in the Philips app on smartphone and those of the LM.

Ok, I can turn them on and off, but how can I associate the status of a lamp with an ETS object?

Can you help me? 


Thanks in advance


Peppe
Reply
#2
See this: https://forum.logicmachine.net/showthread.php?tid=890
Reply
#3
Ok, thanks....
Do you think it's better to get rid of Schneider libraries or I could try to integrate them with yours?
What is the shortest way to make everything working?
Thanks

Peppe
Reply
#4
Do you mean the AN scripts? Then yes you should use mine (also SE) from link above (:
Reply
#5
hello, I was going crazy trying to command on a single group at a time, without succeeding. On and OFF acted on all groups. When I noticed in the function in the library what I think is an oversight:

Code:
1234567891011121314
function sendToGroup(Group_num,body_request)   local response = {}   socket.http.request({   url = "http://"..ip_add.."/api/"..user.."/groups/"..tostring(Light_num).."/action",   method = 'PUT',   sink = ltn12.sink.table(response),   headers = {   ['content-length'] = #body_request,   ['content-type'] = 'application/json',   },   source = ltn12.source.string(body_request),   })   return response end


I guess Light_num on url in 4 row is wrong and to be subsustite by Group_num.... am I right?
By the way, can I address a group by its name?
Reply
#6
You are right about the wrong variable in the code. It seems that groups can only be accessed by a number but not by a name. Group 0 is a broadcast group that controls all lights together.
Reply
#7
(15.12.2021, 05:50)admin Wrote: You are right about the wrong variable in the code. It seems that groups can only be accessed by a number but not by a name. Group 0 is a broadcast group that controls all lights together.

ok thanks.... another question:

-- 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
  ['Led Centrale Down'] = {state = '11/4/10', bri = '11/4/13', rgb = '11/4/12', statevalue = '', brivalue = '', colorvalue = ''},
  ['Led Destro Down'] = {state = '11/4/20', bri = '11/4/23', rgb = '11/4/22', statevalue = '', brivalue = '', colorvalue = ''},
  ['Led Sinistro Down'] = {state = '11/4/30', bri = '11/4/33', rgb = '11/4/32', statevalue = '', brivalue = '', colorvalue = ''},
  ['Led Centrale Up'] = {state = '12/4/10', bri = '12/4/13', rgb = '12/4/12', statevalue = '', brivalue = '', colorvalue = ''},
  ['Led Destro Up'] = {state = '12/4/20', bri = '12/4/23', rgb = '12/4/22', statevalue = '', brivalue = '', colorvalue = ''},
  ['Led Sinistro Up'] = {state = '12/4/30', bri = '12/4/33', rgb = '12/4/32', statevalue = '', brivalue = '', colorvalue = ''}

I can't get any feedback (neither commands) form rgb addresses.... actually I set them as 3 byte unsigned integer (232.600 colours), maybe is that wrong?

Tnx

Peppe
Reply
#8
Yes you can control by name by adding these 2 functions to your user.hue:
Code:
12345678910111213141516171819202122232425
function makeLightsTable()   local lights = getHueLights()   if lights then     lights = json.pdecode(lights)     LightsTable = {}     for _, foundlights in pairs(lights) do       LightsTable[foundlights.name] = tonumber(_)     end     storage.set("hue:lights", LightsTable)   end   return LightsTable end function makeGroupsTable()   local groups = getHueGroups()   if groups then     groups = json.pdecode(groups)     GroupsTable = {}     for _, foundgroups in pairs(groups) do       GroupsTable[foundgroups.name] = tonumber(_)     end     storage.set("hue:groups", GroupsTable)   end   return GroupsTable end
Then add this as a resident script at 0 seconds:
Code:
12345
--Create lights and groups table (resident at 0) require('user.hue') makeLightsTable() makeGroupsTable() os.sleep(600)
From now on you can get the lamp ID by name using this:
Code:
123456789
lamp_id = storage.get("hue:lights")["Plafondlamp Woonkamer"] or 0 body_msg = '{"on":false}' sendToLight(lamp_id,body_msg) -- or group_id = storage.get("hue:groups")["Woonkamer"] or 0 body_msg = '{"on":true}' sendToGroup(group_id,body_msg)

PS: You are correct, there once was a mistake in a older user.hue lib with the sendToGroup function, it was already corrected in my latest version(s)
Reply
#9
(15.12.2021, 14:09)Erwin van der Zwart Wrote: Yes you can control by name by adding these 2 functions to your user.hue:
Code:
12345678910111213141516171819202122232425
function makeLightsTable()   local lights = getHueLights()   if lights then     lights = json.pdecode(lights)     LightsTable = {}     for _, foundlights in pairs(lights) do       LightsTable[foundlights.name] = tonumber(_)     end     storage.set("hue:lights", LightsTable)   end   return LightsTable end function makeGroupsTable()   local groups = getHueGroups()   if groups then     groups = json.pdecode(groups)     GroupsTable = {}     for _, foundgroups in pairs(groups) do       GroupsTable[foundgroups.name] = tonumber(_)     end     storage.set("hue:groups", GroupsTable)   end   return GroupsTable end
Then add this as a resident script at 0 seconds:
Code:
12345
--Create lights and groups table (resident at 0) require('user.hue') makeLightsTable() makeGroupsTable() os.sleep(600)
From now on you can get the lamp ID by name using this:
Code:
123456789
lamp_id = storage.get("hue:lights")["Plafondlamp Woonkamer"] or 0 body_msg = '{"on":false}' sendToLight(lamp_id,body_msg) -- or group_id = storage.get("hue:groups")["Woonkamer"] or 0 body_msg = '{"on":true}' sendToGroup(group_id,body_msg)

PS: You are correct, there once was a mistake in a older user.hue lib with the sendToGroup function, it was already corrected in my latest version(s)

Sorry, I don't understand... I can already control on/off and 0-100% brightness.... How I could use that system?  What I need is to set and feedback of RGB COLOURS....
Reply
#10
This was the answer on your initial question: By the way, can I address a group by its name?

I asumed you wanted to control the HUE group by name but I suppose you meant to use the KNX name instead of ‘1/1/1’ and the answer on that one is yes should work but never recommending that..
Reply
#11
Sorry, I didn't explain myself well, I messed up a bit with more than one problem... and by now it's ok to control HUE Groups by number.

I have no problems to control on-off and 0-100% brightness.

What I need now is to set the RGB colors and receive feedback, both for groups and for individual lamps.

Can you provide me the correct scripts to do it?

The one for the groups and the one for single light.

Thanks

Peppe
Reply
#12
Well, i won't promose to provide anything, quite busy at the time, but the question is why doesn't it work for you and works for me and others..

Do you have color lights or white/yellow? as white/yellow are controlled by XY values and not HUE values (RGB), so i guess this is the case..
Reply
#13
(16.12.2021, 12:16)Erwin van der Zwart Wrote: Well, i won't promose to provide anything, quite busy at the time, but the question is why doesn't it work for you and works for me and others..

Do you have color lights or white/yellow? as white/yellow are controlled by XY values and not HUE values (RGB), so i guess this is the case..

Don't worry, maybe I solved it.

I will let you know later if had troubles.

Thanks again

Peppe
Reply
#14
Hi,
since I also needed the color temperature feedback, I modified the "Hue feedback" script as per attached code.

But the result is that it assigns to all "ctstate" addresses the same value, that is, that of the first.

The rest of the script works fine.
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
-- 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   ['Led Sinistro Down'] = {state = '11/4/10', bri = '11/4/14', rgb = '12/5/14', ct = '12/5/15', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},   ['Led Centrale Down'] = {state = '11/4/20', bri = '11/4/24', rgb = '12/5/24', ct = '12/5/25', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},   ['Led Destro Down'] = {state = '11/4/30', bri = '11/4/34', rgb = '12/5/34', ct = '12/5/35', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},   ['Led Sinistro Up'] = {state = '12/4/10', bri = '12/4/14', rgb = '12/6/14', ct = '12/6/15', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},   ['Led Centrale Up'] = {state = '12/4/20', bri = '12/4/24', rgb = '12/6/24', ct = '12/6/25', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},   ['Led Destro Up'] = {state = '12/4/30', bri = '12/4/34', rgb = '12/6/34', ct = '12/6/35', statevalue = '', brivalue = '', colorvalue = '', ctstate =''} } -- 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 TEMP. KELVIN       name = addressmapping[item.name]       if name then         addr = addressmapping[item.name]['ct']         if addr and addr ~= '' then           currentvalue = addressmapping[item.name]['ctstate']           if currentvalue ~= item.state.ct then             grp.update(addr, tonumber(item.state.ct))             addressmapping[item.name]['ctstate'] = item.state.ct             if logging == true then               log('lamp ' .. item.name .. ' ct is: ' .. item.state.ct)             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

I have missing something...

Peppe

Attached Files Thumbnail(s)
   
Reply


Forum Jump: