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?
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
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:
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.
(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.
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?
15.12.2021, 14:09 (This post was last modified: 15.12.2021, 14:13 by Erwin van der Zwart.)
Yes you can control by name by adding these 2 functions to your user.hue:
Code:
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:
--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:
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)
(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:
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:
--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:
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....
15.12.2021, 15:05 (This post was last modified: 15.12.2021, 15:08 by Erwin van der Zwart.)
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..
(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..
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