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.
- Linux system.
evtest
utility installed.- A Bluetooth game controller.
- Clone or download this repository.
- Ensure
evtest
is installed :
sudo apt install evtest
sudo dnf install evtest
sudo pacman -S evtest
Edit the script to configure the following parameters:
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"
Specify the idle timeout in seconds:
IDLE_LIMIT=300
Define the deadzone for analog stick drift:
DEADZONE_THRESHOLD=150
The script will:
- Detect your controller's input event device automatically.
- Monitor input activity and turn off the controller after the specified idle time.
Run the script manually with root privileges:
sudo ./controlleridle.sh
- 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
- Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
- Enable the service to start automatically at boot:
sudo systemctl enable controlleridle.service
- Start the service immediately:
sudo systemctl start controlleridle.service
- Verify that the service is running:
sudo systemctl status controlleridle.service
For hyprland, use the following in your hyprland.conf
to run at startup.
exec-once = /path/to/controlleridle.sh
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.
- Minor analog stick drift could prevent the controller from timing out if the deadzone threshold is too low.