Maybe this will help you, it works great for us:
[LoggedOffPhone]
exten => *11,1,Goto(from-internal,${EXTEN},1)
exten => *12,1,Goto(from-internal,${EXTEN},1)
exten => _.,1,Answer()
same => n,Set(USEREXIST=$[${DB(DEVICE/${CALLERID(num)}/user)}])
same => n,GotoIf($[${USEREXIST}=none]?LoginOption)
same => n,Goto(from-internal,${EXTEN},1)
same => n,Hangup()
same => n(LoginOption),Playback(cannot-complete-as-dialed)
same => n,Goto(*11,1)
exten => 112,1,Goto(from-internal,${EXTEN},1)
exten => 911,1,Goto(from-internal,${EXTEN},1)
Then, put all devices in this LoggedOffPhone context. Then, in order for BLF keys to work, add this to sip_additional (or in case of FreePBX, the custom version): subscribecontext=from-internal