Difference between revisions of "Home Assistant"
Line 1: | Line 1: | ||
= | == UPS == | ||
Here is my configuration.yaml for a cyberpower and the entities card setup. | Here is my configuration.yaml for a cyberpower and the entities card setup. | ||
Line 9: | Line 9: | ||
You launch CyberPower Business (username : admin , password: admin) and it should automatically find your UPS via the USB port connection. | You launch CyberPower Business (username : admin , password: admin) and it should automatically find your UPS via the USB port connection. | ||
I went to settings, enabled SNMP v1, and created the public and private groups and linked to 0.0.0.0 which means any computer on my network can query the snmp service. I set these to read/write | I went to settings, enabled SNMP v1, and created the public and private groups and linked to 0.0.0.0 which means any computer on my network can query the snmp service. I set these to read/write. Open port 161 in the firewall and set for UDP inbound traffic. | ||
[[File:Ups1.png|1080px|center]] | |||
Secondly you need to download the latest MIB file from CyberPower at https://www.cyberpowersystems.com/products/software/mib-files/ | Secondly you need to download the latest MIB file from CyberPower at https://www.cyberpowersystems.com/products/software/mib-files/ | ||
Line 16: | Line 19: | ||
Use an MIB browser, I used iReasoning MIB Browser (https://www.ireasoning.com/mibbrowser.shtml) | Use an MIB browser, I used iReasoning MIB Browser (https://www.ireasoning.com/mibbrowser.shtml) | ||
Install and start the iReasoning Browser. Choose "File...Open..." and go to the folder where you stored the CyberPower MIB file and select it. Start by selecting your ip address or localhost as the address in the top right box. In my image below you will see it is connected to 'localhost' since I am running the iReasoning Browser on the same computer the UPS is plugged into. If you are running this on another computer you would have to put in the IP address of the computer attached to the UPS (192.168.1.7 in my case). Easier to just run on the same Windows 10 machine. Note that my HA is running in Docker on a Ubuntu machine elsewhere on my network at 192.168.1.38 but I never need to enter this anywhere to get everything to work. | Install and start the iReasoning Browser. Choose "File...Open..." and go to the folder where you stored the CyberPower MIB file and select it. Start by selecting your ip address or localhost as the address in the top right box. In my image below you will see it is connected to 'localhost' since I am running the iReasoning Browser on the same computer the UPS is plugged into. If you are running this on another computer you would have to put in the IP address of the computer attached to the UPS (192.168.1.7 in my case). Easier to just run on the same Windows 10 machine. Note that my HA is running in Docker on a Ubuntu machine elsewhere on my network at 192.168.1.38 but I never need to enter this anywhere to get everything to work. | ||
It's not super intuitive but start after loading the MIB go down the tree with 'private...enterprises...cps...products...ups' and work your way down the folder tree in the MIB file and you will see lots of OIDs you can use. Double click a 'leaf' on the tree and it will query the OID and return a value. The OID is listed at the bottom left and the values when you double click are shown on the right hand panel. | It's not super intuitive but start after loading the MIB go down the tree with 'private...enterprises...cps...products...ups' and work your way down the folder tree in the MIB file and you will see lots of OIDs you can use. Double click a 'leaf' on the tree and it will query the OID and return a value. The OID is listed at the bottom left and the values when you double click are shown on the right hand panel. | ||
[[File:ups2.png|1080px|center]] | |||
You can try any of the OIDs to see which work on your UPS, most were OK on my Value II 1600E but if the OID is not supported it will just tell you that. | You can try any of the OIDs to see which work on your UPS, most were OK on my Value II 1600E but if the OID is not supported it will just tell you that. | ||
Line 29: | Line 33: | ||
Then its time to edit the 'sensor' section of your configuration.yaml file. | Then its time to edit the 'sensor' section of your configuration.yaml file. | ||
<pre> | |||
############################### | |||
# # | |||
# UPS # | |||
# # | |||
############################### | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.4.2.1.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Output Voltage | |||
value_template: '{{ (value | int / 10 ) }}' | |||
unit_of_measurement: "V" | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.1.1.1.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Model | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.4.1.1.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Status | |||
value_template: > | |||
{% set vals = {'1': 'unknown', '2':'onLine', '3':'onBattery', '4':'onBoost', '5':'sleep', '6':'off', '7':'rebooting'} %} | |||
{{vals[value]}} | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.3.2.6.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Advanced Status | |||
value_template: > | |||
{% set vals = {'1': 'normal', '2':'Over Voltage', '3':'Under Voltage', '4':'Frequency failure', '5':'Blackout'} %} | |||
{{vals[value]}} | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.4.1.1.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Battery Status | |||
value_template: > | |||
{% set vals = {'1': 'unknown', '2':'Normal', '3':'Battery Low'} %} | |||
{{vals[value]}} | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.1.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Battery Capacity | |||
value_template: '{{ (value | float) }}' | |||
unit_of_measurement: "%" | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.4.2.3.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Load | |||
value_template: '{{ (value | float) }}' | |||
unit_of_measurement: "%" | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.2.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Battery Voltage | |||
value_template: '{{ (value | int / 10 ) }}' | |||
unit_of_measurement: "V" | |||
- platform: snmp | |||
host: 192.168.1.7 | |||
baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.4.0 | |||
accept_errors: 'true' | |||
community: public | |||
port: 161 | |||
name: UPS Run Time Remaining | |||
value_template: >- | |||
{% set time = (value | int) | int %} | |||
{% set minutes = ((time % 360000) / 6000) | int%} | |||
{% set hours = ((time % 8640000) / 360000) | int %} | |||
{% set days = (time / 8640000) | int %} | |||
{%- if time < 60 -%} | |||
Less then 1 min | |||
{%- else -%} | |||
{%- if days > 0 -%} | |||
{{ days }}d | |||
{%- endif -%} | |||
{%- if hours > 0 -%} | |||
{%- if days > 0 -%} | |||
{{ ' ' }} | |||
{%- endif -%} | |||
{{ hours }}hr | |||
{%- endif -%} | |||
{%- if minutes > 0 -%} | |||
{%- if days > 0 or hours > 0 -%} | |||
{{ ' ' }} | |||
{%- endif -%} | |||
{{ minutes }}min | |||
{%- endif -%} | |||
{%- endif -%} | |||
- platform: template | |||
sensors: | |||
ups_battery_capacity: | |||
unit_of_measurement: "%" | |||
value_template: "{{ states('sensor.ups_battery_capacity_2') }}" | |||
friendly_name: "Battery Capacity" | |||
icon_template: > | |||
{% set level = states('sensor.ups_battery_capacity_2') | float | multiply(0.1) | round(0,"floor") | multiply(10)| round(0) %} | |||
{% if is_state('sensor.ups_status', 'onLine') and is_state('sensor.ups_battery_capacity_2' , '100.0' ) %} | |||
mdi:battery | |||
{% elif is_state('sensor.ups_status', 'onLine') %} | |||
mdi:battery-charging-{{level}} | |||
{% else %} | |||
mdi:battery-{{level}} | |||
{% endif %} | |||
</pre> | |||
Note that the template at the bottom creates a smart icon. It shows the level of the battery and the icon has the 'flash' symbol on the right if it is charging and does not have the flash if at 100% or running on batteries and discharging. (Thanks to RobC and AndyVR on Discord for this icon code) | |||
the entities card setup | |||
<pre> | |||
type: entities | |||
entities: | |||
- entity: sensor.ups_model | |||
name: Model | |||
icon: mdi:power-plug | |||
- entity: sensor.ups_status | |||
name: Status | |||
icon: mdi:power | |||
- entity: sensor.ups_battery_capacity | |||
name: Battery Capacity | |||
- entity: sensor.ups_run_time_remaining | |||
name: Run time remaining | |||
icon: mdi:av-timer | |||
- entity: sensor.ups_battery_status | |||
name: Battery Status | |||
icon: mdi:car-battery | |||
- entity: sensor.ups_battery_voltage | |||
name: Battery Voltage | |||
icon: mdi:car-battery | |||
- entity: sensor.ups_output_voltage | |||
name: Output Volts | |||
icon: mdi:power-socket-au | |||
- entity: sensor.ups_advanced_status | |||
name: Advanced status | |||
- entity: sensor.ups_load | |||
icon: mdi:signal-cellular-3 | |||
header: | |||
type: picture | |||
image: local/ups5.jpg | |||
tap_action: | |||
action: none | |||
hold_action: | |||
action: none | |||
</pre> | |||
and the card itself | |||
Here is my configuration.yaml for a cyberpower and the entities card setup. | |||
First you need to download and install the latest CyberPower Panel Business V4 at https://www.cyberpowersystems.com/products/software/power-panel-business/ | |||
I installed this on my Windows 10 computer (IP 192.168.1.7). I disabled Personal Edition of CyberPower in my startup services and installed Version 4 of the Business edition that I downloaded from the link above (ppb440-setup.exe). | |||
You launch CyberPower Business (username : admin , password: admin) and it should automatically find your UPS via the USB port connection. | |||
I went to settings, enabled SNMP v1, and created the public and private groups and linked to 0.0.0.0 which means any computer on my network can query the snmp service. I set these to read/write | |||
[[File:ups3.png]] | |||
Note in the image above the battery is at 94% and charging (the flash icon to the right of the battery). This is using the icon created in the ‘sensors’ template | |||
https://community.home-assistant.io/t/monitor-cyberpower-ups-plugged-into-windows-machine-via-usb |
Revision as of 11:17, 28 August 2023
UPS
Here is my configuration.yaml for a cyberpower and the entities card setup.
First you need to download and install the latest CyberPower Panel Business V4 at https://www.cyberpowersystems.com/products/software/power-panel-business/
I installed this on my Windows 10 computer (IP 192.168.1.7). I disabled Personal Edition of CyberPower in my startup services and installed Version 4 of the Business edition that I downloaded from the link above (ppb440-setup.exe).
You launch CyberPower Business (username : admin , password: admin) and it should automatically find your UPS via the USB port connection.
I went to settings, enabled SNMP v1, and created the public and private groups and linked to 0.0.0.0 which means any computer on my network can query the snmp service. I set these to read/write. Open port 161 in the firewall and set for UDP inbound traffic.
Secondly you need to download the latest MIB file from CyberPower at https://www.cyberpowersystems.com/products/software/mib-files/
Note where this is saved, mine was of course in the Windows Downloads folder. Unzip the file, mine was called MIB002-0001-10.mib and I stored it in a folder called "MIB" off the Downloads folder.
Use an MIB browser, I used iReasoning MIB Browser (https://www.ireasoning.com/mibbrowser.shtml)
Install and start the iReasoning Browser. Choose "File...Open..." and go to the folder where you stored the CyberPower MIB file and select it. Start by selecting your ip address or localhost as the address in the top right box. In my image below you will see it is connected to 'localhost' since I am running the iReasoning Browser on the same computer the UPS is plugged into. If you are running this on another computer you would have to put in the IP address of the computer attached to the UPS (192.168.1.7 in my case). Easier to just run on the same Windows 10 machine. Note that my HA is running in Docker on a Ubuntu machine elsewhere on my network at 192.168.1.38 but I never need to enter this anywhere to get everything to work.
It's not super intuitive but start after loading the MIB go down the tree with 'private...enterprises...cps...products...ups' and work your way down the folder tree in the MIB file and you will see lots of OIDs you can use. Double click a 'leaf' on the tree and it will query the OID and return a value. The OID is listed at the bottom left and the values when you double click are shown on the right hand panel.
You can try any of the OIDs to see which work on your UPS, most were OK on my Value II 1600E but if the OID is not supported it will just tell you that.
Note two things. First the OIDs from CyberPower need the ".0" at the end, you cannot use just the OID you see in a viewer. Second, look at the response data, it might be an integer; ticks (e.g. time remaining in my example below); or a series of strings, for example the "Status", which you can then use to develop the value_template in configuration.yaml. I have many examples below.
Then its time to edit the 'sensor' section of your configuration.yaml file.
############################### # # # UPS # # # ############################### - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.4.2.1.0 accept_errors: 'true' community: public port: 161 name: UPS Output Voltage value_template: '{{ (value | int / 10 ) }}' unit_of_measurement: "V" - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.1.1.1.0 accept_errors: 'true' community: public port: 161 name: UPS Model - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.4.1.1.0 accept_errors: 'true' community: public port: 161 name: UPS Status value_template: > {% set vals = {'1': 'unknown', '2':'onLine', '3':'onBattery', '4':'onBoost', '5':'sleep', '6':'off', '7':'rebooting'} %} {{vals[value]}} - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.3.2.6.0 accept_errors: 'true' community: public port: 161 name: UPS Advanced Status value_template: > {% set vals = {'1': 'normal', '2':'Over Voltage', '3':'Under Voltage', '4':'Frequency failure', '5':'Blackout'} %} {{vals[value]}} - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.4.1.1.0 accept_errors: 'true' community: public port: 161 name: UPS Battery Status value_template: > {% set vals = {'1': 'unknown', '2':'Normal', '3':'Battery Low'} %} {{vals[value]}} - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.1.0 accept_errors: 'true' community: public port: 161 name: UPS Battery Capacity value_template: '{{ (value | float) }}' unit_of_measurement: "%" - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.4.2.3.0 accept_errors: 'true' community: public port: 161 name: UPS Load value_template: '{{ (value | float) }}' unit_of_measurement: "%" - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.2.0 accept_errors: 'true' community: public port: 161 name: UPS Battery Voltage value_template: '{{ (value | int / 10 ) }}' unit_of_measurement: "V" - platform: snmp host: 192.168.1.7 baseoid: .1.3.6.1.4.1.3808.1.1.1.2.2.4.0 accept_errors: 'true' community: public port: 161 name: UPS Run Time Remaining value_template: >- {% set time = (value | int) | int %} {% set minutes = ((time % 360000) / 6000) | int%} {% set hours = ((time % 8640000) / 360000) | int %} {% set days = (time / 8640000) | int %} {%- if time < 60 -%} Less then 1 min {%- else -%} {%- if days > 0 -%} {{ days }}d {%- endif -%} {%- if hours > 0 -%} {%- if days > 0 -%} {{ ' ' }} {%- endif -%} {{ hours }}hr {%- endif -%} {%- if minutes > 0 -%} {%- if days > 0 or hours > 0 -%} {{ ' ' }} {%- endif -%} {{ minutes }}min {%- endif -%} {%- endif -%} - platform: template sensors: ups_battery_capacity: unit_of_measurement: "%" value_template: "{{ states('sensor.ups_battery_capacity_2') }}" friendly_name: "Battery Capacity" icon_template: > {% set level = states('sensor.ups_battery_capacity_2') | float | multiply(0.1) | round(0,"floor") | multiply(10)| round(0) %} {% if is_state('sensor.ups_status', 'onLine') and is_state('sensor.ups_battery_capacity_2' , '100.0' ) %} mdi:battery {% elif is_state('sensor.ups_status', 'onLine') %} mdi:battery-charging-{{level}} {% else %} mdi:battery-{{level}} {% endif %}
Note that the template at the bottom creates a smart icon. It shows the level of the battery and the icon has the 'flash' symbol on the right if it is charging and does not have the flash if at 100% or running on batteries and discharging. (Thanks to RobC and AndyVR on Discord for this icon code)
the entities card setup
type: entities entities: - entity: sensor.ups_model name: Model icon: mdi:power-plug - entity: sensor.ups_status name: Status icon: mdi:power - entity: sensor.ups_battery_capacity name: Battery Capacity - entity: sensor.ups_run_time_remaining name: Run time remaining icon: mdi:av-timer - entity: sensor.ups_battery_status name: Battery Status icon: mdi:car-battery - entity: sensor.ups_battery_voltage name: Battery Voltage icon: mdi:car-battery - entity: sensor.ups_output_voltage name: Output Volts icon: mdi:power-socket-au - entity: sensor.ups_advanced_status name: Advanced status - entity: sensor.ups_load icon: mdi:signal-cellular-3 header: type: picture image: local/ups5.jpg tap_action: action: none hold_action: action: none
and the card itself Here is my configuration.yaml for a cyberpower and the entities card setup.
First you need to download and install the latest CyberPower Panel Business V4 at https://www.cyberpowersystems.com/products/software/power-panel-business/
I installed this on my Windows 10 computer (IP 192.168.1.7). I disabled Personal Edition of CyberPower in my startup services and installed Version 4 of the Business edition that I downloaded from the link above (ppb440-setup.exe).
You launch CyberPower Business (username : admin , password: admin) and it should automatically find your UPS via the USB port connection.
I went to settings, enabled SNMP v1, and created the public and private groups and linked to 0.0.0.0 which means any computer on my network can query the snmp service. I set these to read/write
Note in the image above the battery is at 94% and charging (the flash icon to the right of the battery). This is using the icon created in the ‘sensors’ template
https://community.home-assistant.io/t/monitor-cyberpower-ups-plugged-into-windows-machine-via-usb