Adding UPS/NUTS to Energy Panel

Wondering if anyone has a working setup for adding NUTS / UPS to their home assistant energy tab? I was able to do it once, but after a restart home assistant energy complains “unexpected device class”

Here is my config:

- platform: template
  sensors:
    rackups_power_usage:
      unit_of_measurement: "W"
      value_template: >-
        {% if states('sensor.rackups_status_data') in ['OL', 'OL CHRG'] -%}
          {{ (states('sensor.rackups_load') | float) / 100 * (states('sensor.rackups_nominal_real_power') | float) }}
        {%- else -%}
          0
        {%- endif %}
      device_class: energy

- platform: integration
  name: lab_power_usage
  source: sensor.rackups_power_usage
  unit_prefix: k
  round: 3

When I go to the dev tools to query those sensors I get:

sensor.rackups_power_usage
state: 9.0
attributes:
    unit_of_measurement: W
    friendly_name: deskups_power_usage
    device_class: energy

sensor.lab_power_usage
state: unknown
attributes:
    state_class: total
    source: sensor.deskups_power_usage
    friendly_name: desk_power_usage
    icon: mdi:chart-histogram

I know that lab_power_usage should be in kWh, but that field is missing.

Every time I restart home assistant I get the log:

Logger: homeassistant.components.integration.sensor
Source: components/integration/sensor.py:132
Integration: integration (documentation, issues)
First occurred: 11:49:09 AM (1 occurrences)
Last logged: 11:49:09 AM
Could not restore last state: [<class ‘decimal.ConversionSyntax’>]

So, I’m wondering if anyone has a working NUTS/UPS config they could share, that hooks into the energy panel?

Have you had any luck with this?
It would be a very useful integration.

Looking for the same if anyone have a clue.

The below is working for me. I found in this thread where you need to use the new template integration for things to work.

@ch8zer thanks for the original work and inspiration!

template:
  - sensor:
      - name: ups_power_usage
        device_class: power
        unit_of_measurement: W
        state_class: measurement
        state: >
          {% if states('sensor.ups_status_data') in ['OL', 'OL CHRG'] -%}
            {{ (states('sensor.ups_load') | float) / 100 * (states('sensor.ups_nominal_real_power') | float) }}
          {%- else -%}
            0
          {%- endif %}

sensor:
  - platform: integration
    name: Closet Energy
    source: sensor.ups_power_usage
    unit_prefix: k

Screenshot 2021-12-30 101623

5 Likes

Powercalc sounds very interesting by its simplicity:

I have this configured for my light switches but it doesn’t recognize the NUT UPS device type. I wonder if it would be considered a linear power type since the wattage can be anywhere from 0 to max the unit provides.

Hi everyone,

Does somes have integrated their ups consumption in the energy dashboard?

i try with this , but i can’t select it in the dashboard

- platform: template
  sensors:
    real_eaton_energy:
      friendly_name: 'Conso onduleur'
      value_template: |
        {% if states('sensor.eaton_status_data') in ['OL', 'OL CHRG'] -%}
        {{ (states('sensor.eaton_current_real_power') | float()) / 1000 }}
        {%- else -%}
          0
        {%- endif %}
      unit_of_measurement: "kWh"

@Tarlak The example I gave in my post above is working for me. From what I’ve read the legacy method that you’ve used doesn’t play nice with the energy dashboard but the new template integration does.

1 Like

Has i’m pretty new in HA, i don’t understand whats the difference between legacy method ?

I try to put my template in a separate file (not in configuraiton.yaml), and for the moment all the exemple i found looks like i post :frowning:

@Tarlak I can’t say that I really understand the differences either but from my post above here is a link with some discussion on the difference between the legacy template method and the newer template integration. Here is my config, I keep it in configuration.yaml, it’s been working for me.

template:
  - sensor:
      - name: ups_power_usage
        device_class: power
        unit_of_measurement: W
        state_class: measurement
        state: >
          {% if states('sensor.ups_status_data') in ['OL', 'OL CHRG'] -%}
            {{ (states('sensor.ups_load') | float) / 100 * (states('sensor.ups_nominal_real_power') | float) }}
          {%- else -%}
            0
          {%- endif %}

sensor:
  - platform: integration
    name: Closet Energy
    source: sensor.ups_power_usage
    unit_prefix: k
6 Likes

I found my mistake :slight_smile: thanks for your example @kckopp, sometime a little sleep help a lot :slight_smile:

1 Like

this is so great guys, thanks!

Thank you! This mostly worked as-is - I had to modify the nominal power name to match the states my NUT instance created, and I included my UPS power factor (0.6 from Tripp technical specifications) in the equation.

1 Like

The sensor above can be added to an usual card but the Energy dashboard ignores it as it is “W” and “measurement” and not “total_increasing”/“kWh”. How do I convert the former to the latter? It needs to accumulate the increasing value somewhere…

@aik Go to Settings > Devices & Integration > Helpers.

Create a helper called Integration - Riemann sum integral.

Give it a name.

Add your “W” sensor as the Input sensor

Leave the Integration method as Trapezoidal rule.

Set your Precision. I left mine to 2 decimal places or 2.

Metrics prefix should be k (kilo) to give you kW.

Time unit should be Hours.

After adding it, give it a couple of hours for the data to update the helper and it should allow you to add it to the energy dashboard.

2 Likes

Thanks, lets see how it goes!
A couple of questions - does it have to be kW (and not just W) and “hours” (not minutes)? Trying to get my mind around energy sensors requirements in HA.
I wonder if this is the way to fix my Xiaomi power meter from Energy usage calculations do not match

Tried and confused. The energy bashboard says the dishwasher used today 0.15kWh when hovering mouse on top of that item in “monitor individual device”. However, when I click on that sensor, a detailed window opens with the very same sensor with a graph saying 0.81kWh consumed, all today.
Soooo confusing :-/

Thanks, it worked for me after having changed the states names to make them correspond to my ups’s ones.