How to Automate Bluetooth Tasks with Termux

Automate Bluetooth tasks with Termux and take control of your Android. Save time, skip taps, and unlock new levels of efficiency—FOSS-style.

Calista automating her Bluetooth connections with Termux while commuting through Manila—because efficiency doesn’t wait.

Bluetooth tasks with Termux changed how I handle my connections—no more manual toggles.

I used to waste five to ten minutes a day fumbling through Bluetooth menus—connecting headphones, switching to car audio, forgetting to turn it off again.

Multiply that over a week, and you’re looking at hours lost to button taps and swipes. That’s when I discovered the power of Bluetooth tasks with Termux—and everything changed.

In the spirit of FOSS, I set out to automate these mundane Bluetooth interactions using nothing but a terminal emulator, some shell scripts, and the mighty Termux. No root, no bloatware, just pure command-line magic.

If you’ve ever wished your Android could “just do it” when you walk into your room or start your car, you’re about to meet your new favorite workflow.

Let’s build something powerful, local, and open. Keep reading.

⚠️ Disclaimer:
The steps outlined in this article were based on my personal setup and were working at the time of writing. Due to the ever-changing nature of Android, Termux, and package support, your experience may vary. Termux has limited or no native support for certain hardware features like Bluetooth, depending on your device and Android version. Use these instructions as a reference, not a guarantee. I publish these guides to document my own experiments and findings — always verify against your own environment.

How Bluetooth Works on Android (Without Root)

Before we automate Bluetooth tasks with Termux, it helps to understand what’s going on behind the scenes. On Android, Bluetooth is managed by system services that require elevated permissions to control directly. Without root, you won’t be able to access everything, but thanks to the Termux:API add-on and Activity Manager (am) commands, we can interact with many core functions safely.

For example, am start allows us to launch Bluetooth settings or even simulate taps, while svc bluetooth enable can toggle Bluetooth on and off. These aren’t Termux-specific—they’re built into Android—but Termux gives us a programmable terminal interface to string them together in powerful ways.

· · ─ ·𖥸· ─ · ·

Getting Started: Installing Termux and Required Tools

Before diving into Bluetooth tasks with Termux, let’s set up your environment. This guide assumes you’re working with an Android device that doesn’t require root access—just your thumbs, your brain, and a love for open-source tools.

Prerequisites

Before you start automating Bluetooth tasks with Termux, ensure you have the following:

  • An Android device with Bluetooth capability.
  • Termux installed from the Google Play Store or F-Droid.
  • Basic familiarity with using Termux and shell scripting.

Step 1: Install Termux

To begin automating Bluetooth tasks with Termux, you need Termux installed. If you haven’t done this yet:

  1. Open the Google Play Store or F-Droid.
  2. Search for Termux.
  3. Install and open the app.

Termux provides a Linux environment that’s essential for scripting and automating tasks on your Android device.

Step 2: Update Termux Packages

Updating Termux packages ensures that you have the latest tools and security patches. Run the following command in Termux:

pkg update && pkg upgrade

This prepares your environment for installing additional tools needed for Bluetooth automation.

Step 3: Install Required Tools

To automate Bluetooth tasks with Termux, you need to install some essential tools. Start by installing bluez and blueman:

pkg install bluez blueman

bluez provides Bluetooth management tools, and blueman offers a graphical Bluetooth manager.

Step 4: Install and Configure bluez

bluez is a Bluetooth protocol stack for Linux that includes utilities to manage Bluetooth devices. To install and configure bluez, use the following commands:

pkg install bluez

Configure bluez to suit your automation needs. For example, you might need to set up Bluetooth permissions and configurations in Termux.

Step 5: Automate Bluetooth Tasks with Scripts

Now you can create scripts to automate various Bluetooth tasks. For instance, you can write a script to turn Bluetooth on or off, connect to a specific device, or scan for nearby devices. Here’s an example script to turn Bluetooth on:

#!/data/data/com.termux/files/usr/bin/bash
# Script to turn Bluetooth on
bluetoothctl power on

Save this script as bt_on.sh and make it executable:

chmod +x bt_on.sh

Similarly, you can create scripts for other Bluetooth tasks, such as connecting to devices or handling Bluetooth profiles.

Step 6: Create and Schedule Scripts

To run your Bluetooth automation scripts at specific times or intervals, you can use cron or Termux:Tasker:

Using cron:

Install cronie for scheduling tasks:

pkg install cronie 

Edit the cron jobs file:

crontab -e 

Add a cron job entry to run your script at a desired time. For example, to run bt_on.sh every day at 8 AM:

8 * * * /data/data/com.termux/files/home/bt_on.sh

Using Termux:Tasker: Integrate with Tasker to schedule and manage tasks more visually.

Step 7: Testing Your Automation

Test your automation scripts to ensure they work as expected. Run your scripts manually to verify functionality:

./bt_on.sh

Check for any errors and make necessary adjustments to ensure reliable automation of your Bluetooth tasks.

Step 8: Troubleshooting

If you encounter issues while automating Bluetooth tasks with Termux, consider the following troubleshooting steps:

  • Ensure that Bluetooth permissions are correctly configured.
  • Check script permissions and paths.
  • Verify that bluez and other required tools are properly installed.

Refer to Termux and Bluetooth documentation for further assistance if needed.

· · ─ ·𖥸· ─ · ·

What You Can Do with Bluetooth and Termux

With Bluetooth and Termux, you can perform a variety of tasks to automate and manage Bluetooth operations on your Android device:

  1. Turn Bluetooth On/Off:
    • Use scripts to enable or disable Bluetooth on your device.
  2. Connect to Bluetooth Devices:
    • Automate connections to paired Bluetooth devices (e.g., headphones, speakers).
  3. Disconnect Bluetooth Devices:
    • Script disconnections from Bluetooth devices.
  4. Scan for Nearby Bluetooth Devices:
    • Automate the process of scanning for available Bluetooth devices in range.
  5. Pair with New Bluetooth Devices:
    • Automate the pairing process with new devices, including handling pairing requests.
  6. Manage Bluetooth Profiles:
    • Enable or disable specific Bluetooth profiles (e.g., A2DP, HFP).
  7. Retrieve Device Information:
    • Script retrieval of information about paired or nearby Bluetooth devices (e.g., MAC address, device name).
  8. Manage Bluetooth Services:
    • Start or stop Bluetooth-related services and daemons.
  9. Automate Bluetooth File Transfers:
    • Set up scripts to handle file transfers between devices using Bluetooth.
  10. Bluetooth Device Discovery:
    • Automate the process of discovering new Bluetooth devices and logging their details.
  11. Configure Bluetooth Settings:
    • Change Bluetooth settings programmatically (e.g., visibility, discoverability).
  12. Handle Bluetooth Profiles and Services:
    • Enable or disable Bluetooth services such as audio streaming or file transfers.

· · ─ ·𖥸· ─ · ·

Sample Use Cases and Scripts

Script to Turn Bluetooth On/Off:

#!/data/data/com.termux/files/usr/bin/bash 
# Turn Bluetooth on bluetooth
ctl power on

Script to Scan for Nearby Devices:

#!/data/data/com.termux/files/usr/bin/bash
# Scan for Bluetooth devices
bluetoothctl scan on

Script to Connect to a Device:

#!/data/data/com.termux/files/usr/bin/bash
# Connect to a specific device
bluetoothctl connect XX:XX:XX:XX:XX:XX

Script to Disconnect from a Device:

#!/data/data/com.termux/files/usr/bin/bash
# Disconnect from a specific device
bluetoothctl disconnect XX:XX:XX:XX:XX:XX

Script to Check Bluetooth Status:

#!/data/data/com.termux/files/usr/bin/bash
# Check if Bluetooth is on
bluetoothctl show | grep 'Powered: yes'

· · ─ ·𖥸· ─ · ·

Take Control of Your Device

Automate Like a FOSS Pro

In a world full of apps that track and monetize every tap, building your own Bluetooth automations with Termux is an act of digital sovereignty. You’ve seen how simple scripts can save you time, reduce distractions, and streamline your day—all using tools that respect your freedom.

· · ─ ·𖥸· ─ · ·

We’ve only scratched the surface of what’s possible with Bluetooth tasks in Termux. If you found this guide useful or want more tutorials like this, subscribe to my newsletter at samgalope.dev/newsletter. You’ll get fresh tips, exclusive FOSS tools, and automation workflows straight to your inbox.

Let’s build smarter—together.

⚠️ Disclaimer:
The steps outlined in this article were based on my personal setup and were working at the time of writing. Due to the ever-changing nature of Android, Termux, and package support, your experience may vary. Termux has limited or no native support for certain hardware features like Bluetooth, depending on your device and Android version. Use these instructions as a reference, not a guarantee. I publish these guides to document my own experiments and findings — always verify against your own environment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments (

)

  1. Marcello Belli

    I get an error when installing bluez and blueman:

    ~ $ pkg install bluez
    Checking availability of current mirror:
    [*] https://mirrors.cqupt.edu.cn/termux/termux-main: ok
    Reading package lists… Done
    Building dependency tree… Done
    Reading state information… Done
    E: Unable to locate package bluez

    What is the repo to select?

    Thanks
    M

    1. Sam Galope

      Hello Marcello.

      The error occurs because the bluez package is not available in Termux’s default repositories. However, there are alternative solutions and workarounds you can try.

      You can find the full guide here: Fixing the “Unable to Locate Package BlueZ” Termux Error.

      Best regards.

  2. Weagle

    Helpful info. Fortunate me I discovered your website accidentally, and I am stunned why this twist of fate didn’t happened earlier! I bookmarked it.

    1. Sam Galope

      I’m so glad you found the site, even if by accident! 😊 Thanks for bookmarking it—I’m happy to have you here! If you’re interested, you might also enjoy this article: Reading Potentiometer Values with ESP32 in MicroPython. I appreciate your support, and hope you stick around!

  3. Beckendorf

    Hello! I know this is kinda off topic however I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa? My blog discusses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you might be interested feel free to send me an e-mail. I look forward to hearing from you! Excellent blog by the way!

    1. Sam Galope

      Thanks for reaching out! I appreciate the offer, but for now, I’m focusing on my own content. That said, I’d love to check out your blog! In the meantime, you might enjoy this article: How to Connect an MP3 TF-16P Module to ESP32. Let me know what you think! 😊

  4. McMulen

    Good day! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward to new updates.

    1. Sam Galope

      Hello! I appreciate your interest and kind words about the blog! 😊 I’m not on Twitter at the moment, but I’m always excited to share updates through the blog and other channels. Feel free to keep an eye on my posts, and thanks again for following along!

      If you’re interested, you might enjoy this article: ESP32 Servo Motor Smooth Movement. Thanks for your support! 🙌

  5. Auguste

    Not sure why Bluetooth support has still not been added to Termux or their official Termux API apps!

    Be advised that the main Search Results for this do NOT work as I tried, waste of time: https://www.samgalope.dev/2024/09/09/how-to-automate-bluetooth-tasks-with-termux/

    It seems like he has not tested the solutions he posted / AI auto generated content:
    https://www.samgalope.dev/2024/12/02/fixing-the-unable-to-locate-package-bluez-termux-error-a-step-by-step-guide/

    Don’t bother with these steps as they do not work due to lack of bluetooth support in Termux itself.

    1. Sam Galope

      Hi — appreciate you taking the time to comment. Sorry it didn’t work out for you. Just to be clear: I write these guides based on real troubleshooting I’ve done myself, not AI filler or untested steps. At the time I published those posts, the methods worked on my specific setup.

      That said, Termux is notorious for its inconsistencies — what works on one device or version might fail completely on another, especially with something as finicky as Bluetooth support.

      I’ve gone ahead and added a disclaimer to the article so others are aware. If you do find a reliable workaround, I’m more than happy to update the post and credit you.