Mix between dahdi and voip

Hello, I’m trying to determine the best way to setup outoing routing to utilize analog (dahdi/zap) trunks when they are available and voip trunks (through a service such as vitelity) when they are unavailable.

We have 3 dahdi/zap lines that are currently in a group (g0, but I can re-arrange as necessary). These lines are considered “key” lines which means that there is a single telephone number that is used to call into the company. The call will roll-over to the first available line out of the three lines.

My goal is to subsidize outgoing calling with a voip trunk such as vitelity. I would like vitelity to be used for outoing calls when 2 out of the 3 dahdi/zap lines are in use for either outgoing or incoming calls.

I know I could just set the max channels setting to 2 on my dahdi/zip trunk but it seems to me that the inbound calls are not counted against the maximum so it would be common to have more than 2 channels being used at times when the trunk thinks it is only using two.

I was able to find out how to count inbound sip trunk calls against an outbound sip trunk.

Please advise.