Skip to content

Shell script to handle bluetooth controller idle timout using evtest utility

Notifications You must be signed in to change notification settings

AbrarAbe/controlleridle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Bluetooth Controller Idle Timeout Script

This script monitors input events from a Bluetooth game controller on a Linux system and powers off the controller after a specified period of inactivity. It uses the evtest utility to detect events and applies a deadzone to analog inputs to avoid unintended disconnections due to minor stick drift.

Features :

  • Detects input events from a specified Bluetooth controller.
  • Automatically powers off the controller after a configurable idle timeout.
  • Ignores minor stick drift with configurable deadzone thresholds.
  • Dynamically finds the input event device for the controller by name.

Requirements

  • Linux system.
  • evtest utility installed.
  • A Bluetooth game controller.

Installation

  1. Clone or download this repository.
  2. Ensure evtest is installed :

Ubuntu

sudo apt install evtest

Fedora

sudo dnf install evtest

Arch

sudo pacman -S evtest

Configuration

Edit the script to configure the following parameters:

Controller Name

List input devices by name :

grep -E 'Name' /proc/bus/input/devices

Example output :

N: Name="Power Button"
N: Name="Asus Wireless Radio Control"
N: Name="HDA Intel PCH Headphone"
N: Name="PLAYSTATION(R)3 Controller Motion Sensors"
N: Name="PLAYSTATION(R)3 Controller"

Look for the Name= field corresponding to your controller.

Set the name of your controller as shown in /proc/bus/input/devices:

CONTROLLER_NAME="PLAYSTATION(R)3 Controller"

Idle Timeout

Specify the idle timeout in seconds:

IDLE_LIMIT=300

Deadzone Threshold

Define the deadzone for analog stick drift:

DEADZONE_THRESHOLD=150

Usage

The script will:

  • Detect your controller's input event device automatically.
  • Monitor input activity and turn off the controller after the specified idle time.

Manual Execution

Run the script manually with root privileges:

sudo ./controlleridle.sh

Run at Startup Using systemd

1. Create a Systemd Service File

  • Create a service file for the script:
sudo nano /etc/systemd/system/controlleridle.service
  • Add the following content to the file:
[Unit]
Description=Controller Idle Script - Turns off Bluetooth after inactivity
After=bluetooth.service

[Service]
Type=simple
ExecStart=/path/to/your/script/controlleridle.sh
Restart=always
User=your-username
Group=your-group
WorkingDirectory=/home/your-username

[Install]
WantedBy=multi-user.target

2. Reload systemd Daemon

  • Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload

3. Enable the Service

  • Enable the service to start automatically at boot:
sudo systemctl enable controlleridle.service

4. Start the Service

  • Start the service immediately:
sudo systemctl start controlleridle.service

5. Check Service Status

  • Verify that the service is running:
sudo systemctl status controlleridle.service

Hyprland Spesific

For hyprland, use the following in your hyprland.conf to run at startup.

exec-once = /path/to/controlleridle.sh

Debugging

To see logs from the script, use:

sudo journalctl -u controlleridle.service

If the service fails, ensure the path to the script is correct and matches the ExecStart line in the service file.

Limitations

  • Minor analog stick drift could prevent the controller from timing out if the deadzone threshold is too low.

About

Shell script to handle bluetooth controller idle timout using evtest utility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages