RE: Hue Brightness feedback - Sral1987 - 30.11.2020
Thank you admin
it worked just one time then this error replyed
Code: Resident script:32: Expected value but found T_END at character 1
stack traceback:
[C]: in function 'decode'
this is my full resident feedbac script
Code: -- 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
['Schlafzimmer'] = {state = '10/1/27', bri = '10/1/15', rgb = 'x/x/x', ct = '32/1/21', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Wand Links'] = {state = '32/1/7', bri = '32/1/9', rgb = '32/1/16', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Wand Rechts'] = {state = '32/1/8', bri = '32/1/10', rgb = '', statevalue = '', brivalue = '', colorvalue = ''},
['Küche Led'] = {state = '32/1/11', bri = '32/1/13', rgb = '10/1/5', statevalue = '', brivalue = '', colorvalue = ''},
['Küche indirekt'] = {state = '32/1/12', bri = '10/1/3', rgb = '32/1/14', statevalue = '', brivalue = '', colorvalue = ''},
['Esstisch'] = {state = '10/1/157', bri = '10/1/159', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Zelt'] = {state = '10/1/25', bri = 'x/x/x', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Wohnzimmer Links'] = {state = '32/1/3', bri = '32/1/5', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Wohnzimmer Rechts'] = {state = '32/1/4', bri = '32/1/6', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Kinderzimmer Links'] = {state = '32/1/17', bri = '32/1/19', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Kinderzimmer Rechts'] = {state = '32/1/18', bri = '32/1/20', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Nachtlicht'] = {state = '10/1/57', bri = '10/1/59', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Küche Theke'] = {state = '10/1/161', bri = '10/1/163', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''}
}
-- Set polling interval in seconds
interval = 1
-- Use logging
logging = false
-- Load needed lib's
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.write(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
if item.state.bri then
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'] or 0
if currentvalue ~= item.state.bri then
grp.write(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
end
-- color temperature
name = addressmapping[item.name]
if name and item.state.ct then
addr = addressmapping[item.name]['ct']
if addr and addr ~= '' then
newvalue = math.floor(1000000 / item.state.ct)
currentvalue = addressmapping[item.name]['ctvalue']
if currentvalue ~= newvalue then
grp.update(addr, newvalue)
addressmapping[item.name]['ctvalue'] = newvalue
if logging == true then
log('lamp ' .. item.name .. ' color temperature is: ' .. newvalue .. ' K')
end
end
end
end
--Color
if item.state.ct or item.state.xy then
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.checkwrite(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.write(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
end
-- Delay loop
os.sleep(interval)
end
RE: Hue Brightness feedback - Erwin van der Zwart - 30.11.2020
I think you use an older version of the user.hue
Can you check if your function getHueLights() matches the one below? Especially for return table.concat(response)
Code: function getHueLights()
local response = {}
body_searchHueLights= ''
socket.http.request({
url = "http://"..ip_add.."/api/"..user.."/lights",
method = 'GET',
sink = ltn12.sink.table(response),
headers = {
['content-length'] = #body_searchHueLights,
['content-type'] = 'application/json',
},
source = ltn12.source.string(body_searchHueLights),
})
return table.concat(response)
end
RE: Hue Brightness feedback - Sral1987 - 01.12.2020
Hmm strage behavior,
now it works without any error. User.hue function is the same. I user your V3.
The last time this Error appeared was yesterday 22:30, i did not change anything.
What i notice is when i add a new light ist takes some time to recorgnize till states would written on objects. Is there something like a timeouot or value check before writing to objects ?
Anyway thank you admin and Erwin for your Work
BR
RE: Hue Brightness feedback - Ravi Kiran S - 25.03.2021
(09.06.2020, 08:24)Firechief Wrote: Ok, got it working now!
Thx for the help Can u pls tell me How run the Bridge setup () and how to control hue lights with LM
RE: Hue Brightness feedback - Karaffe - 21.01.2022
Hello
The control of Philips Hue lamps via the fabrscript is working.
But how can I control tunable white lamp or how is the script to do this for a single lamp
So that I can change the color temperature.
Could someone help me with this I would need the script for this (hue commands)
RE: Hue Brightness feedback - Firechief - 25.03.2023
@ Erwin,
I've installed a few (13) new Hue lamps and i'm trying to discover their lampnumbers via the discover script. I get a return in the log, but not all lamps are there. Any idea?
Code: Hue discovery 24.03.2023 08:18:54
* string: 192.168.100.187
Hue discovery 24.03.2023 08:18:54
* table:
[1]
* string: [{"error":{"type":101,"address":"","description":"link button not pressed"}}]
Hue discovery 24.03.2023 08:18:55
* table:
[1]
* string: [{"success":{"/lights":"Searching for new devices"}}]
Hue discovery 24.03.2023 08:18:55
string: {
“1":{"state":{"on":false,"bri":254,"hue":41490,"sat":78,"effect":"none","xy":[0.3116,0.3277],"ct":153,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2022-12-03T14:06:43"},"type":"Extended color light”,"name":"Led terras”,
"modelid":"LST004","manufacturername":"Signify Netherlands B.V.","productname":"Hue lightstrip outdoor”,"capabilities":{"certified":true,"control":{"mindimlevel":2000,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"huelightstrip","function":"mixed","direction":"omnidirectional","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:06:6a:54:98-0b","swversion":"1.101.2","swconfigid":"D771FA32","productid":"Philips-LST004-1-LedStripsOutv1"},
"3":{"state":{"on":false,"bri":254,"hue":41432,"sat":75,"effect":"none","xy":[0.3143,0.3302],"ct":156,"alert":"none","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2022-12-03T14:00:15"},"type":"Extended color light","name":"Keuken Werkblad R”,
"modelid":"LCA001","manufacturername":"Signify Netherlands B.V.","productname":"Hue color lamp”,"capabilities":{"certified":true,"control":{"mindimlevel":200,"maxlumen":800,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"sultanbulb","function":"mixed","direction":"omnidirectional","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:06:2e:13:af-0b","swversion":"1.101.2","swconfigid":"3C05E7B6","productid":"Philips-LCA001-5-A19ECLv6"},
"4":{"state":{"on":false,"bri":254,"hue":41432,"sat":75,"effect":"none","xy":[0.3143,0.3302],"ct":156,"alert":"none","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2022-12-03T14:00:25"},"type":"Extended color light","name":"Keuken Werkblad L”,
"modelid":"LCA001","manufacturername":"Signify Netherlands B.V.","productname":"Hue color lamp”,"capabilities":{"certified":true,"control":{"mindimlevel":200,"maxlumen":800,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"sultanbulb","function":"mixed","direction":"omnidirectional","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:06:2c:ef:60-0b","swversion":"1.101.2","swconfigid":"3C05E7B6","productid":"Philips-LCA001-5-A19ECLv6"},
"5":{"state":{"on":false,"bri":254,"hue":8632,"sat":117,"effect":"none","xy":[0.4425,0.4060],"ct":343,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2023-02-16T16:21:36"},"type":"Extended color light","name":"Douche 1”,
"modelid":"LCG002","manufacturername":"Signify Netherlands B.V.","productname":"Hue color spot”,"capabilities":{"certified":true,"control":{"mindimlevel":200,"maxlumen":300,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"spotbulb","function":"mixed","direction":"downwards","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:06:bb:4b:ae-0b","swversion":"1.101.10","swconfigid":"0982EB31","productid":"Philips-LCG002-1-GU10ECLv2"},
"6":{"state":{"on":false,"bri":254,"hue":8632,"sat":117,"effect":"none","xy":[0.4425,0.4060],"ct":343,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2023-02-16T16:27:01"},"type":"Extended color light","name":"Douche 2”,
"modelid":"LCG002","manufacturername":"Signify Netherlands B.V.","productname":"Hue color spot”,"capabilities":{"certified":true,"control":{"mindimlevel":200,"maxlumen":300,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"spotbulb","function":"mixed","direction":"downwards","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:08:41:77:f1-0b","swversion":"1.101.10","swconfigid":"0982EB31","productid":"Philips-LCG002-1-GU10ECLv2"},
"7":{"state":{"on":false,"alert":"none","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2021-12-12T13:50:30"},"type":"On/Off plug-in unit","name":"Hue Smart plug”,
"modelid":"LOM002","manufacturername":"Signify Netherlands B.V.","productname":"Hue Smart plug”,"capabilities":{"certified":true,"control":{},"streaming":{"renderer":false,"proxy":false}},"config":{"archetype":"plug","function":"functional","direction":"omnidirectional","startup":{"mode":"safety","configured":true}},"uniqueid":"00:17:88:01:08:62:9c:b7-0b","swversion":"1.93.6","swconfigid":"7A0791B1","productid":"SmartPlug_OnOff_v01-00_02"},
"10":{"state":{"on":false,"bri":254,"hue":41432,"sat":75,"effect":"none","xy":[0.3143,0.3302],"ct":156,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2022-12-08T15:39:53"},"type":"Extended color light","name":"Keuken Wasbak”,
"modelid":"929003116101","manufacturername":"Signify Netherlands B.V.","productname":"Perifo linear light bar”,"capabilities":{"certified":true,"control":{"mindimlevel":100,"maxlumen":1700,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"ceilinghorizontal","function":"mixed","direction":"downwards","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:0c:bd:de:f4-0b","swversion":"1.101.5","swconfigid":"83BB01E2","productid":"3241-3129-1221_HC07_PSG04"},
"11":{"state":{"on":false,"bri":254,"hue":41432,"sat":75,"effect":"none","xy":[0.3143,0.3302],"ct":156,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2022-12-08T14:16:02"},"type":"Extended color light","name":"Hanglamp Eiland 2”,
"modelid":"929003115901","manufacturername":"Signify Netherlands B.V.","productname":"Perifo cylinder pendant”,"capabilities":{"certified":true,"control":{"mindimlevel":100,"maxlumen":510,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"pendantspot","function":"mixed","direction":"downwards","startup":{"mode":"powerfail","configured":true}},"uniqueid":"00:17:88:01:0d:1a:8b:aa-0b","swversion":"1.101.5","swconfigid":"85CF1793","productid":"4422-9556-4251_HC07_PSG04"},
"13":{"state":{"on":false,"bri":254,"hue":41432,"sat":75,"effect":"none","xy":[0.3143,0.3302],"ct":156,"alert":"select","colormode":"ct","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2023-01-04T16:43:50"},"type":"Extended color light","name":"Hanglamp Eiland 1”,
"modelid":"929003115901","manufacturername":"Signify Netherlands B.V.","productname":"Perifo cylinder pendant”,"capabilities":{"certified":true,"control":{"mindimlevel":100,"maxlumen":510,"colorgamuttype":"C","colorgamut":[[0.6915,0.3083],[0.1700,0.7000],[0.1532,0.0475]],"ct":{"min":153,"max":500}},"streaming":{"renderer":true,"proxy":true}},"config":{"archetype":"pendantspot","function":"mixed","direction":"downwards","startup":{"mode":"safety","configured":true}},"uniqueid":"00:17:88:01:0c:69:83:d8-0b","swversion":"1.101.5","swconfigid":"85CF1793","productid":"4422-9556-4251_HC07_PSG04"},
"14":{"state":{"on":false,"bri":254,"hue":39391,"sat":14,"effect":"none","xy":[0.3682,0.3715],"ct":230,"alert":"select","colormode":"xy","mode":"homeautomation","reachable":true},"swupdate":{"state":"noupdates","lastinstall":"2023-03-24T07:16:31"},"type":"Extended color light","name":"Eetplaats Balk”,
"modelid":"5060730P7_01","manufacturername":"Signify Netherlands B.V.","productname"...
As you can see there are ... but even that lamp is not complete.
user.lua: V5
Kind regards
RE: Hue Brightness feedback - admin - 27.03.2023
Each log entry is limited to 8KB. You can decode the JSON string and log each entry separately:
Code: data = require('json').decode(response)
for key, value in pairs(data) do
log(key, value)
end
RE: Hue Brightness feedback - Firechief - 28.03.2023
(27.03.2023, 05:28)admin Wrote: Each log entry is limited to 8KB. You can decode the JSON string and log each entry separately:
Code: data = require('json').decode(response)
for key, value in pairs(data) do
log(key, value)
end
Do i add this to the current hue discovery script?
Kind regards.
RE: Hue Brightness feedback - admin - 28.03.2023
Yes, instead of logging the JSON string response from getHueLights() use the above code. Replace response variable with the variable name that getHueLights() returns.
RE: Hue Brightness feedback - Firechief - 28.03.2023
Admin,
I'm sorry, but as stated in my signature i am a novice at this.
So i've made a new "test" script and pasted the code in there, but nothing shows up.
I do get an error in the error log:
Code: Hue Discovery Test 28.03.2023 11:22:58
Resident script:2: bad argument #1 to 'decode' (string expected, got nil)
stack traceback:
[C]: in function 'decode'
So cleary i'm doing something wrong but i have no clue.
RE: Hue Brightness feedback - admin - 28.03.2023
Post your full script
RE: Hue Brightness feedback - Firechief - 28.03.2023
Code: require('user.hue')
data = require('json').decode(response)
for key, value in pairs(data) do
log(key, value)
end
RE: Hue Brightness feedback - admin - 28.03.2023
Try this:
Code: require('user.hue')
response = getHueLights()
data = require('json').decode(response)
for key, value in pairs(data) do
log(key, value)
end
RE: Hue Brightness feedback - Firechief - 28.03.2023
This works! Thx a lot!
Admin,
This seems to log only 10 out of my 19 lamps...
Admin,
Disregard my remark, it seems only 10 are shown in the log at the script itself. In the SE general log they are all there.
RE: Hue Brightness feedback - NKereshki - 20.04.2023
Helo,
Can you help me with the script to control the RGB color of a group in Philips Hue. I followed your recommendations for on/off, brightness and color temperature and everything works very well. But I can't handle the RGB of a group. I am using user.hue v5
Thank you in advance!
Best regards,
Nayden
RE: Hue Brightness feedback - Erwin van der Zwart - 20.04.2023
Are you using setRGBGroup(Group_num,RGB_variable)?
RE: Hue Brightness feedback - NKereshki - 20.04.2023
(20.04.2023, 12:12)Erwin van der Zwart Wrote: Are you using setRGBGroup(Group_num,RGB_variable)?
Hello,
I haven't tried that. In the forum I can't find an example script using the setRGBGroup(Group_num,RGB_variable). I'm an electrical engineer and now styding lua scripting. I used the RGB commands in the HUE for one lamp and everything works perfectly. But for a group I can't set it up.
Best regards,
Nayden Kereshki
RE: Hue Brightness feedback - Erwin van der Zwart - 21.04.2023
Code: --Control HUE group from RGB object (color) (use as event based script)
require('user.hue')
value = event.getvalue()
group_id = 1
if value == 0 then
body_msg = '{"on":false}'
sendToGroup(lamp_id,body_msg)
else
setRGBGroup(group_id,value)
end
RE: Hue Brightness feedback - NKereshki - 24.04.2023
(21.04.2023, 06:45)Erwin van der Zwart Wrote: Code: --Control HUE group from RGB object (color) (use as event based script)
require('user.hue')
value = event.getvalue()
group_id = 1
if value == 0 then
body_msg = '{"on":false}'
sendToGroup(lamp_id,body_msg)
else
setRGBGroup(group_id,value)
end
Hello, Erwin
Thank you very much for the help. It works exactly as I expected. I don't know what we would do without your support.
Best regards,
Nayden Kereshki
RE: Hue Brightness feedback - Sral1987 - 01.05.2023
(05.09.2020, 20:24)Erwin van der Zwart Wrote: Hi,
You have 2 mistakes in your script:
Code: response = sendToGroup(group_id,body_msg)
should be
response = sendToGroup(Group_id,body_msg)
and
response = sendToGroup(Group_num,body_msg)
should be
response = sendToGroup(Group_id,body_msg)
I just tested with my latest user lib and this command and works perfect
Code: require('user.hue')
require('json')
--log(json.pdecode(getHueGroups())) -- enable to check group number
--setBrightnessGroup(1,100) -- Group, brightness in %
setBrightnessCTGroup(1,60,2000) -- Group, brightness in %, CT in Kelvin
BR,
Erwin
Hi Erwin,
finaly i found time to Solve Group Control, unfortunanly i cant control Groups by Group Adress cause the Brightness Value is the Script by 100%. How could i change that ?
NVM!!! Sometimes the Solutuoion is just to easy ( shame on me )
of course it has to be like this
require('user.hue')
require('json')
--log(json.pdecode(getHueGroups())) -- enable to check group number
value = event.getvalue() -- 1 byte unsigned integer scale 0 - 100
setBrightnessGroup(3,value) -- Group, brightness in %
--setBrightnessCTGroup(1,60,2000) -- Group, brightness in %, CT in Kelvin
|