Know the state of the extension before dialing

i want to know the status of an extension before dialing to it. basically i dont want to dial to the extension when it is busy or offline. i tired with device_state and extension_state . but with my following code i always found same result for extension 2000.

exten => 2000,1,Verbose(The Device status is ${DEVICE_STATE(SIP/2000)})
exten => 2000,n,Verbose(or the extension status is ${EXTENSION_STATE(2000)})
  -- Executing [2000@from-internal:1] Verbose("SIP/2001-00000035", "The Device status is NOT_INUSE") in new stack
The Device status is NOT_INUSE
    -- Executing [2000@from-internal:2] Verbose("SIP/2001-00000035", "or the extension status is UNKNOWN") in new stack
or the extension status is UNKNOWN

You need to enable call counters. Also note that a SIP phone on which someone is dialing a number will appear to be free, and there will always be glare cases where the line was free when tested, but not when called.

thanks david,

its working …