Upgrade 3CX to v18 and get it hosted free!

Asterisk day night mode example

Author image

This example shows you a simple way to have a day and night mode that will automatically switch based on the current system time.
In this example, I assume 4710 is our MAIN DID extension. Extension 521 is the reception desk extension number. We use a gotoiftime statement to see if we should go to the prompt or if we should continue on to dialing the reception extension. The 4710 would be replaced with the S extension if you are working with analog lines.

/etc/asterisk/extensions.conf


exten => 4710,1,GotoIfTime(17:00-8:59|*|*|*?night-mode|1) ;break at night send directly to message otherwise just continue and dial
exten => 4710,2,GotoIfTime(12:00-12:59|*|*|*?night-mode|1);break for lunch
exten => 4710,3,Dial(Sip/521,15,tr)
exten => 4710,4,Goto(night-mode,1)

exten => night-mode,1,Answer
exten => night-mode,2,Wait(2)
exten => night-mode,3,SetMusicOnHold(default)
exten => night-mode,4,DigitTimeout,3
exten => night-mode,5,ResponseTimeout,20
exten => night-mode,6,Background(/astsounds/p1)
exten => night-mode,7,SetVar(LISTCOUNT=$[${LISTCOUNT} + 1]) ; increment
exten => night-mode,8,WaitExten(8)
exten => night-mode,9,GotoIf($["${LISTCOUNT}" >= "0"]?0,1:3)
exten => night-mode,10,Background(pls-wait-connect-call)
exten => night-mode,11,Goto(0)

; 0 Forwards caller to receptionist
exten => 0,1,Playback(pls-wait-connect-call)
exten => 0,2,Dial(Sip/510,30,m)
exten => 0,3,Voicemail(u510)
exten => 0,104,Voicemail(u510)

Night Service Button

This alternate example presents an Asterisk 1.6.1 example that works more like a traditional button toggle, based on AEL and using ASTDB that provides BLF lamp updates for a Snom 320 with firmware 7.3.14. If you are using snom you should follow the instructions at https://wiki.snom.com/Features/Extension_Monitoring#Configuration to ensure that your BLF subscriptions are successful. Following that you should set the spare function on your snom to subscribe to your Night service phantom DN.

Simply read DB(service/daynight) to act on it in your dialplan.

extensions.ael

context nightservice { // You must include this in your relevant internal context in extensions.conf

// assuming 7702 is the Custom phantom DN for your night service lamp

hint(Custom:7702) 7702 => {
// Day service / night service toggle
SayDigits(1); // Change this to a suitable prompt
Read(SERVICEMODE,);
&setServiceMode(${SERVICEMODE},Custom:${EXTEN});
}

}

macro setServiceMode(mode,blfDevice) {
Verbose(BLF DEVICE: ${blfDevice});
switch(${mode}) {
case D: //day
case 3: // keypad button for D
Set(mode=D);
Set(BLF=NOT_INUSE); // lamp off
break;
case N: //night
case 6: // keypad button for N
Set(mode=N);
Set(BLF=BUSY); // lamp on solid
break;
case L: //Lunch
case 5: // keypad button for L
Set(mode=L);
Set(BLF=ONHOLD); // lamp flashing
break;
default:
Set(${mode}=”D”);
Set(BLF=NOT_INUSE);
break;
}
Verbose(BLF Setting: ${BLF});
Set(DB(service/daynight)=${mode});
Set(DEVICE_STATE(${blfDevice})=${BLF});
}

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.