Add this section to your ups.conf:
[laptop-battery]
driver = dummy-ups
port = /var/lib/nut/laptop-battery.dev
desc = "ThinkPad Battery Virtual UPS"
# Optional: set polling interval
# pollinterval = 30Basic configuration (modify as needed):
# Network UPS Tools upsd configuration file
# LISTEN <address> [<port>]
LISTEN 127.0.0.1 3493
LISTEN ::1 3493
# Maximum number of connections
MAXCONN 1024
# Certificate and key files for SSL
# CERTFILE /etc/nut/upsd.pem
# KEYFILE /etc/nut/upsd.keyCreate users for accessing the UPS:
# Network UPS Tools upsd users file
[admin]
password = your_admin_password
actions = SET
instcmds = ALL
upsmon master
[upsmon]
password = your_monitor_password
upsmon masterConfigure the monitoring daemon:
# Network UPS Tools upsmon configuration
# Monitor the laptop battery UPS
MONITOR laptop-battery@localhost 1 upsmon your_monitor_password master
# Shutdown command
SHUTDOWNCMD "/sbin/shutdown -h +0"
# Notification command (optional)
NOTIFYCMD /usr/sbin/upssched
# How long to wait before declaring UPS dead
DEADTIME 15
# Power values
MINSUPPLIES 1
# Notification flags
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL
NOTIFYFLAG BADCOMM SYSLOG+WALL
NOTIFYFLAG COMMOK SYSLOG+WALL
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
# Notification messages
NOTIFYMSG ONLINE "UPS %s: On line power"
NOTIFYMSG ONBATT "UPS %s: On battery"
NOTIFYMSG LOWBATT "UPS %s: Battery is low"
NOTIFYMSG REPLBATT "UPS %s: Battery needs to be replaced"
NOTIFYMSG BADCOMM "UPS %s: Communication failure"
NOTIFYMSG COMMOK "UPS %s: Communication restored"
NOTIFYMSG NOCOMM "UPS %s: Communication lost"
# Run as user
RUN_AS_USER nut
# Poll frequency
POLLFREQ 5
POLLFREQALERT 5
# Hostname for notifications
# HOSTSYNC 15Set the NUT mode:
# Network UPS Tools configuration
# Mode can be: none, standalone, netserver, netclient
MODE=standaloneCreate /etc/systemd/system/laptop-battery-nut.service:
[Unit]
Description=Update Laptop Battery Status for NUT
After=multi-user.target
[Service]
Type=oneshot
User=nut
ExecStart=/usr/local/bin/laptop-battery-to-nut.shCreate /etc/systemd/system/laptop-battery-nut.timer:
[Unit]
Description=Update Laptop Battery Status for NUT every 30 seconds
Requires=laptop-battery-nut.service
[Timer]
OnCalendar=*:*:0/30
Persistent=true
[Install]
WantedBy=timers.target-
Install the script:
sudo cp laptop-battery-to-nut.sh /usr/local/bin/ sudo chmod +x /usr/local/bin/laptop-battery-to-nut.sh sudo chown nut:nut /usr/local/bin/laptop-battery-to-nut.sh
-
Create initial battery data file:
# Ensure the nut user owns the data directory sudo mkdir -p /var/lib/nut sudo chown nut:nut /var/lib/nut sudo chmod 755 /var/lib/nut # Run the script to create initial data sudo -u nut /usr/local/bin/laptop-battery-to-nut.sh
-
Set up systemd timer:
sudo systemctl daemon-reload sudo systemctl enable laptop-battery-nut.timer sudo systemctl start laptop-battery-nut.timer -
Start NUT services:
sudo systemctl enable [email protected] sudo systemctl start [email protected] sudo systemctl enable nut-server.service sudo systemctl start nut-server.service sudo systemctl enable nut-monitor.service sudo systemctl start nut-monitor.service
-
Test the setup:
upsc laptop-battery upsc laptop-battery ups.status upsc laptop-battery battery.charge
- Check logs:
journalctl -u [email protected] - Test script:
sudo -u nut /usr/local/bin/laptop-battery-to-nut.sh - Verify file:
cat /var/lib/nut/laptop-battery.dev - Check permissions: Ensure the
nutuser can read battery information
You can modify the script to:
- Adjust the low battery threshold
- Add temperature monitoring if available
- Customize UPS model/manufacturer names
- Add additional battery metrics
- Support multiple batteries