Automatically turn off your Raspberry Pi's display when your PC goes offline, and turn it back on when the PC returns. The RPi keeps running normally - only the screen powers off to save energy.
Perfect for home servers, development setups, or any Raspberry Pi with an attached display that doesn't need to be on 24/7.
- 🔌 Automatic display control - Screen off when PC is unreachable, on when PC returns
- ⚡ Power saving - Saves 2-30W depending on your display
- 🖥️ Multiple display protocols - Supports X11, Wayland, and Raspberry Pi hardware control
- 🌐 Network-based monitoring - Uses ping to detect PC availability
- ⏱️ Configurable timeout - Set how long to wait before turning off display
- 🔄 Auto-start on boot - Runs as systemd service
- 📝 Detailed logging - Track all state changes
- 🖥️ Multi-PC support - Monitor multiple computers (optional)
- PC online → Display stays ON
- PC offline for X seconds → Display turns OFF
- PC comes back online → Display turns ON
The Raspberry Pi continues running all services, processes, and network connections. Only the display output is controlled.
- Raspberry Pi (any model with network connectivity)
- Python 3.7+
- Network connection (Ethernet or WiFi)
- One of the following display control methods:
- Wayland:
wlopm(recommended for modern setups) - X11:
xset - Raspberry Pi OS:
vcgencmd(legacy)
- Wayland:
# Download the script
wget https://raw.githubusercontent.com/YOUR_REPO/display_monitor.py
wget https://raw.githubusercontent.com/YOUR_REPO/display-monitor.service
# Or clone the repository
git clone https://github.com/YOUR_REPO/rpi-display-monitor.git
cd rpi-display-monitorFor Wayland (recommended):
sudo apt-get update
sudo apt-get install wlopmFor X11:
sudo apt-get install x11-xserver-utilsFor Raspberry Pi hardware control:
# Already included in Raspberry Pi OSEdit display_monitor.py and set your PC's IP address:
PC_IP = "192.168.1.XXX" # Your PC's IP address
PING_INTERVAL = 5 # Seconds between pings
TIMEOUT_THRESHOLD = 20 # Seconds before turning off display
DISPLAY_OFF_METHOD = "wlopm" # Choose: "wlopm", "xset", or "vcgencmd"Important: Set your PC to use a static IP address (either via DHCP reservation in your router or static IP configuration).
# Run manually to test
python3 display_monitor.pyTurn off your PC and wait - after the timeout, your display should turn off!
Press Ctrl+C to stop.
# Copy files to correct locations
sudo cp display_monitor.py /home/$USER/display_monitor.py
sudo chmod +x /home/$USER/display_monitor.py
# Edit the service file
nano display-monitor.service
# Update User= to your username
# Update ExecStart= path if needed
# Install service
sudo cp display-monitor.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable display-monitor.service
sudo systemctl start display-monitor.service# Check service status
sudo systemctl status display-monitor.service
# Watch logs
tail -f ~/.display_monitor.log
# Or use journalctl
sudo journalctl -u display-monitor.service -f# Your PC's IP address (required)
PC_IP = "192.168.1.100"
# How often to ping the PC (seconds)
PING_INTERVAL = 5
# How long to wait before turning off display (seconds)
TIMEOUT_THRESHOLD = 20
# Display control method
DISPLAY_OFF_METHOD = "wlopm" # Options: "wlopm", "xset", "vcgencmd"Turn off display only if ALL monitored PCs are down:
MONITOR_MULTIPLE_PCS = True
PC_IPS = ["192.168.1.100", "192.168.1.101", "192.168.1.102"]Choose based on your setup:
| Method | When to Use | Requirements |
|---|---|---|
wlopm |
Wayland desktop | sudo apt-get install wlopm |
xset |
X11 desktop | sudo apt-get install x11-xserver-utils |
vcgencmd |
Raspberry Pi OS (legacy) | Built-in |
How to check what you're using:
echo $XDG_SESSION_TYPE
# Output: "wayland" or "x11"The systemd service file needs to be configured for your environment:
[Service]
User=YOUR_USERNAME
Environment="WAYLAND_DISPLAY=wayland-0"
Environment="XDG_RUNTIME_DIR=/run/user/1000"[Service]
User=YOUR_USERNAME
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/YOUR_USERNAME/.Xauthority"Finding your user ID:
id -u
# Usually 1000 for the first userCheck which method works manually:
# For Wayland
export WAYLAND_DISPLAY=wayland-0
export XDG_RUNTIME_DIR=/run/user/$(id -u)
wlopm --off '*'
# Wait 2 seconds
wlopm --on '*'
# For X11
export DISPLAY=:0
xset s activate
xset dpms force off
# Wait 2 seconds
xset dpms force on
# For Raspberry Pi
vcgencmd display_power 0
# Wait 2 seconds
vcgencmd display_power 1Whichever works, use that as your DISPLAY_OFF_METHOD.
Set a static IP in your router:
- Log into your router (usually http://192.168.1.1)
- Find DHCP Settings or Address Reservation
- Reserve your PC's current IP for its MAC address
Or set a static IP on your PC directly.
# Check logs
sudo journalctl -u display-monitor.service -n 50
# Common issues:
# - Wrong username in service file
# - Wrong file path in ExecStart
# - Missing environment variables for Wayland/X11# Make script executable
chmod +x /home/$USER/display_monitor.py
# Check service user matches your username
sudo nano /etc/systemd/system/display-monitor.service
# Update User=YOUR_USERNAME# Test if you can ping your PC
ping -c 5 YOUR_PC_IP
# Check firewall allows ICMP
# Windows: Windows Defender Firewall → Allow app
# Linux: sudo ufw allow from 192.168.1.0/24More tolerant of network hiccups:
TIMEOUT_THRESHOLD = 120 # Wait 2 minutesFaster response:
TIMEOUT_THRESHOLD = 10 # Only 10 seconds
PING_INTERVAL = 2 # Ping every 2 secondsChange log location:
log_file = '/var/log/display_monitor.log' # System-wide log
# or
log_file = os.path.join(os.path.expanduser('~'), 'my_custom.log')# Stop temporarily
sudo systemctl stop display-monitor.service
# Start
sudo systemctl start display-monitor.service
# Restart (after config changes)
sudo systemctl restart display-monitor.service
# Disable auto-start
sudo systemctl disable display-monitor.serviceTypical power consumption with display off:
| Display Type | Power Saved |
|---|---|
| 24" HDMI Monitor | 15-30W |
| Official RPi Display | 2-5W |
| Small HDMI Display | 5-10W |
Raspberry Pi itself continues running at normal ~5W power consumption.
| Feature | Display Off (This Tool) | Full Suspend |
|---|---|---|
| RPi still running | ✅ Yes | ❌ No |
| SSH accessible | ✅ Yes | ❌ No |
| Services running | ✅ Yes | ❌ No |
| Power saved | ~2-30W | ~4.5W |
| Wake time | Instant | 1-2 seconds |
| Complexity | Simple | Medium |
- Home server with display - Turn off screen when you're not at your desk
- Development setup - Save power when your main PC is off
- Media center - Display off when not actively watching
- Pi-hole with monitor - Screen only on when needed
- Multi-user environment - Display stays on if any user's PC is online
Q: Does this shut down the Raspberry Pi?
A: No, only the display turns off. The RPi keeps running everything normally.
Q: Can I wake the display manually?
A: Yes, just turn on your PC or move your mouse/press a key (depending on display method).
Q: What if my network is unreliable?
A: Increase TIMEOUT_THRESHOLD to make it less sensitive to temporary network issues.
Q: Can I use this with Wake-on-LAN?
A: Yes! The display will turn on when your PC sends a wake signal.
Q: Does it work over WiFi?
A: Yes, both the PC and RPi can use WiFi.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
MIT License - Feel free to use and modify as needed.
Created for Raspberry Pi enthusiasts who want smart display power management without system suspension.
If you encounter issues:
- Check the troubleshooting section above
- Review logs:
tail -f ~/.display_monitor.log - Open an issue with your log output and configuration
Star this repo if you find it useful! ⭐