Extension with Time Conditions?

I am in the process of setting up a PBX for a school where DDI calls to classroom extensions should land at the switchboard during school hours, but go through to the extension at other times.

Can someone point me to some documentation on how to do this, preferably using the FreePBX Gui but if it requires editing a custom config file that would be also o.k. – I expect this configuration to be pretty static.

You should be able to do this with Time conditions. You will need to point the inbound route to a time condition that rings the switchboard during normal hours and rings the extension otherwise. I think this would be pretty straightforward to set-up in the Web Gui.

If you take this approach that John says (which will work), you’ll need to program that for each DID. So if you have 100 DIDs that would normally ring to 100 different extensions, then you’ll have to create 100 different internal routes and 100 different time conditions.

Do your DIDs map to extension numbers? Meaning, does NXX1234 map to extension 1234?

If you have DID’s, then they would all have to have their own route - so thinking in reverse - How about a time condition of ‘All calls between 8-5 mon-fri’ go to XXXX (the switchboard), then use the specific DID routes for the ‘off hours’.

it’s a useful feature request to enter into the system if this is a common issue, basically a destination that can be set against a timegorup that can then have any number of inbound routes link to, so if the condition is met (or not met, which ever logic you choose) anything linked to that goes to that destination, otherwise it goes to their already defined destination. Such feature requests need to go into the tracker or they will be quickly forgotten.

This might not be too hard to implement with a line or two of custom code.

If your trunk is in the from-trunk or from-pstn context place a section in extensions_custom.conf called “from-pstn-custom” and add a line of code similar to this:

exten => _XXX.,1,GotoIfTime(time range|days of week|days of month|months?[[context|]extension|]pri)

In practice this might look like

exten => _XXX.,1,GotoIfTime(9:00-17:00|mon-fri||?ivr-3,s,1)

This will match any DID that has at least 4digits and test that call for the time. If the time matches, in this case 9-5 daily, it will send all calls to ivr-3. If it fails the time test, it will fall on through to the normal call routing, which in your case would be the DID match and off to an extension.


Thank you very much for that last example; that looks easy enough to implement.

Now if you would also have a suggestion where next to look for my Incoming Calls problem ( http://www.freepbx.org/forum/freepbx/users/incoming-calls-on-sip-trunk-403-forbidden ) … can’t turn off the telco line for the voip line until I can receive calls over it.


If you want to keep working properly, you are probably going to need something more like this I believe:

exten => _XXX.,1,GotoIfTime(9:00-17:00|mon-fri|*|*?ivr-3,s,1)
exten => _XXX.,n,Goto(ext-did,${EXTEN},1)

Otherwise it will not find anything else in the from-pstn-custom context and then fail outside of that time (at least with some asterisk configs as I think this behavior has been changing somewhat with 1.4 depending on certain config options). The assumption above is that all the dids are defined, as it will circumvent from-did-direct and ext-did-catchall.

So … in the long term, if there is enough interest (or bribes) a module that hooks into inbound routes, allowing a single destination to be specified for multiple routes by time would be the right way to go. (And then daynight able to hook into it like has been enabled with timeconditions on 2.5 to override one or multiple time conditions with a single daynight override would be even better.)


I have some custom code in from-pstn-custom and I don’t have a return route at the end of it. Here Tiz:


exten => 6419621634,1,Answer()
exten => 6419621634,n,noop(It is in From PSTN custom)
exten => 6419621634,n,wait(2)
exten => 6419621634,n,senddtmf(1|1000)

I use this code to send a dtmf 1 to trick my Grand Central number into thinking I have pressed one. Note that I do not have a return route. I think because the call to “from-pstn-custom” is actually an include, it return to the next command after the include. At least, this is the behavior I have observed. Let me know if I am off base here, but it works on my box.

I think this is new behavior in 1.4 and I’m not sure if it is configurable or not. I do not think it is the same in 1.2 although I am not certain. Here is an example test to understand the behavior:

exten => 9123,1,Noop(tst-1 - 1)
exten => 9123,n,Noop(tst-1 - 2)

exten => 9123,1,Noop(tst-2 - 1)
exten => 9123,n,Noop(tst-2 - 2)
exten => 9123,n,Noop(tst-2 - 3)

exten => 9123,1,Noop(tst-3 - 1)
exten => 9123,n,Noop(tst-3 - 2)
exten => 9123,n,Noop(tst-3 - 3)
exten => 9123,n,Noop(tst-3 - 4)

include => tst-1
include => tst-2
include => tst-3

Now dial 9123 and you will get:

    -- Executing [[email protected]:1] NoOp("SIP/222-b7501c28", "tst-1 - 1") in new stack
    -- Executing [[email protected]:2] NoOp("SIP/222-b7501c28", "tst-1 - 2") in new stack
    -- Executing [[email protected]:3] NoOp("SIP/222-b7501c28", "tst-2 - 3") in new stack
    -- Executing [[email protected]:4] NoOp("SIP/222-b7501c28", "tst-3 - 4") in new stack
    -- Executing [[email protected]:5] Wait("SIP/222-b7501c28", "1") in new stack
    -- Executing [[email protected]:6] Congestion("SIP/222-b7501c28", "20") in new stack

So note it will fall through and look for the next priority in the next include, meaning you have to be very careful because as you can see, [tst-2] does not have it’s priority 1 or 2 executed and [tst-3] does not have it’s first 3 executed.

Wolf, sorry for hijacking the thread.
Philippe, I am glad we hijacked this thread. If I had done this, I would never had figured it out. Thanks for the insight.

In Wolf’s case, your way would be the correct way. I usually use this to trap something and if it does trap it, then process the call normally. I need to modify my code also.

Thanks and have a great day. Suppertime here.

I don’t mind this hijacking – I learned things from this.