In the age of IoT (Internet of Things), it’s possible to repurpose everyday devices into powerful home automation tools. One of the most underestimated peripherals in this context is the PC mouse—both classic and gaming variants. With the right modifications and integrations, a mouse can be transformed into a universal smart controller for:
- TV and media center control
- Fenestration management (automated windows and doors)
- Smart lighting
- Air conditioner control
This article outlines how to technically modify and integrate a PC mouse into a multi-functional smart home remote.
🛠 What You’ll Need
Hardware:
- Wired/wireless USB PC mouse (preferably gaming with extra buttons)
- Raspberry Pi (Zero, 3B+, or 4)
- USB OTG adapter (for USB mice)
- IR LED + IR receiver module
- 2-channel or 4-channel relay module
- Servo motors or linear actuators (for window/door actuation)
- Smart light bulbs or relay-controlled lighting
- Wi-Fi enabled smart plug (optional for AC)
- Power supply (5V 3A for Pi, 12V for actuators)
Software:
- Python 3 (on Raspberry Pi)
evdev
library for mouse event captureLIRC
for IR controlRPi.GPIO
orgpiozero
for relay controlHome Assistant
(optional for integration)- MQTT (optional for wireless home automation)
🧠 Step 1: Connect and Read Mouse Events
Using Python and the evdev
library, the Raspberry Pi can read raw inputs from the mouse.
pip3 install evdev
from evdev import InputDevice, categorize, ecodes
mouse = InputDevice('/dev/input/eventX') # Replace X with your mouse event number
for event in mouse.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))
Map specific mouse buttons or gestures (like left-click, scroll up, side button) to smart actions.
📺 Step 2: Turn Mouse into TV Remote
Use the LIRC library to emit IR signals via an IR LED connected to your Pi.
- Install LIRC:
sudo apt-get install lirc
- Configure
/etc/lirc/lirc_options.conf
and/boot/config.txt
for GPIO IR out. - Record your TV remote with
irrecord
, name it e.g.tv_remote.conf
. - Emit signal via button press:
import os
def tv_power_toggle():
os.system("irsend SEND_ONCE tv_remote KEY_POWER")
Map this to a button like scroll-click or side button.
🪟 Step 3: Fenestration Management (Windows and Doors)
Attach servo motors or linear actuators to windows or sliding doors. Connect these to a relay module or motor driver board.
GPIO Trigger Example:
import RPi.GPIO as GPIO
import time
RELAY_PIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
def open_window():
GPIO.output(RELAY_PIN, GPIO.HIGH)
time.sleep(2) # Duration to fully open
GPIO.output(RELAY_PIN, GPIO.LOW)
def close_window():
GPIO.output(RELAY_PIN, GPIO.HIGH)
time.sleep(2)
GPIO.output(RELAY_PIN, GPIO.LOW)
Assign “open” to left scroll and “close” to right scroll, for example.
💡 Step 4: Indoor Light Control
For smart bulbs (e.g., Philips Hue, Tuya), integrate using APIs or Home Assistant via MQTT.
For relay-controlled lights:
LIGHT_PIN = 22
GPIO.setup(LIGHT_PIN, GPIO.OUT)
def toggle_light():
GPIO.output(LIGHT_PIN, not GPIO.input(LIGHT_PIN))
Map this function to the right mouse button or a gaming macro key.
❄️ Step 5: Air Conditioner Management
IR-Controlled AC
Use LIRC again, as in the TV remote, but with AC-specific IR codes (commonly used by LG, Daikin, etc.).
def ac_toggle():
os.system("irsend SEND_ONCE ac_remote KEY_POWER")
Smart Plug AC Integration
Control via MQTT or API if plugged into a smart plug.
🧬 Optional: Full Smart Home Integration via MQTT
Install Mosquitto MQTT broker on your Pi and have it relay commands to other smart devices:
sudo apt install mosquitto mosquitto-clients
Python MQTT Example:
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("home/lights/livingroom", "toggle")
Use this method for more scalable automation and remote control.
🧠 Button Mapping Strategy
Mouse Input | Function |
---|---|
Left-click | Open windows |
Right-click | Close windows |
Scroll click | Toggle TV power |
Side Button 1 | Toggle AC |
Side Button 2 | Toggle indoor lights |
Scroll up | Increase AC temp / brightness |
Scroll down | Decrease AC temp / brightness |
For gaming mice, use the extra macro buttons for complex scene triggers like “Sleep Mode” or “Leave Home”.
🧩 Future Extensions
- Integrate voice assistant triggers via mouse buttons
- Add gesture recognition using mouse movement
- Expand to control smart blinds and garage doors
- Mobile app to mirror mouse control remotely
🏁 Conclusion
With just a PC mouse and a Raspberry Pi, you can build a cost-effective, highly customizable universal smart home controller. Whether you want to replace your TV remote, automate your windows, or manage your home’s climate—all it takes is a little creativity, some GPIO magic, and a few lines of Python.