23.07.2025, 11:31
Hello.
A few months ago, I integrated Philips Hue lighting fixtures that support dimming, color temperature change, and RGB. Everything works perfectly, except I hadn't set up the feedback for the light fixture's state if you change it from the Philips Hue app. Before posting on the forum, I carefully reviewed all topics related to this issue. I am using "user.hue v5.lua" and "resident hue feedback v2.lua". The on/off, dimming, and RGB feedback work perfectly. However, neither the color temperature change itself nor its feedback are working correctly. For example, I set 2000K from W4K, and in the Hue app, it shows a completely different color. The feedback also doesn't work. When I disable the feedback script, the color temperature control works correctly. I am using the following script. Please help me find where I am going wrong. I have spent over 2 days on this problem without a resolution.
Regards,
Nayden
A few months ago, I integrated Philips Hue lighting fixtures that support dimming, color temperature change, and RGB. Everything works perfectly, except I hadn't set up the feedback for the light fixture's state if you change it from the Philips Hue app. Before posting on the forum, I carefully reviewed all topics related to this issue. I am using "user.hue v5.lua" and "resident hue feedback v2.lua". The on/off, dimming, and RGB feedback work perfectly. However, neither the color temperature change itself nor its feedback are working correctly. For example, I set 2000K from W4K, and in the Hue app, it shows a completely different color. The feedback also doesn't work. When I disable the feedback script, the color temperature control works correctly. I am using the following script. Please help me find where I am going wrong. I have spent over 2 days on this problem without a resolution.
Regards,
Nayden
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
['Cove lighting-cr'] = {state = '1/0/9', bri = '32/2/9', rgb = '32/3/9', ct = '32/4/9', statevalue = '', brivalue = '', colorvalue = '', ctvalue = ''}
}
-- 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