This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

DALI DT8 Dimmer
#7
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
Reply


Messages In This Thread
DALI DT8 Dimmer - by managementboy - 06.11.2018, 15:55
RE: DALI DT8 Dimmer - by admin - 08.11.2018, 08:07
RE: DALI DT8 Dimmer - by managementboy - 17.11.2018, 13:39
RE: DALI DT8 Dimmer - by AEK - 28.11.2018, 09:19
RE: DALI DT8 Dimmer - by Daniel - 28.11.2018, 10:12
RE: DALI DT8 Dimmer - by AEK - 28.11.2018, 10:28
RE: DALI DT8 Dimmer - by Snoolik - 19.12.2018, 12:16
RE: DALI DT8 Dimmer - by Snoolik - 26.12.2018, 12:22
RE: DALI DT8 Dimmer - by khalil - 06.07.2021, 09:58
RE: DALI DT8 Dimmer - by Snoolik - 08.05.2019, 09:48
RE: DALI DT8 Dimmer - by admin - 06.07.2021, 10:58
RE: DALI DT8 Dimmer - by khalil - 06.07.2021, 11:25
RE: DALI DT8 Dimmer - by admin - 06.07.2021, 11:35
RE: DALI DT8 Dimmer - by khalil - 07.07.2021, 14:37
RE: DALI DT8 Dimmer - by admin - 07.07.2021, 14:39
RE: DALI DT8 Dimmer - by khalil - 08.07.2021, 10:52
RE: DALI DT8 Dimmer - by admin - 08.07.2021, 10:57
RE: DALI DT8 Dimmer - by khalil - 08.07.2021, 11:23

Forum Jump: