Difference between revisions of "Home Assistant - NUT UPS Energy Tracking"

From ETCwiki
Jump to navigationJump to search
Line 57: Line 57:
 
  upsc cyberpowerb@localhost
 
  upsc cyberpowerb@localhost
  
== Add UPS to Home Assistant ==
+
== Home Assistant UPS Energy Tracking ==
 +
 
 +
=== Add a NUT UPS to Home Assistant ===
 +
Log into your Home Assistant web interface.
 +
* Configuration > Integrations > Add Integration
 +
* Find or search for NUT in the list (Network UPS Tools) and add
 +
* Enter your server information we created above
 +
** Hostname is the ip of the server in the LISTEN line usually
 +
** User is local_mon (from upsd.users)
 +
** Pass is mysupersecretpass (upsd.users)
 +
* For my UPS I track sensor.cyberpowerb_load in the list of sensors to enable
 +
** My Sensor shows up as a load percentage (or really an integer 0-100)
 +
 
 +
=== Edit configuration.yaml ===
 +
template:
 +
  - sensor:
 +
      - name: UPS LR usage
 +
        unit_of_measurement: kW
 +
        state: "{{ states('sensor.cyberpowera_load') | float * 6 / 1000 }}"
 +
        state_class: measurement
 +
        device_class: power

Revision as of 18:49, 24 October 2021

If you have a UPS (Uninterruptible Power Supply) that has either a USB connection or ethernet connection, you can likely add it to Home Assistant Server as an energy tracking device. This guide is generic enough to work with most USB UPS but I am using a Cyberpower CP1000, and have 2 of them showing up as an energy tracking device in my Home Assistant Energy section.

Network UPS Tools

Install Network UPS Tools

Network UPS Tools also called NUT is the tool we run on Linux to track UPS features.

sudo apt update
sudo apt install nut

Edit /etc/nut/nut.conf

The default mode is none, so lets change it to standalone in this file

MODE=standalone

Edit /etc/nut/ups.conf

We need to add our UPS to this file so NUT knows what driver to use. Add this section to your ups.conf. Name your ups in the square brackets, it doesn't have to say cyberpowerb, this is just mine.

[cyberpowerb]
     driver = usbhid-ups
     port = auto
     desc = "Cyberpower CP1000 B"
     pollfreq = 30

If you are having detection problems, add this line to your ups.conf config just under the driver line. Replace with your UPS vendor ID (find via lsusb)

vendorid = 0764

Edit /etc/nut/upsd.conf

Add a LISTEN directive, you can have more than one. Port separated by a space. Default is 3493. You may not want to open your LAN IP here.

LISTEN 192.168.1.100 3493
LISTEN 127.0.0.1 3493

Edit /etc/nut/upsd.users

Add this to create a user that can read UPS stats.

[local_mon]
      password = mysupersecretpass
      upsmon master

Edit /etc/nut/upsmon.conf

Add your UPS to the bottom to be monitored

MONITOR cyberpowerb@localhost 1 local_mon mysupersecretpass master

(optional) You may want to change polling to be less frequent

POLLFREQ 15

(optional) If your UPS goes stale, change when it assumes it is dead

DEADTIME 30

(optional) I stopped the computer from turning off the UPS on reboot by adding "no" or anything else to the end

POWERDOWNFLAG /etc/killpowerno

Restart NUT Services

This is for systemctl based distros of course.

systemctl restart nut-driver
systemctl restart nut-server
systemctl restart nut-monitor

Query NUT Server for info

This will poll the ups for available monitoring stuff.

upsc cyberpowerb@localhost

Home Assistant UPS Energy Tracking

Add a NUT UPS to Home Assistant

Log into your Home Assistant web interface.

  • Configuration > Integrations > Add Integration
  • Find or search for NUT in the list (Network UPS Tools) and add
  • Enter your server information we created above
    • Hostname is the ip of the server in the LISTEN line usually
    • User is local_mon (from upsd.users)
    • Pass is mysupersecretpass (upsd.users)
  • For my UPS I track sensor.cyberpowerb_load in the list of sensors to enable
    • My Sensor shows up as a load percentage (or really an integer 0-100)

Edit configuration.yaml

template:
  - sensor: 
      - name: UPS LR usage
        unit_of_measurement: kW
        state: "Template:States('sensor.cyberpowera load')"
        state_class: measurement
        device_class: power