[Tasker Tips & Tricks] markvvaals:
The problem I was facing is the "check" to see if bluetooth was connected, in which case it is undesirable to disconnect obviously.

For instance I disconnect from car bluetooth and within the wait time I reconnect to it (or another bluetooth device for that matter).

The previous solutions would turn off bluetooth after the timer has finished, regardless if you are connected or not.

EDIT: Here is my new, more elegant solution.

The solution I had before is at the bottom of this post.

Summary

Create a profile that's activated when bluetooth is connected and on.

This triggers a wait time, after which it turns off bluetooth.

It only does this when this profile is active, thus only when nothing is connected to bluetooth.

Detailed steps

Create a profile and call it "BT Disconnected"

Then choose context: State, Net, BT Connected

Leave name and address blank, but check invert

Confirm by using the back button (top left)
​

You're now prompted to select a task, create a new one

Call it "BT Auto Off"

Press the + to add an action

Select action category: Task, Wait

Now fill it with the delay you want

(Note: do not set too short, this will turn bluetooth off before it can connect to anything. I suggest at least a minute or so.)

Confirm by using the back button (top left)
​

Add another task with the plus icon (bottom right)

Select action category: Net, Bluetooth

Leave set to "off" and add an If argument

For the variable, fill in %PACTIVE

Leave operator as Match (~)

As value, type: *,BT Disconnected,*

(Note: use the profile name you chose at the start, between commas and asterisks)

Optionally label the task something like "BT off if not connected"

Confirm by using the back button
​

Go back to the tasker main screen, let's add another context.

Click the profile to unfold it and long press the state "Not BT Connected"

Choose add for our second context: State, Net, BT Status

Change status to "on"

Confirm by using the back button (top left)
​

Don't forget to press the check mark at the top of the main screen to confirm the changes and activate them.

Hope this helps someone!

-----------------------------------------------------------------------------------

My previous solution is behind the button below.

I set up a profile which is active when bluetooth is connected and used the exit task to turn off bluetooth.

The steps below walk you through the setup of this profile

Create a profile

Call it "BT Connected"

Then chose: State, Net, BT Connected

Leave everything blank (we want this profile to be active during all bluetooth connections)

Confirm by using the back button.
​

You're now prompted to select a task, create a new one

Call it "Do Nothing"

Press the + to add an action

Select action category: Task, Wait

Then set it to 1 second.

Confirm the action and then the task by using the back button twice.​

Now you're back at the main screen, long press the "-> Do Nothing" and add an exit task.

Call it "BT Auto Off"

Press the + to add an action

Select action category: Task, Wait

Now fill it with the delay you want

I suggest at least a minute or so to allow a lost connection to reconnect. Can also be much more, I have mine set to 10min.​

Confirm the wait time and add another action.

Select action category: Net, Bluetooth

Set "off" and add an If argument.

For the variable, fill in %PACTIVE

For operator choose Doesn't match (!~)

For argument use *,BT Connected,*

Note: use the profile we are creating, between asterisks and commas.
​

Confirm by using the back button.
​

Now all you need to do is press the check mark at the top of the main screen to confirm the changes and activate them.

What it does, explained

The new profile (BT Connected) is activated when you connect to any BT device.

Once activated it runs the entry task which is "Do Nothing". That is because we don't want it to do anything but we do need this profile to be active while connected.

When the bluetooth connection is lost, the exit task runs. That is waiting for the delay time you set and after that turning off bluetooth.

The if-statement is to ensure we don't turn off bluetooth if it is connected to anything after the delay has passed. Since the profile will be activated once again when bluetooth is connected again.

I found this way the easiest since there is no variable to test if bluetooth is connected directly.