Asterisk func Devstate
Created by: JustRumours,Last modification on Wed 29 of Apr, 2009 [12:04 UTC]
DEVICE_STATE(device) and DEVSTATE(device)
Synopsis
Get or Set a device stateIntroduced in Asterisk 1.6 as DEVICE_STATE(), with a backport available for 1.4.
Description
The DEVICE_STATE function can be used to retrieve the device state from any device state provider.For example:
NoOp(SIP/mypeer has state ${DEVSTATE(SIP/mypeer)})
NoOp(Conference number 1234 has state ${DEVSTATE(MeetMe:1234)})
The DEVSTATE function can also be used to set custom device state from the dialplan. The "Custom:" prefix must be used.
For example:
Set(DEVSTATE(Custom:lamp1)=BUSY)
Set(DEVSTATE(Custom:lamp2)=NOT_INUSE)
You can subscribe to the status of a custom device state using a hint in the dialplan:
exten => 1234,hint,Custom:lamp1
The possible values for both uses of this function are:
UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING | RINGINUSE | ONHOLD
Asterisk 1.6.1.x: The event infrastructure in Asterisk got another big update to help support distributed events. It currently supports distributed device state and distributed Voicemail MWI (Message Waiting Indication). A new module has been merged, res_ais, which facilitates communicating events between servers. It uses the SAForum AIS (Service Availability Forum Application Interface Specification) CLM (Cluster Management) and EVT (Event) services to maintain a cluster of Asterisk servers, and to share events between them. For more information on setting this up, see doc/distributed_devstate.txt.
Troubleshooting
- Make sure you know what will happen after an Asterisk restart! It might be necessary to use a .call file (or the Asterisk manager API) to call the DevState application right after Asterisk has started to ensure correct LED status. Note that, before doing so, you might also have to reboot or initialize the phones in question so that they can renew their SIP subscription of the extension that is used to monitor the devicestate; for example SIP NOTIFY could be used for that purpose (see sip_notify.conf).
Example of using DEVICE_STATE for call-limit
Because call-limit is deprecated, sometimes you will need to make sure that, if an extension is in use, you will not call it.The following dialplan entries make sure that extension 100 has only one call at a time.
exten => 100,1,ExecIf($ ${DEVICE_STATE(SIP/${EXTEN})} = INUSE ?Busy)
exten => 100,2,Dial(SIP/${EXTEN})
See also
- Asterisk func HINT: New HINT() function in Asterisk 1.6
- Asterisk func EXTENSION_STATE: New EXTENSION_STATE() function in Asterisk 1.6
- Backport for Asterisk 1.4
- Extstate() function for 1.4, get extension state instead of device
- Asterisk cmd BristuffDevstate
- Asterisk SLA
- Mini How-To: Blog entry by the author
- Devstate server, small server to link devstate between multiple Asterisk servers.

Comments
333New Version of fun_devstate
Changed both in the file and edited the comments.
Hope this patch will help some of you guys.
New download here: http://www.hdpnet.de/downloads/asterisk/devstate/func_devstate.c
333
3331.4 backport
333DevState Backport mod
Syntax: funcdevstate change <custom device> <state>
Example: funcdevstate change Custom:test0 RINGING
URL Here: http://paul.voinetworks.net/func_devstate.c
333Devstate - SIP Channel remain NOT_INUSE
I use Grandstream SIP phones and found that this particular issue is a result of wrong "type=" entry in sip.conf.
Changing type=friend to type=peer for the GS extension resolved the issue.
My Asterisk is 1.4.16.2 patched with the func_devstate.c backport.
333devstate for SIP channel
If the call is initiated by the SIP channel, then the state remains NOT_INUSE even if the call gets through. But if the call is sent to the SIP channel, the states work perfectly, but changing to RINGING, BUSY etc. I have tried SCCP and IAX2 channel and both work fine both ways meaning calling and being called.
What should I do ?
Should I submit a bug report ?
My asterisk version is Asterisk 1.4.7.1.