Time Conditions

Hi everyone,
I am currently stuck at a problem. I have time conditions configured in my FreePBX with time groups from 7 am to 5pm. If this time condition matches, the calls go to a ring group, if not then the calls go to an IVR, saying we are currently closed. Currently, all the workers are using softphones to make calls. What I want to achieve is: if an extension is still online after 5 pm, the call should go to the extension, instead going to the IVR.
Thanks !

There are a couple ways to accomplish that but not sure if any will meet your needs. Perhaps someone else can offer another solution I haven’t presented here.

  1. set up a call flow control in front of the time conditions that the users “working late” can activate and deactivate. Example:

normal call flow between 7 & 5 > ring group
normal call flow between 5pm & 7AM > IVR

suggested change:

Normal call flow > call flow control = DAY > time group > etc…
Normal call flow > call flow control = NIGHT > ring group

This way, if the call flow control is left in it’s default “DAY” setting, the Time condition controls the call routing. If the call flow control is set to “NIGHT” (using a *xxx dial code) it overrides the Time Condition and routes calls directly to the ring group until it is set back to “DAY” again.

The only caveat to this is you’ll need to trust your employees to turn the Call flow control off after they finish working late so that normal Time Conditions will take over again.

  1. The other possibility is just to route all calls directly to the ring group and have the ring group’s failover be the IVR. Arguably not a great solution.

If you want to branch a call based on the device status of a single extension, you can do so using dynroutes and this method: Using Dynamic Routes to branch call flow based on extension state

Using dynroutes you can check the extension hint for the value of UNAVAILABLE and branch the call that way. You can probably string multiple conditions as part of the expression using and/or, but I don’t recall ever doing that so you’ll have to google it.

Alternatively, if there is an API you can call somewhere that will tell you if the office is occupied, you could use that with dynroutes as well.

1 Like

Interesting idea but wouldn’t that get a bit cumbersome if there were more than one or two extensions involved? you’d have to create a dynamic route to check each extension and daisy chain them on a negative result no?

Unless I don’t understand the method properly.

1 Like

Yes, this is only practical if you can do it with 1 or 2 dynroutes. if monitoring multiple extensions, then it gets more complex than my last answer. You would want to use an Asterisk expression like the following:

$["${EXTENSION_STATE(7002@from-internal)}"="UNAVAILABLE" & "${EXTENSION_STATE(7005@from-internal)}"="UNAVAILABLE"]

I just tested. The above expressions will evaluate to ‘1’ if ALL of the conditions are met, i.e. both extensions 7002 and 7005 are UNAVAILABLE (no devices registered) otherwise it will evaluate to ‘0’. You could add checks against other extensions by stringing them together with the & char. Then one could use this expression in a dynroute using the method outlined in this post: Using Dynamic Routes as an extended blocklist

For completeness I also tested this expression:

$["${EXTENSION_STATE(7002@from-internal)}"="UNAVAILABLE" || "${EXTENSION_STATE(7005@from-internal)}"="UNAVAILABLE"]

which evaluates to ‘1’ if EITHER condition is met which otherwise evaluates to ‘0’.

If monitoring more than a small number of extensions, it would probably be best to create a single custom hint that tracks all the extensions in question and then use that custom hint in the dynroute.

I was thinking of the same thing. Like would it be possible to write a dialplan that created a hint for a dialgroup and set it to either OCCUPIED or EMPTY based on the status of all the member extensions.

So if all the extensions were set as UNAVAILABLE then the status of the dialgroup would be “EMPTY” but if any of the member extensions were any other value then the status would be “OCCUPIED”

Not sure how you’d make it dynamic though so as members of the dialgroup are added/subtracted it would know.

I just configured the call flow control with these changes, but to set this night the person who is online has to toggle it to night by dialing the *280 number given by freepbx. Is there anyway i can automate this so that the user doesn’t has to do it every time? Any possibility that looks at the status of the user and toggle it to night automatically after 5pm if online and when the user goes offline again, it sets to it normal DAY call flow control.


Yep, you can make your own cron job that has a query and action based on the result. I believe the callflow control is just an AstDB entry that you can update from the asterisk CLI.

This is correct.

Is there any way or any tutorial or post where i can a guide to to this? I am actually new to this place.


Yes-ish, seems like @ashcortech actually has some experience here and might be willing share what they ultimately did. You will like need to modify triggers and conditions to match your unique needs.

Is it possible to use cron to turn off callflow - FreePBX / System Administration - FreePBX Community Forums

The post give you some idea on changing the callflow control, you will likely need to do some googling to get everything else lined up.

Alternatively, if you want to try to do it in the web GUI, you could try stringing multiple dynamic routes together.

Here is a post about how to change a CFC from a dynamic route. You would need another dynamic route in front of this to run your determination query and route to this dynamic route if the conditions are met.

Using Dynamic Routes for Call Flow Control - FreePBX / Tips and Tricks - FreePBX Community Forums

PBX GUI : Dynamic Routes User Guide (sangoma.com)

I had the exact asterisk command line needed somewhere in my notes and can’t find it. I’ll do some more digging

Ok, found the command…

You need to use the asterisk database command in a script.

so very simply you could put /usr/sbin/asterisk -x “database put DAYNIGHT C0 DAY”


/usr/sbin/asterisk -x “database put DAYNIGHT C0 NIGHT”

into a cronjob to change the Call Flow Toggle Feature Code Index id of 0.

The Call Flow Toggle Feature Code Index is the number in the first field of the callflow module in the FreePBX GUI. If you wanted to do the same with a callflow that had an index ID of 6 it would be:

/usr/sbin/asterisk -x “database put DAYNIGHT C6 NIGHT”

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.