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:
Then add this as a resident script at 0 seconds:
From now on you can get the lamp ID by name using this:
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)
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
Code:
--Create lights and groups table (resident at 0)
require('user.hue')
makeLightsTable()
makeGroupsTable()
os.sleep(600)
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)