Multiple DayNight Toggles (aka Call Flow Control)?

Hello everyone!
I am in a desperate situation where I often need to change the active call flow control (which can only be one…right?).
I find that netsting call flow controls is very unhandy if you have 4 different scenarios.
So what I would like to do is to create an 4 different extensions that set the appropriate call flow as the inbound route destination.

To make an example:
I have
CALL FLOW NR 1
CALL FLOW NR 2
CALL FLOW NR 3
CALL FLOW NR 4

I create:
extension *881 -> Toggles Call Flow nr 1 and sets it as destination of the inbound route
extension *882 -> Toggles Call Flow nr 2 and sets it as destination of the inbound route
extension *883 -> Toggles Call Flow nr 3 and sets it as destination of the inbound route
extension *884 -> Toggles Call Flow nr 4 and sets it as destination of the inbound route

Is something like that possible?
If so…how would you achieve it?
Thank you in advance for your time and effort.

I figured it out

edit /etc/asterisk/extensions_custom.com and paste the following

[from-internal-custom]
include => enable-switch

[check-active-switch]
exten => s,1,NoOp(“This context loops through all the switches and checks which one is ON. Than it follows its destination”)
exten => s,n,GoSub(sub-get-nr-of-switches,s,1)
exten => s,n,Set(nrofs=${GOSUB_RETVAL})
exten => s,n,Set(i=0)
exten => s,n,Set(default-dest=app-daynight,${switchnr},1)
exten => s,n,Set(switchnr=“NULL”)
exten => s,n,While($[$[${i} < ${nrofs}] & $[${switchnr} = “NULL”]])
exten => s,n,Set(switchnr=${IF($["${DB(DAYNIGHT/C${i})}" = “NIGHT”]?${i}:“NULL”)})
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,EndWhile
exten => s,n,GotoIf($[${switchnr}!=“NULL”]?app-daynight,${switchnr},1:${default-dest})
exten => s,n,Hangup()

[sub-get-nr-of-switches]
exten => s,1,Set(nr_of_s=0)
exten => s,n,Set(exten_state=“NOT_ACQUIRED”)
exten => s,n,While($[${exten_state}!=0])
exten => s,n,Set(exten_state=$[${VALID_EXTEN(app-daynight,${nr_of_s},1)}])
exten => s,n,NoOp(Exten nr ${nr_of_s} of app-daynight is ${exten_state})
exten => s,n,Set(nr_of_s=${IF($[${exten_state}=1]?$[${nr_of_s}+1]:${nr_of_s})})
exten => s,n,EndWhile
exten => s,n,NoOp(${nr_of_s} switches found)
exten => s,n,Return(${nr_of_s})

[enable-switch]
exten =>_*20X,1,NoOp(“Abilita Switch selezionato e disabilita altre”)
same => n,GoSub(sub-get-nr-of-switches,s,1)
same => n,Set(nrofs=${GOSUB_RETVAL})
same => n,Set(switchtoactivate=${EXTEN:3})
same => n,NoOp(Activated Switch nr ${switchtoactivate})
same => n,Set(i=0)
same => n,While($[${i}<${nrofs}])
same => n,Set(DB(DAYNIGHT/C${i})=DAY)
same => n,Set(i=$[${i}+1])
same => n,EndWhile
same => n,Set(freepbx_toggle_dest=*28${switchtoactivate})
same => n,Goto(app-daynight-toggle,${freepbx_toggle_dest},1)
same => n,Hangup

Next go to freepbx and create a custom destination -> check-active-switch,s,1 and set it as destination of the inbound route

Hello,

very nice work but unfortunately does not work for me.
Switching Call Flow Control with *20X works but on any incoming call a have output:
– Executing [s@check-active-switch:11] GotoIf(“SIP/Trunk-00002765”, “0?app-daynight,“NULL”,1:app-daynight,1”) in new stack
– Goto (app-daynight,s,1)
[2018-01-08 09:19:30] WARNING[6761][C-00002762]: pbx.c:6863 __ast_pbx_run: Channel ‘SIP/Trunk-00002765’ sent to invalid extension but no invalid handler: context,exten,priority=app-daynight,s,1

Any suggestions?

Thanks.

This is because you don’t have any active toggles i.e. at least one should be in night mode for this to work correctly.

You can mitigate this by changing the following line. This contains a default detestation if no toggle is selected.
[check-active-switch]

exten => s,n,Set(default-dest=app-daynight,4,1)