I love my HBS-730 Bluetooth headphones. They come with all the bells and whistles, heck, even a battery feedback. All good but one little detail: the battery feedback comes in 3 levels HIGH, MEDIUM, LOW. Here is the problem:

  • HIGH – the device just has been charged, has full battery, mode lasts about 10 min
  • MEDIUM – this is where you spend the 99% of you 8h power time
  • LOW – battery about to die, you have literally 5 min to get a cable and start charging

It is entirely possible for me to go for a bike ride with 6 min left on my headphones thinking that I will be ok. The companion app although exist and let you pass through calls, messages etc, has no information about the exact battery level of the headphones. I had enough, time to employ Tasker.  The Bluetooth battery monitor lets you keep track of any Bluetooth device, even if that gadget has no battery indicator whatsoever.

Tasker – Bluetooth battery monitor

screenshot_20161003-121554

[box type=”info”]MADE ON:
Android version: Android 7 (Nougat)
Plugins: none[/box]

Although you can streamline the project quite a bit with plugins, I’m using vanilla Tasker for best compatibility with all Android users. The project consists three profiles. Not all of them are necessary, but they create an application that you can use straight away. The only editing that needs to be done is entering the device name in the Bluetooth battery monitor context.

The project offers you 2 calibrations modes.
You can choose to measure a lifespan of your fully charged device (more accurate). This measurement will be used in the battery life estimation later.
Alternatively, you can enter an estimated value of the battery life in hours and minutes.

The calibration is being done once, then the main profile is enabled. A notification will appear on each connects and disconnects from the Bluetooth device to let you know about the estimated life span.

Headset override

This profile is responsible for opening the calibration scene and making sure the calibration profiles are triggered correctly. Initially, the Bluetooth device had to be off, for calibration to work correctly, now it doesn’t matter.

We are using BT device to set a variable (%BToverride), then to launch a scene unless the profile has been launched before. Once calibration screen is open it won’t run again (%Startup).

[toggle title=”Headset Override”]

Profile: Headset Override 
State: BT Connected [ Name:LG HBS730 Address:* ]
Enter: BT Connection Override 
A1: Variable Set [ Name:%B_Toverride To:1 Do Maths:Off Append:Off ]
A2: Perform Task [ Name:Start Scene Priority:%priority Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ] If [ %Startup !Set ]

Exit: BT Connection Override-
A1: Variable Set [ Name:%B_Toverride To:0 Do Maths:Off Append:Off ]

[/toggle]

Start scene

screenshot_20161003-121454This task creates then opens a scene. It also notifies our headset override profile that set up has been completed (%Startup =1). The scene contains initial elements and few hidden ones that will become visible when selection is done. The calibration button simply closes the scene and enables a calibration profile. Time button hides other elements and enables all hidden UI elements including number pickers for hour and  minute values. These are written  to variables %BTh and %BTm and converted later to  a total number of seconds. The OK button closes the scene and sets the %B_Tmax value – which is the maximum battery life. Please note that %BT and %B_T spelling are intentional as not all variables will be cleared by the reset  button later.

[toggle title=”Start scene”]

Start Scene
A1: Create Scene [ Name:BT Start ] If [ %Startup !Set ]
A2: Show Scene [ Name:BT Start Display As:Dialog, Dim Behind Heavy Horizontal Position:100 Vertical Position:100 Animation:System Show Exit Button:On Continue Task Immediately:On ] If [ %Startup !Set ]
A3: Variable Set [ Name:%Startup To:1 Do Maths:Off Append:Off ]

[/toggle]

BT calibration

This mode will measure how long your device lasts on a single charge. Bluetooth battery monitor will use this value to set a correct %B_Tmax. The profile alone is a simplified version of the main profile, all variable referenced have the %BTC prefix to it. Each time your device is disconnected from the mobile a notification is issued that gives you the option to continue measurement if the device is not discharged, or end the calibration if your Bluetooth device run out of power.

When calibration is done the BT measuring done task is executed. It will set the correct %B_Tmax and clear the %BTC related variables. At this point, the main profile becomes activated and the calibration profile is no longer in use.

[toggle title=”BT Calibration”]

Profile: BT Calibration
State: BT Connected [ Name:LG HBS730 Address:* ]
Enter: BTC Connect
A1: Notify Cancel [ Title:BT Battery Warn Not Exist:Off ]
A2: Variable Set [ Name:%BTCstart To:%TIMES Do Maths:Off Append:Off ]

Exit: BTC Disconnect 
A1: Variable Set [ Name:%BTCstop To:%TIMES - %BTCstart Do Maths:On Append:Off ]
A2: Variable Clear [ Name:%BTCstart Pattern Matching:Off ]
A3: Variable Set [ Name:%BTCtotal To:0 Do Maths:Off Append:Off ] If [ %BTCtotal !Set ]
A4: Variable Set [ Name:%BTCtotal To:%BTCtotal+%BTCstop Do Maths:On Append:Off ]
A5: Variable Clear [ Name:%BTCstop Pattern Matching:Off ]
A6: Notify [ Title:BT Battery Text:Would you like to: Icon:hd_device_access_bluetooth_connected Number:0 Permanent:Off Priority:3 Actions:(2) ]

[/toggle]

BT battery MAIN

screenshot_20161003-121705This is the meat of things. When connected, if previous readings are available, a notification will let you know how long your device will live (%btttlchour and %btttlcminute) This values are calculated in a disconnect task and come from %BTttl (time to live) estimation. If the profile is run for the  first time a current time in seconds is measured and set as %BTstart. If a notification has been displayed before it will close within 10 sec.

The actions responsible for calculating minutes and hours from  total seconds value are shared across the connect and disconnect tasks. These are slightly modified for the purpose of displaying a correct message.

To calculate the estimated time to live we have to take into consideration two scenarios:

  • TTL<60 min
  • TTL>60 min

By default system will treat the %BTttl as if was smaller than 60 min and values of %btttlchours/minutes will become overridden in an IF condition should that value was greater than 60. The notification gives us two options. Close, if the Bluetooth device has some battery life in it (close notification) and reset if the battery device needs a charge (clear all %BT variables). The %B_Tmax will be unaffected.

[toggle title=”BT battery MAIN”]

Profile: BT battery MAIN
State: BT Connected [ Name:LG HBS730 Address:* ]
Enter: BT Connect 
Abort Existing Task
A1: Notify Cancel [ Title:BT Battery Warn Not Exist:Off ]
A2: Variable Set [ Name:%btttlc To:ceil(%BTttl/60) Do Maths:On Append:Off ] If [ %BTttl Set ]
A3: Variable Set [ Name:%btttlchour To:0 Do Maths:Off Append:Off ]
A4: Variable Set [ Name:%btttlcminute To:%btttlc Do Maths:Off Append:Off ]
A5: If [ %btttlc > 60 ]
A6: Variable Set [ Name:%btttlcminute To:(%btttlc)%60 Do Maths:On Append:Off ]
A7: Variable Set [ Name:%btttlchour To:ceil((%btttlc)/60) Do Maths:On Append:Off ]
A8: End If
A9: Notify [ Title:BT Battery Text:You have %btttlchour H %btttlcminute min left Icon:hd_device_access_bluetooth_connected Number:1 Permanent:Off Priority:1 ] If [ %BTttl Set ]
A10: Variable Set [ Name:%BTstart To:%TIMES Do Maths:Off Append:Off ]
A11: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A12: Notify Cancel [ Title:BT Battery Warn Not Exist:Off ]

Exit: BT Disconnect 
A1: Variable Set [ Name:%BTstop To:%TIMES - %BTstart Do Maths:On Append:Off ]
A2: Variable Clear [ Name:%BTstart Pattern Matching:Off ]
A3: Variable Set [ Name:%BTtotal To:0 Do Maths:Off Append:Off ] If [ %BTtotal !Set ]
A4: Variable Set [ Name:%BTtotal To:%BTtotal+%BTstop Do Maths:On Append:Off ]
A5: Variable Clear [ Name:%BTstop Pattern Matching:Off ]
A6: Variable Set [ Name:%BTttl To:%B_Tmax-%BTtotal Do Maths:On Append:Off ]
A7: Variable Set [ Name:%btttlc To:ceil(%BTttl/60) Do Maths:On Append:Off ] If [ %BTttl Set ]
A8: Variable Set [ Name:%btttlchour To:0 Do Maths:Off Append:Off ]
A9: Variable Set [ Name:%btttlcminute To:%btttlc Do Maths:Off Append:Off ]
A10: If [ %btttlc > 60 ]
A11: Variable Set [ Name:%btttlcminute To:(%btttlc)%60 Do Maths:On Append:Off ]
A12: Variable Set [ Name:%btttlchour To:ceil((%btttlc)/60) Do Maths:On Append:Off ]
A13: End If
A14: Notify [ Title:BT Battery Text:You have %btttlchour H %btttlcminute min left Icon:hd_device_access_bluetooth_connected Number:1 Permanent:Off Priority:1 Actions:(2) ] If [ %BTttl Set ]

[/toggle]

Calculations

The math behind is simple.

  • Time of disconnect (s) – Time of connect (s) = %BTstop
  • Time in use %BTtotal(s) + %BTstop = %BTtotal
  • Time to live (s) = B_Tmax -%BTtotal

To calculate the seconds into minutes we need two operations. For TTL below 60min we have:

%btttlchour = 0 AND %btttlcminutes = (%btttc)%60 (%btttc is a copy of %BTttl)

For TTL above 60 min:

 %btttlchour = ceil(%btttlc)/60  AND %btttlcminutes = (%btttc)%60 (%btttc is a copy of %BTttl)

Ready files

As usual, you can follow Bluetooth battery monitor tutorial and the video above. In addition to this, you can download the complete file below. You can also consider supporting the website, it starts from 0.99  and it means a lot! Either way happy talking!

[box type=”info”] Ready Project xml file (please remove the underscore from the file name) : bluetooth_battery-prj [/box]

4 COMMENTS

  1. This is exactly what I’ve been looking for, though I seem to be running into some issues getting this to work. I ran the calibration mode for the duration of my battery life, turned off the calibration mode, and when I reconnected the fully charged device, nothing would happened. I looked into how the variables were set, and it looks like %BTCtotal gets cleared (as expected), but %B_Tmax gets set to “%BTCtotal” instead of the contents of %BTCtotal. Not sure how to get around this… but since I only noticed this after running the BT Measures Done task, I don’t know the value to manually set %B_Tmax since it was cleared, and now I’ll need to run the calibration over again.

    Also, not a a big issue, but I noticed the Notify Cancel action under the BT Measures Done task is for “BT battery” and not “BT Battery”, which is preventing it from clearing when pressing the BT battery discharged button.

  2. Hey, I have uploaded new project file last night as someone pointed out the cancel notification issue to me (fixed now) . After calibration has been done, there wont be a notification on connect, only on a disconnect (only the 1st time) as the battery use is not done once connected for the first time after calibration.

    re: issue check in BT Measures Done that A2: is setting %%B_Tmax to %BTCtotal – and A3 is clear %BTC* not other way around

    • A2 of BT Measures Done is setting %B_Tmax to %BTCtotal. Should it be setting %%B_Tmax to %BTCtotal? If that’s the case, I will fix it now, and report back once my battery is drained again.

  3. You dont have to drain the battery to test it.
    %B_Ttotal is time in sec of how long your device will live (you can enter is manually in the vars tab)
    none of the %BTC variables should be filled after calibration. Note the %B_Ttotal value and clear all variables. then do 1 min calibration and see if the variable will be done once you press on the notification that calibration is complete. connect the BT device again, wait 10 sec – if you d/c you should see notification with 50 sec left, and same on the next connection.

Comments are closed.