A Python script to retrieve UPS status from the APC PowerChute Serial Shutdown for Business web interface. Supports command-line output, JSON, MQTT (Home Assistant), and Zabbix trapper integration.
https://github.com/yo1t/apcget
No external packages required — runs on Python standard library only.
- Python 3.6+
- APC PowerChute Serial Shutdown for Business (port 6547)
zabbix_sender— required only when using the--zabbix-sendoptionmosquitto_puborpaho-mqtt— required only when using the--mqtt-sendoption (either one)
# zabbix_sender
sudo dnf install zabbix-sender # RHEL / Amazon Linux
sudo apt install zabbix-sender # Ubuntu / Debian
brew install zabbix # macOS (Homebrew)
# mosquitto_pub (either mosquitto_pub or paho-mqtt — install one)
sudo dnf install mosquitto # RHEL / Amazon Linux
sudo apt install mosquitto-clients # Ubuntu / Debian
brew install mosquitto # macOS (Homebrew)
# paho-mqtt (alternative to mosquitto_pub)
pip3 install paho-mqttpython3 apcget.py [IP_ADDRESS] [USERNAME] [PASSWORD] [OPTIONS]Credentials can also be provided via environment variables or a config file (see below).
USERNAMEandPASSWORDare the credentials you configured in PowerChute (not OS credentials).
python3 apcget.py 192.168.1.100 your_username your_password
# Output: 19.0# Battery charge
python3 apcget.py 192.168.1.100 your_username your_password --battery
# Multiple items (space-separated output)
python3 apcget.py 192.168.1.100 your_username your_password --load --runtime --voltage
# Output: 19.0 29 102.0| Option | Description | Example |
|---|---|---|
--status |
Device status | Online |
--load |
UPS load (%) | 19.0 |
--runtime |
Runtime remaining (min) | 29 |
--voltage |
Input voltage (VAC) | 102.0 |
--battery |
Battery charge (%) | 100.0 |
--batteryvoltage |
Battery voltage (VDC) | 13.7 |
Defaults to --load if no option is specified. Units (%, VAC, etc.) are not included in the output.
The --json option outputs all items as JSON. Useful for integration with Home Assistant, scripts, etc.
python3 apcget.py 192.168.1.100 your_username your_password --json
# Output: {"status": "Online", "load": "19.0", "runtime": "29", "voltage": "102.0", "battery": "100.0", "batteryvoltage": "13.7"}The --mqtt-send option publishes all items as JSON to an MQTT broker. Either mosquitto_pub or paho-mqtt is required (install one). mosquitto_pub is used if available; otherwise it falls back to paho-mqtt.
python3 apcget.py 192.168.1.100 your_username your_password \
--mqtt-send 192.168.1.200 \
--mqtt-topic apcget/my-ups # topic name can be any string you like| Option | Description | Default |
|---|---|---|
--mqtt-send |
MQTT broker address | (none) |
--mqtt-topic |
MQTT topic (e.g. apcget/ups-living, apcget/ups-office) |
apcget/ups |
--mqtt-port |
MQTT broker port | 1883 |
--mqtt-user |
MQTT username | (none) |
--mqtt-password |
MQTT password | (none) |
Add MQTT sensors to configuration.yaml (replace the topic with the one you chose above):
mqtt:
sensor:
- name: "UPS Load"
state_topic: "apcget/my-ups" # match your --mqtt-topic
value_template: "{{ value_json.load }}"
unit_of_measurement: "%"
- name: "UPS Battery"
state_topic: "apcget/my-ups"
value_template: "{{ value_json.battery }}"
unit_of_measurement: "%"
- name: "UPS Runtime"
state_topic: "apcget/my-ups"
value_template: "{{ value_json.runtime }}"
unit_of_measurement: "min"
- name: "UPS Status"
state_topic: "apcget/my-ups"
value_template: "{{ value_json.status }}"
- name: "UPS Voltage"
state_topic: "apcget/my-ups"
value_template: "{{ value_json.voltage }}"
unit_of_measurement: "VAC"
- name: "UPS Battery Voltage"
state_topic: "apcget/my-ups"
value_template: "{{ value_json.batteryvoltage }}"
unit_of_measurement: "VDC"The --zabbix-send option sends all 6 items at once via zabbix_sender.
python3 apcget.py 192.168.1.100 your_username your_password \
--zabbix-send 10.0.0.1 \
--zabbix-host MyUPS| Option | Description | Default |
|---|---|---|
--zabbix-send |
Zabbix server address | (none) |
--zabbix-host |
Host name in Zabbix | IP address |
--zabbix-port |
Zabbix server port | 10051 |
Create the following Zabbix trapper items on the target host:
| Key | Type | Description |
|---|---|---|
apc.status |
Text | Device status |
apc.load |
Numeric (float) | UPS load |
apc.runtime |
Numeric (integer) | Runtime remaining |
apc.voltage |
Numeric (float) | Input voltage |
apc.battery |
Numeric (float) | Battery charge |
apc.batteryvoltage |
Numeric (float) | Battery voltage |
* * * * * /usr/bin/python3 /path/to/apcget.py --config /path/to/.apcget.conf --zabbix-send 127.0.0.1 --zabbix-host ups-host >/dev/null 2>&1Credentials are resolved in the following priority order, allowing password-free command lines:
Priority: Command-line arguments > Environment variables > Config file
[powerchute]
ip = 192.168.1.100
username = your_username
password = your_password# Run with config file only (no arguments needed)
python3 apcget.py
# Specify a custom config path
python3 apcget.py --config /etc/apcget.confSet file permissions to owner-only read:
chmod 600 ~/.apcget.conf| Variable | Description |
|---|---|
APCGET_IP |
PowerChute IP address |
APCGET_USERNAME |
Login username |
APCGET_PASSWORD |
Login password |
export APCGET_IP=192.168.1.100
export APCGET_USERNAME=your_username
export APCGET_PASSWORD='your_password'
python3 apcget.py- Passing passwords as command-line arguments exposes them via
psand shell history. Use a config file or environment variables instead - SSL certificate verification is disabled because PowerChute uses a self-signed certificate
- Set
chmod 600on config files to prevent other users from reading them
This software is provided "as is", without warranty of any kind. Use at your own risk. The authors are not responsible for any damage, data loss, or other issues arising from the use of this software. This tool is not affiliated with or endorsed by Schneider Electric or APC.
- APC PowerChute Serial Shutdown for Business v1.4.0.601
- UPS: APC RS 550S
- Python 3.9 / 3.10
- Zabbix 7.4 (trapper integration)
- Amazon Linux 2023 / macOS