DALI gateway

DALI gateway library #

Load the library:

require('user.dali')

Library functions #

res, err = dalicmd(gwid, cmd, params) #

Sends a DALI command to the given gateway. Returns true on success when no reply is expected, string on success when reply is expected, nil plus an error message in case of failure.

Parameters:

  • gwid - (number/string) gateway id: gateway number, 'internal' or 'internal2' (if internal DALI bus is present)
  • cmd - (string) command to send, refer to command table for possible values
  • params - (table) command parameters, see below

Parameters for common commands (Lua table):

  • addrtype - (string) address type, only required for addressable commands, possible values: short group broadcast
  • address - (number) short or group address
  • value - (number) additional value to send

3 addressing modes are supported

  • broadcast - all ballasts should react: { addrtype = 'broadcast' }
  • short - only one ballast having a unique short address should react: { addrtype = 'short', address = BALLAST_ID }
  • group - several ballasts belonging to a group should react: { addrtype = 'group', address = GROUP_ID }

Parameters for raw command (Lua table):

  • data - (string) data to send, either 2 or 3 bytes
  • reply - (boolean) reply from ballast is required
  • repeat - (boolean) send data twice

Command types #

If a command is addressable, you must provide address type and address in the params table.

If a command expects a reply it must be addressed so only one ballast can reply, otherwise a collision will happen. In case of success, reply is a binary string, usually consisting of a single byte. You can convert it to number like this:

-- query status of ballast with short address 5 on the internal DALI bus
res, err = dalicmd('internal', 'querystatus', { addrtype = 'short', address = 5 })
-- read ok
if res then
  status = res:byte()
  log(status)
end

If a command has a value range, the params table must have a value field which is an integer in the specified range. For example, arc command accepts a value from 0 to 254:

-- set level to 42 for all ballast on the internal DALI bus
dalicmd('internal', 'arc', { addrtype = 'broadcast', value = 42 })

Changing internal ballast parameters #

Most parameters are changed via DTR (data transfer register), so first you need to set DTR value via setdtr and then set the required parameter via a second request.

Set max level to 200 of the ballast with short address 5 on the internal DALI bus:

dalicmd('internal', 'setdtr', { addrtype = 'short', address = 5, value = 200 })
dalicmd('internal', 'storemax', { addrtype = 'short', address = 5 })

External gateway example #

Use gateway with id 1, switch all ballasts off, set ballast with short address 5 to full on:

require('user.dali')

dalicmd(1, 'arc', { addrtype = 'broadcast', value = 0 })
dalicmd(1, 'arc', { addrtype = 'short', address = 5, value = 254 })

DALI command list #

Command Description Address Reply Value range
arc direct arc power control 0..254
off turn off without fading
up dim up using the selected fade rate
down dim down using the selected fade rate
stepup step up
stepdown step down
recallmax recall max level
recallmin recall min level
stepdownoff step down and off
stepupon on and step up
gotoscene go to scene 0..15
reset reset
storeactual store actual level in the dtr
storemax store the dtr as max level
storemin store the dtr as min level
storesystemfailure store the dtr as system failure level
storepoweron store the dtr as power on level
storefadetime store the dtr as fade time
storefaderate store the dtr as fade rate
storescene store the dtr as scene 0..15
removescene remove from scene 0..15
addtogroup add to group 0..15
removefromgroup remove from group 0..15
storeshortaddress store dtr as short address
querystatus query status
queryballast query ballast
querylampfailure query lamp failure
querylamppoweron query lamp power on
querylimiterror query limit error
queryresetstate query reset state
querymissingshort query missing short address
queryversion query version number
querydtr query content dtr
querydevicetype query device type
queryphysicalmin query physical minimum level
querypowerfailure query power failure
queryactual query actual level
querymax query max level
querymin query min level
querypoweron query power on level
querysystemfailure query system failure level
queryfadetimerate query fade time / fade rate
queryscene query scene level (scenes 0-15) 0..15
querygroupslow query groups 0-7
querygroupshigh query groups 8-15
queryrandomaddrh query random address (high)
queryrandomaddrm query random address (middle)
queryrandomaddrl query random address (low)
terminate terminate
setdtr set data transfer register (dtr) 0..255
initialise initialise
randomise randomise
compare compare
withdraw withdraw
searchaddrh set search address (high) 0..255
searchaddrm set search address (middle) 0..255
searchaddrl set search address (low) 0..255
programshortaddr program short address 0..63
verifyshortaddr verify short address 0..63
queryshortaddr query short address
physicalselection physical selection
enabledevicetype enable device type x 0..255