Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
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
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
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
Posts: 1793
Threads: 6
Joined: Jul 2015
Reputation:
120
Do you mean the AN scripts? Then yes you should use mine (also SE) from link above (:
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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?
Posts: 8069
Threads: 43
Joined: Jun 2015
Reputation:
470
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.
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
(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
Posts: 1793
Threads: 6
Joined: Jul 2015
Reputation:
120
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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:
1 2 3 4 5
require (
'user.hue' )
makeLightsTable ()
makeGroupsTable ()
os.sleep (
600 )
From now on you can get the lamp ID by name using this:
Code:
1 2 3 4 5 6 7 8 9
lamp_id =
storage.get (
"hue:lights" )[
"Plafondlamp Woonkamer" ]
or 0
body_msg =
'{"on":false}'
sendToLight (
lamp_id ,
body_msg )
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)
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
(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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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:
1 2 3 4 5
require (
'user.hue' )
makeLightsTable ()
makeGroupsTable ()
os.sleep (
600 )
From now on you can get the lamp ID by name using this:
Code:
1 2 3 4 5 6 7 8 9
lamp_id =
storage.get (
"hue:lights" )[
"Plafondlamp Woonkamer" ]
or 0
body_msg =
'{"on":false}'
sendToLight (
lamp_id ,
body_msg )
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....
Posts: 1793
Threads: 6
Joined: Jul 2015
Reputation:
120
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..
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
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
Posts: 1793
Threads: 6
Joined: Jul 2015
Reputation:
120
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..
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
(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
Posts: 289
Threads: 77
Joined: May 2017
Reputation:
0
25.01.2022, 13:09
(This post was last modified: 25.01.2022, 15:52 by gdimaria .)
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
addressmapping = {
[
'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 =
'' }
}
interval =
1
logging =
true
require (
'user.hue' )
require (
'json' )
while true do
reply =
getHueLights ()
mylamps =
json.decode (
reply )
for _ ,
item in pairs (
mylamps )
do
if item.state.reachable ==
true then
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
name =
addressmapping [
item.name ]
if name then
addr =
addressmapping [
item.name ][
'bri' ]
if addr and addr ~=
'' then
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
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
name =
addressmapping [
item.name ]
if name then
addr =
addressmapping [
item.name ][
'rgb' ]
if addr and addr ~=
'' then
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 )
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.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
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
end
os.sleep (
interval )
end
I have missing something...
Peppe
Attached Files
Thumbnail(s)