CyberPower Business Sensors

Hi,

After trying the other versions around I came to the conclusion I could either have my CyberPower UPS in Home Assistant or have the default Web UI.

This is how I managed to have my cake and eat it.

Web UI, useful for changing settings etc…

We need to get our Bearer token to integrate with Home Assistant.
I used chrome for this but I’m sure other browsers have similar options.

In Chrome go to the View menu - Developer - Developer Tools and the Dev panel should open to the right hand side. Under the Network Tab then Headers Tab you will see the Request Headers Section, your Authorization token can be found here. Copy this for use later.

Note: If you click on the Response tab, you will find all the available status options (attributes) available which can be added as sensors.

Lets set up some sensors!

The main status sensor to which child sensors can be created.

- platform : rest 
  resource: http://<IPADRESS>:3052/local/rest/v1/ups/status
  name: Server UPS
  headers:
    Authorization: <BEARER-TOKEN-COPIED-EARLIER>
    User-Agent: Home Assistant
    Content-Type: application/json
  value_template: '{{ value_json["battery"]["stateText"] }}' 
  json_attributes:
    - input
    - output
    - battery
    - bypass
    - system
    - onlyPhaseArch
    - communicationAvaiable
    - <Add any other attributes found in response tab>

Now we can create seperate sensors like this using our above main sensor.

- platform: template
  sensors:
    ups_mains_voltage:
      friendly_name: UPS Mains Voltage
      unit_of_measurement: "V"
      value_template: "{{ state_attr('sensor.server_ups', 'input')['voltages'][0] | replace(' V','') | float | round(0)}}"
    ups_load_percent:
      friendly_name: UPS Load Percent
      unit_of_measurement: "%"
      value_template: "{{ state_attr('sensor.server_ups', 'output')['loads'][0] | replace(' %','') | float | round(0)}}"
    ups_load_watts:
      friendly_name: UPS Load Watts
      unit_of_measurement: "W"
      value_template: "{{ states('sensor.ups_load_percent') | float / 100 * 550 | round(0)}}"
    ups_battery_voltage:
      friendly_name: UPS Battery Voltage
      unit_of_measurement: "V"
      value_template: "{{ state_attr('sensor.server_ups', 'battery')['voltage'] | replace(' V','') | float | round(0)}}"
    ups_battery_capacity:
      friendly_name: UPS Battery Capacity
      unit_of_measurement: "%"
      value_template: "{{ state_attr('sensor.server_ups', 'battery')['capacity'] | replace(' %','') | float | round(0)}}"
    ups_battery_runtime:
      friendly_name: UPS Battery Runtime
      unit_of_measurement: "min"
      value_template: "{{ state_attr('sensor.server_ups', 'battery')['remainingRunTimeInSecs'] | float / 60 | round(0)}}"

I hope someone finds this useful.

:grinning: :+1:

4 Likes

Wonderful!
Do you think this will work with PowerPanel Personal too?

Hi,

I’ve actually stopped using this and just set up a vm instead.

You could try it but I’m not maintaining the container anymore.

I just realised that I though your reply was to a docker image i’d made and not the actual template. I reckon it will work yes. did you ever try it?

Awesome! Thank you.

Hey again, thanks this is awesome! Wanted to give anyone else a heads up that was trying to write a sensor that would detect if communication with the UPS was unavailable. Spent over an hour trying to figure out why this didn’t work (where ent is set to UPS entity):

is_state_attr(ent.entity_id, 'communicationAvailable', False)

Apparently a developer at CyberPower misspelled ‘Available’. The following will work as a template sensor:

is_state_attr(ent.entity_id, 'communicationAvaiable', False)

Note the missing ‘l’

1 Like