An integration to poll a Cyberpower UPS throught the pwrstat-api wrapper.
Many thanks to:
-
JetBrains for the excellent
PyCharm IDE and providing me with an open source licence to speed up the
project development. -
@bruggeman for the
pwrstat-api
wrapper.
I wrote this to compliment the pwrstat-api wrapper. I've been accessing the wrapper using the RESTful API integration and it was working great. But it was lacking full Integration support and monitoring more than one UPS was a pain manage to config.
I decided to add proper Integration support.
The integration needs a working pwrstat-api
server. The integration does not support any of the cloud feature of Cyberpower.
The integration needs a working install of pwrstat-api
to provide the UPS data in a JSON format. You can install one directly from the official web site or look at the A Quick pwrstat Docker Image section to see how to set one up from this repository.
Not yet...
Copy the custom_components/pwrstat
directory into your /config/custom_components
directory.
Run the installation script. Run it once to make sure the operations look sane
and run it a second time with the go
parameter to do the actual work. If you
update just rerun the script, it will overwrite all installed files.
install /config# check output looks good
install go /config
Restart your Home Assistant installation.
Follow these steps:
- Navigate to
Settings -> Devices & Services
. - Click on
+ ADD INTEGRATION
. - Search for
cyberpower
and select it. - Enter the UPS name, its exact URL including the scheme, and how often you
want to poll the device. - Click
Submit
.
If it works you should see this:
You can enter more than one UPS.
You can create an energy sensor to convert W
into kWh
with something similar to this:
- platform: integration
source: sensor.pwrstat_office_ups_load
name: pwrstat_office_ups_energy
unit_prefix: k
round: 2
method: left
This is my snapshot of the pwrstat-api
docker set up. I modified it to mount the local tools inside the docker so there was no need to include a deb
file.
You can create a docker instance with these commands:
cd extras/pwstatcd
docker build -t ups-status:latest -f dockerfile .
HOME_NAME=your-name-goes-here docker-compose up
# This should work.
wget -q -O - http://127.0.0.1:5002/pwrstat
{"Battery Capacity": "80 %", "Firmware Number": "BF01902B1D1z", "Last Power Event": "Blackout at 2023/11/25 22:04:46 for 15 sec", "Line Interaction": "None", "Load": "86 Watt(23 %)", "Model Name": "ST Series", "Output Voltage": "116 V", "Power Supply by": "Utility Power", "Rating Power": "375 Watt", "Rating Voltage": "120 V", "Remaining Runtime": "19 min", "State": "Normal", "Test Result": "Passed at 2022/08/24 10:20:31", "Utility Voltage": "116 V"}
You can also use Network UPS Tools.
And I did for the longest time and it great. I just found it a little too powerful for my needs. I have 2 PCs each with a Cyberpower UPS on them and it ended up being simpler to monitor them in Home Assistant so a lot of the extra functionality was moot. Look at it if you're trying to hook different UPS devices together across a variety of systems.