Set Bluetooth off if no device connected (after an interval)

Search This thread

g0d0fmischief

Senior Member
Aug 15, 2010
60
7
This would seem to have been an extremely simple thing and i've even found a place on the wiki where it had a downloadable profile that would do this. The newer versions of Tasker don't allow for import of those profiles it doesn't seem, if it doesn't I am not doing it right. I've made some profiles and tasks to this point, simple stuff, like turn wifi on at home or work, and set display to auto rotate (orientation) for certain apps. I'm still way n00b with tasker. I would like to use tasker to turn off my bluetooth if it goes a period of time without a device connected. Can someone do a noob walk through of how to do this?

Thanks in advance.
 

ktmom

Retired Forum Moderator
Apr 22, 2015
5,176
3,387
Deep Space Station K7
Create a profile -> State -> BT Connected (leave everything alone except tic invert)


Create enter task
Task -> Wait (set the delay you want)
Net -> Bluetooth -> Set [Off]


------ edit --------

The above is literally what you asked for. However, assuming the delay is to ensure nothing has connected to BT before shutting it off, you might want to add an IF statement to the final action. Such as:

"%PACTIVE ~ *[Profile name]*

[Profile name] should be replaced with the actual name of this profile. Leave the * in place though.

A final thought is by adding a second context to the profile:

State -> net -> BT status (on)

This profile will be active only when BT is on.
 
Last edited:

niyonsv

Senior Member
Hi, I think I did the same thing but it didn't work. The Bluetooth just stays On and doesn't disconnect after 20 seconds. The profile in the Tasker app shows green color after turning on the Blutooth.

Pasting the profile from xml. Can you please check if there's any error?

PHP:
<TaskerData sr="" dvi="1" tv="5.0u5m">
	<Profile sr="prof41" ve="2">
		<cdate>1504900913492</cdate>
		<edate>1504902100965</edate>
		<id>41</id>
		<mid0>42</mid0>
		<nme>Bluetooth Auto Off</nme>
		<State sr="con0" ve="2">
			<code>3</code>
			<pin>true</pin>
			<Str sr="arg0" ve="3"/>
			<Str sr="arg1" ve="3"/>
		</State>
		<State sr="con1" ve="2">
			<code>2</code>
			<Int sr="arg0" val="1"/>
		</State>
	</Profile>
	<Task sr="task42">
		<cdate>1504900934895</cdate>
		<edate>1504902039267</edate>
		<id>42</id>
		<nme>BT Disconnected</nme>
		<Action sr="act0" ve="7">
			<code>30</code>
			<Int sr="arg0" val="0"/>
			<Int sr="arg1" val="20"/>
			<Int sr="arg2" val="0"/>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>294</code>
			<Int sr="arg0" val="0"/>
			<ConditionList sr="if">
				<Condition sr="c0" ve="3">
					<lhs>%PACTIVE</lhs>
					<op>2</op>
					<rhs>Bluetooth Auto Off</rhs>
				</Condition>
			</ConditionList>
		</Action>
	</Task>
</TaskerData>
 

g0d0fmischief

Senior Member
Aug 15, 2010
60
7
Create a profile -> State -> BT Connected (leave everything alone except tic invert)


Create enter task
Task -> Wait (set the delay you want)
Net -> Bluetooth -> Set [Off]


------ edit --------

The above is literally what you asked for. However, assuming the delay is to ensure nothing has connected to BT before shutting it off, you might want to add an IF statement to the final action. Such as:

"%PACTIVE ~ *[Profile name]*

[Profile name] should be replaced with the actual name of this profile. Leave the * in place though.

A final thought is by adding a second context to the profile:

State -> net -> BT status (on)

This profile will be active only when BT is on.

Awesome, I'll give this a shot in just a bit thank you
 
  • Like
Reactions: Shezkah

niyonsv

Senior Member
How about selecting the profile with a long press, "exporting -> description to clipboard" then pasting that here.

Profile: Bluetooth Auto Off (41)
State: Not BT Connected [ Name:* Address:* ]
State: BT Status [ Status:eek:n ]
Enter: BT Disconnected (42)
A1: Wait [ MS:0 Seconds:20 Minutes:0 Hours:0 Days:0 ]
A2: Bluetooth [ Set:eek:ff ] If [ %PACTIVE ~ Bluetooth Auto Off ]

Oops, sorry, some texts are converted to emojis.

-----Edit------
Something more; if I manually 'turn off' the Bluetooth, the Tasker automatically 'turns on' it.
 
Last edited:

g0d0fmischief

Senior Member
Aug 15, 2010
60
7
Create a profile -> State -> BT Connected (leave everything alone except tic invert)


Create enter task
Task -> Wait (set the delay you want)
Net -> Bluetooth -> Set [Off]


------ edit --------

The above is literally what you asked for. However, assuming the delay is to ensure nothing has connected to BT before shutting it off, you might want to add an IF statement to the final action. Such as:

"%PACTIVE ~ *[Profile name]*

[Profile name] should be replaced with the actual name of this profile. Leave the * in place though.

A final thought is by adding a second context to the profile:

State -> net -> BT status (on)

This profile will be active only when BT is on.

Without the added contexts you mentioned it just turned the Bluetooth off on a timer, even while it was connected and I was talking on the phone. With the two added contexts it seems to work perfect

Correction, it doesn't work at all now it would seem. Hmm. I'll try to make it again tomorrow.

Edit; yeah I've went through it and tried over and over neither seems to work. Even having ticed invert, it basically just turns it off on a timer. No matter what else. Hmm so close. I can post screen shots of how I've done it if you want to see
 
Last edited:
  • Like
Reactions: Shezkah

letmedanz

Senior Member
Aug 26, 2010
2,833
4,207
Bangalore
Google Pixel 7 Pro
I agree for some reason this seems to have stopped working.
Had this simple profile that would turn off after a few minutes of disconnecting from my car blue tooth.
Was using a variable once connected to specific bt
Perhaps after the update something changed? Weird
 
  • Like
Reactions: Shezkah

Crepusculi

Senior Member
Nov 6, 2011
62
5
From what I can tell, it is the check for the variable %BLUE ~ "on" is what is causing bluetooth to turn back on. FWIW, I tried making a similar profile that would do the same with WiFi, and that's how I discovered the bug. I'm trying to find a way to trigger a different profile based on an event of bluetooth turning on, and then that would turn on the "Main" profile we had before. I'll update if I figure it out.
 
  • Like
Reactions: Shezkah

yogioz

Senior Member
Aug 2, 2005
99
18
Canberra
I use this to cycle Bluetooth...XML is:

<TaskerData sr="" dvi="1" tv="5.6">
<Profile sr="prof2" ve="2">
<cdate>1542882243077</cdate>
<edate>1554470940795</edate>
<flags>16</flags>
<id>2</id>
<mid0>3</mid0>
<nme>Cycle Bluetooth</nme>
<Share sr="Share">
<d>Cycle Bluetooth</d>
<t></t>
</Share>
<State sr="con0" ve="2">
<cname>BT On</cname>
<code>3</code>
<pin>true</pin>
<Str sr="arg0" ve="3">Cycle Bluetooth</Str>
<Str sr="arg1" ve="3"/>
</State>
</Profile>
<Task sr="task3">
<cdate>1542882243062</cdate>
<edate>1554470940795</edate>
<id>3</id>
<rty>1</rty>
<Action sr="act0" ve="7">
<code>37</code>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%BLUE</lhs>
<op>2</op>
<rhs>Off</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act1" ve="7">
<code>30</code>
<Int sr="arg0" val="0"/>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="5"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
</Action>
<Action sr="act2" ve="7">
<code>294</code>
<Int sr="arg0" val="1"/>
</Action>
<Action sr="act3" ve="7">
<code>30</code>
<Int sr="arg0" val="0"/>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="10"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
</Action>
<Action sr="act4" ve="7">
<code>294</code>
<Int sr="arg0" val="0"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%PACTIVE</lhs>
<op>2</op>
<rhs>*Auto Off Unpaired Bluetooth*</rhs>
</Condition>
</ConditionList>
</Action>
</Task>
</TaskerData>


Sent from my Pixel
 
Last edited:
  • Like
Reactions: altafharsh60

Shezkah

New member
Oct 22, 2019
1
0
I really appreciate all your helpful responses to this question but unfortunately it seems not to be working with the current Tasker version. Does anyone have an updated tip to make this work? Forgetting to disable Bluetooth is the bane of my battery :confused:
 

ktmom

Retired Forum Moderator
Apr 22, 2015
5,176
3,387
Deep Space Station K7
I really appreciate all your helpful responses to this question but unfortunately it seems not to be working with the current Tasker version. Does anyone have an updated tip to make this work? Forgetting to disable Bluetooth is the bane of my battery :confused:

It would be easier to help you troubleshoot your current profile. Please post the description and what tasker version and device/OS. All of these can affect how a task performs.
 

markvvaals

New member
Sep 25, 2011
2
7
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.
 
Last edited:

markvvaals

New member
Sep 25, 2011
2
7
It most certainly did. Thanks so much. Though, it only seemed to work for me when I removed the asterisks and commas from BT Connected.

From my understanding PACTIVE checks a comma separated list of profile names. In my testing it does not work when only the profile name is entered, thus without asterisks and comma's. The comma's are there to make sure you check the full name of the profile, preventing a false positive.
Note that it's the comma's surround the profile name, and starting and ending with an asterisk.
 

allsyed

Member
Aug 25, 2016
6
1
Hyderabad
ASUS ROG Phone 5
Here is what I am using

Code:
<TaskerData sr="" dvi="1" tv="5.10">
	<Profile sr="prof2" ve="2">
		<cdate>1602032723274</cdate>
		<clp>true</clp>
		<edate>1602033015010</edate>
		<flags>8</flags>
		<id>2</id>
		<mid0>3</mid0>
		<nme>Turn Off BT</nme>
		<State sr="con0" ve="2">
			<code>3</code>
			<pin>true</pin>
			<Str sr="arg0" ve="3"/>
			<Str sr="arg1" ve="3"/>
		</State>
		<State sr="con1" ve="2">
			<code>2</code>
			<Int sr="arg0" val="1"/>
		</State>
	</Profile>
	<Task sr="task3">
		<cdate>1602032744159</cdate>
		<edate>1602032794555</edate>
		<id>3</id>
		<nme>Turn Off BT</nme>
		<Action sr="act0" ve="7">
			<code>30</code>
			<Int sr="arg0" val="0"/>
			<Int sr="arg1" val="0"/>
			<Int sr="arg2" val="5"/>
			<Int sr="arg3" val="0"/>
			<Int sr="arg4" val="0"/>
		</Action>
		<Action sr="act1" ve="7">
			<code>294</code>
			<Int sr="arg0" val="0"/>
		</Action>
	</Task>
</TaskerData>
 

cyanGalaxy

Senior Member
Dec 30, 2018
794
393
25
Germany
Sony Xperia M
Moto G4
...
The steps below walk you through the setup of this profile
5PUb.gif
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 7
    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.
    6
    Create a profile -> State -> BT Connected (leave everything alone except tic invert)


    Create enter task
    Task -> Wait (set the delay you want)
    Net -> Bluetooth -> Set [Off]


    ------ edit --------

    The above is literally what you asked for. However, assuming the delay is to ensure nothing has connected to BT before shutting it off, you might want to add an IF statement to the final action. Such as:

    "%PACTIVE ~ *[Profile name]*

    [Profile name] should be replaced with the actual name of this profile. Leave the * in place though.

    A final thought is by adding a second context to the profile:

    State -> net -> BT status (on)

    This profile will be active only when BT is on.
    5
    Long press on the profile name then hit the gear icon then deselect "restore settings"
    3
    How about selecting the profile with a long press, "exporting -> description to clipboard" then pasting that here.

    Profile: Bluetooth Auto Off (41)
    State: Not BT Connected [ Name:* Address:* ]
    State: BT Status [ Status:eek:n ]
    Enter: BT Disconnected (42)
    A1: Wait [ MS:0 Seconds:20 Minutes:0 Hours:0 Days:0 ]
    A2: Bluetooth [ Set:eek:ff ] If [ %PACTIVE ~ Bluetooth Auto Off ]

    Oops, sorry, some texts are converted to emojis.

    -----Edit------
    Something more; if I manually 'turn off' the Bluetooth, the Tasker automatically 'turns on' it.
    2
    This would seem to have been an extremely simple thing and i've even found a place on the wiki where it had a downloadable profile that would do this. The newer versions of Tasker don't allow for import of those profiles it doesn't seem, if it doesn't I am not doing it right. I've made some profiles and tasks to this point, simple stuff, like turn wifi on at home or work, and set display to auto rotate (orientation) for certain apps. I'm still way n00b with tasker. I would like to use tasker to turn off my bluetooth if it goes a period of time without a device connected. Can someone do a noob walk through of how to do this?

    Thanks in advance.