Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Display Power Monitor

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.

Features

  • 🔌 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)

How It Works

  1. PC online → Display stays ON
  2. PC offline for X seconds → Display turns OFF
  3. PC comes back online → Display turns ON

The Raspberry Pi continues running all services, processes, and network connections. Only the display output is controlled.

Requirements

  • 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)

Installation

1. Clone or Download

# 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-monitor

2. Install Dependencies

For Wayland (recommended):

sudo apt-get update
sudo apt-get install wlopm

For X11:

sudo apt-get install x11-xserver-utils

For Raspberry Pi hardware control:

# Already included in Raspberry Pi OS

3. Configure

Edit 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).

4. Test It

# Run manually to test
python3 display_monitor.py

Turn off your PC and wait - after the timeout, your display should turn off!

Press Ctrl+C to stop.

5. Install as Service

# 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

6. Verify

# 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

Configuration

Basic Settings

# 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"

Monitor Multiple PCs

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"]

Display Control Methods

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"

Service Configuration

The systemd service file needs to be configured for your environment:

For Wayland

[Service]
User=YOUR_USERNAME
Environment="WAYLAND_DISPLAY=wayland-0"
Environment="XDG_RUNTIME_DIR=/run/user/1000"

For X11

[Service]
User=YOUR_USERNAME
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/YOUR_USERNAME/.Xauthority"

Finding your user ID:

id -u
# Usually 1000 for the first user

Troubleshooting

Display doesn't turn off

Check 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 1

Whichever works, use that as your DISPLAY_OFF_METHOD.

PC IP keeps changing

Set a static IP in your router:

  1. Log into your router (usually http://192.168.1.1)
  2. Find DHCP Settings or Address Reservation
  3. Reserve your PC's current IP for its MAC address

Or set a static IP on your PC directly.

Service fails to start

# 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

Permission errors

# 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

Network issues

# 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/24

Advanced Usage

Adjust Sensitivity

More tolerant of network hiccups:

TIMEOUT_THRESHOLD = 120  # Wait 2 minutes

Faster response:

TIMEOUT_THRESHOLD = 10   # Only 10 seconds
PING_INTERVAL = 2        # Ping every 2 seconds

Custom Logging

Change 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/Start Service

# 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.service

Power Savings

Typical 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.

Comparison: Display Off vs Full Suspend

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

Use Cases

  • 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

FAQ

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.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

License

MIT License - Feel free to use and modify as needed.

Credits

Created for Raspberry Pi enthusiasts who want smart display power management without system suspension.

Support

If you encounter issues:

  1. Check the troubleshooting section above
  2. Review logs: tail -f ~/.display_monitor.log
  3. Open an issue with your log output and configuration

Star this repo if you find it useful! ⭐

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages