Dali commissioning Luminaires
How should I implement DTR command for multiple elements?
If you look at the structure of the DTR command (now called DTR0 in Ed 2), you can see that there is no address information in it. It is just the command number and the 8 bit value. This means that if you send a DTR command, all control gear on the bus that are powered on and connected will set their internal DTR value to the sent value; that is it is inherently a broadcast command. You cannot set different DTR values in different gear without resorting to non standard methods such as powering off or disconnecting gear selectively which is not usually possible in an installation.
The way you set different values for a setting such as MAX LEVEL in different gear is to address the STORE DTR AS MAX LEVEL command to only those gear. It does not matter that DTR has changed in all the gear, DTR is a RAM value which is reused for lots of purposes and is volatile. The first byte of command 42, STORE DTR AS MAX LEVEL is an address byte with the bits in the format YAAA AAA1 where Y=0 for short addresses, 1 for group or broadcast. The A bits are the binary value of 0 to 63 for the short address option, or 0 to 15 for the group address option, and are all 1 for the broadcast option.
Which commands should I use to verify if my lamp is addressed and without group?
Command 150 QUERY MISSING SHORT ADDRESS can be sent with the standard addressing methods - short, group or broadcast. The response is Yes if the gear has no short address set. You can see the same information in the response to Command 144 QUERY STATUS where bit 6 of the response is set if the gear has no short address set. The difference between using these two commands is due to the way that DALI handles collisions when you can have multiple responses. If you send Command 144 QUERY STATUS broadcast or group addressed, you can get collisions in the response because all gear must respond and not be able to determine anything about any of the gear, but if you send Command 150 QUERY MISSING SHORT ADDRESS broadcast or group addressed and get no response then either all gear have short addresses or there are none present, and if you get Yes or a collision then you know at least 1 gear has a missing short address.
Command 192 QUERY GROUPS 0-7 and Command 193 QUERY GROUPS 8-15 sent to the short address that you are interested in. For example, if you wanted to find out if short address 0 was a member of any group, you would issue both queries and consider all the bits in both responses like this:
Command 192 QUERY GROUPS 0-7 is binary YAAA AAA1 1100 0000. So for Short Address 0, this is 0000 0001 1100 0000 = 0x01C0
Say you get a response 0x93 = 1001 0011 meaning groups 0, 1, 4 and 7 are set.
Command 193 QUERY GROUPS 8-15 is binary YAAA AAA1 1100 0001. So for Short Address 0, this is 0000 0001 1100 0001 = 0x01C1
Say you get a response 0x81 = 1000 0001 meaning groups 8, and 15 are set.
So in total, groups 0, 1, 4, 7, 8 and 15 are set in the gear with Short Address 0, the rest are clear.
If you are checking that it is not a member of any group, you would expect response of 0 for both of these queries.
Random Addressing in DALI
The addressing routine is done by the gear selecting a random 3 byte (24 bit) number, so that it is highly unlikely to be the same as any other gear on the bus, and the master searching for that address. Only when the search address matches the random address will the gear be able to be programmed with a short address. All the control gears see the same search address but they should have unique random addresses. If not, there is a verification stage which can catch duplicates and the gear should be asked to select a new random number.
The core of the addressing routine is

Initialise (repeated twice) - this can be addressed to broadcast,
short address, or only those without short address.
Randomise (repeated twice) - no addressing. Gear generates an
internal 3 byte random number (address). Then wait 100ms.
Set Search Address (3 byte value H, M, L) - Master is going to ask
how the random address compares with this search address.
Compare - Gear response Yes if its random address is less than or
equal to the Search address, and not in Withdrawn state.
Master {changes search address, sends it out and sends Compare} in a
loop until the Search Address must equal the Random address. It is
very likely, but not guaranteed, that this has occurred in only one
gear on the bus. That gear where this is the case is now in Selected
mode which has special meaning to command 267.
Command 267 PROGRAM SHORT ADDRESS (with short address in second byte
in the bit format 0AAA AAA1). Only gear in selected mode will accept
this command.
Command 268 VERIFY SHORT ADDRESS (with short address in same format)

should get a Yes response.


Withdraw - Prevents response to Compare commands until the next
Initialise in the gear which in Selected mode.
Repeat from Set Search address (step 3) until no further gear is found.
Terminate - Gear exits addressing mode.

There is no particular algorithm recommended for handing out the short addresses, so most masters just start with 0 and work upwards. The only requirement is to not reuse the same short address, so the master needs to keep a (non volatile) list of used addresses, which is probably needs to do anyway for routine control messages. Also note that there is no explicit requirement to select the search addresses using a binary search method but that a linear search will timeout the Initialise timer and be too slow to be acceptable to users.
I've described the basics of the addressing routine - there are some additional points such as timeouts, deleting short addresses, minimising traffic/time on the bus, identifying gear during the process etc which can be learned from the standard.