Some functions for Type 8 temperature control
Code:
function getCurrentTc(gateway, addr)
code = 2 -- parameter code to get current Tc
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return tc
end
function getCoolestTcLimit(gateway, addr)
code = 128 -- parameter code to get coolest Tc limit
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return tc
end
function getCoolestTcLimitPhys(gateway, addr)
code = 129 -- parameter code to get coolest Tc physical limit
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return tc
end
function getWarmestTcLimit(gateway, addr)
code = 130 -- parameter code to get warmest Tc limit
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return tc
end
function getWarmestTcLimitPhys(gateway, addr)
code = 131 -- parameter code to get warmest Tc physical limit
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return tc
end
function setWarmestTcLimit(gateway, addr, tc)
code = 1 -- parameter code to set warmest Tc limit
res, err = dalicmd(gateway, 'setdtr2', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr2 error: ' .. err end
mirek = math.floor(1000000 / tc)
dtr0 = bit.band(mirek, 0xff)
dtr1 = bit.rshift(bit.band(mirek, 0xff00), 8)
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = dtr0 })
if err then return nil, 'setdtr2 error: ' .. err end
res, err = dalicmd(gateway, 'setdtr1', { addrtype = 'short', address = addr, value = dtr1 })
if err then return nil, 'setdtr2 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'storecolortemplimit', { addrtype = 'short', address = addr })
if err then return nil, 'storecolortemplimit error: ' .. err end
res, err = dalicmd(gateway, 'storecolortemplimit', { addrtype = 'short', address = addr })
return res, err
end
function setCoolestTcLimit(gateway, addr, tc)
code = 0 -- parameter code to set coolest Tc limit
res, err = dalicmd(gateway, 'setdtr2', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr2 error: ' .. err end
mirek = math.floor(1000000 / tc)
dtr0 = bit.band(mirek, 0xff)
dtr1 = bit.rshift(bit.band(mirek, 0xff00), 8)
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = dtr0 })
if err then return nil, 'setdtr2 error: ' .. err end
res, err = dalicmd(gateway, 'setdtr1', { addrtype = 'short', address = addr, value = dtr1 })
if err then return nil, 'setdtr2 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'storecolortemplimit', { addrtype = 'short', address = addr })
if err then return nil, 'storecolortemplimit error: ' .. err end
res, err = dalicmd(gateway, 'storecolortemplimit', { addrtype = 'short', address = addr })
return res, err
end
function saveSceneTc(gateway, addr, tc, arc_level, scene)
-- Save scene with saved Tc and Arc level
mirek = math.floor(1000000/tc)
dtr0 = bit.band(mirek, 0xff)
dtr1 = bit.rshift(bit.band(mirek, 0xff00), 8)
res, err = dalicmd(gateway, 'setdtr1', { addrtype = 'short', address = addr, value = dtr1 })
if err then return nil, 'setdtr1 tc error: ' .. err end
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = dtr0 })
if err then return nil, 'setdtr0 tc error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'setcolortemp', { addrtype = 'short', address = addr })
if err then return nil, 'setcolortemp error: ' .. err end
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = arc_level })
if err then return nil, 'setdtr0 arc_level error: ' .. err end
res, err = dalicmd(gateway, 'storescene', { addrtype = 'short', address = addr, value = scene })
if err then return nil, 'storescene error: ' .. err end
res, err = dalicmd(gateway, 'storescene', { addrtype = 'short', address = addr, value = scene })
if err then return nil, 'storescene error: ' .. err end
return res, err
end
function getSupportedColorTypeFeatures(gateway, addr)
-- Get supported color type features
-- Return pattern:
-- If successful:
-- xy - 0/1, unsupported/supported
-- tc - 0/1, unsupported/supported
-- direct - 0-5, how much channels support direct control
-- rgbwaf - 0-5, how much rgbwaf channels
-- else: nil, Command name with error
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorfeatures', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorfeatures error: ' .. err end
res = res:byte()
xy = bit.band(res, 0x01)
tc = bit.rshift(bit.band(res, 0x02), 1)
direct = bit.rshift(bit.band(res, 0x1c), 2)
rgbwaf = bit.rshift(bit.band(res, 0xe0), 5)
return xy, tc, direct, rgbwaf
end
function getSceneTc(gateway, addr, scene)
res, err = dalicmd(gateway, 'queryscene', { addrtype = 'short', address = addr, value = scene })
if err then return nil, 'queryscene error: ' .. err end
arc_level = res:byte()
code = 226 -- parameter code to get scene Tc
res, err = dalicmd(gateway, 'setdtr0', { addrtype = 'short', address = addr, value = code })
if err then return nil, 'setdtr0 error: ' .. err end
res, err = dalicmd(gateway, 'enabledevicetype', { addrtype = 'short', address = addr, value = 8 })
if err then return nil, 'enabledevicetype error: ' .. err end
res, err = dalicmd(gateway, 'querycolorvalue', { addrtype = 'short', address = addr })
if err then return nil, 'querycolorvalue error: ' .. err end
hb = res:byte()
res, err = dalicmd(gateway, 'querydtr0', { addrtype = 'short', address = addr })
if err then return nil, 'querydtr0 error: ' .. err end
lb = res:byte()
mirek = bit.lshift(hb, 8) + lb
tc = 1000000 / mirek
return arc_level, tc
end