[Solved] UPS % to watt calculation

Hello!

I have a UPS that shows me the procent of load being used, i have it connected to unraid and from unraid it’s connected to home assistant, though NUT. I can get the procentage in home assistant but not the watt’s being used. In unraid i can type the VA and max watt, so it’s calculating the watts depending on the procent, like the pic shows below.
I have read some about templating, but i immediately felt like it was far above my head - is this possible to calculate in home assistant, and if so, how is it done?

Thanks!

Create a sensor which will give you the value in watts

template
  - sensors:
       - name: "UPS Load"
         state_class: measurement
         device_class: power  
         unit_of_measurement: "W"
         state: "{{ (states('your_sensor in %') * states('your entity with Output capacity in W') / 100)  | int(default=0) }}"

Basically what Didier says, but conversions from VA to W is not 1:1.
Your UPS has a “efficiency” rating. Mine has 60%, with a 700VA max output, so my “load to power” sensor is

{{ states('sensor.eaton3s_load')|int  * 0.01 * 700 * 0.6|round(2) }}

I hooked a smart plug to confirm. The curves do not match perfectly (not sure who’s right or wrong, tbh), but close enough.

Wow!

I know it was going to be easy, just if you know how to… Thank you alot for the fast reply!

That made it!

Thank you guys alot for you’r help!
This forum is the absolut best…

Now it looks like this :slight_smile:

ups

Thank you again!

I’m trying to create this same ups load sensor for watts. I’ve made sensors before in my configuration.yaml. But where do I put this? Is it still in configuration.yaml or in sensors.yaml or somewhere else? Thanks

Well that depends on how your HA is set up, do you have pages for template.yaml, sensor.yaml and so on?

I have this under my “template.yaml” and it’s still working great.

# UPS % till Watt konvertering
  - sensor:
      - name: "UPS Watt"
        state_class: measurement
        device_class: power  
        unit_of_measurement: "W"
        state: "{{ states('sensor.ups_load')|int  * 0.01 * 2000 * 0.6|round(2) }}"
1 Like

Joakim,

I didn’t have the template. yaml or the sensor. yaml. I making those files individually and pasted your code in. But the sensor never showed up.

I did find this though.
https://www.reddit.com/r/homeassistant/comments/p1z19p/want_to_add_ups_to_the_new_energy_monitoring/

  • platform: template
    sensors:
    ups_watt:
    unit_of_measurement: ‘W’
    value_template: >-
    {{states(‘sensor.ups_load’) | float * 3.6}}

I put that code in my configuration.yaml. It is showing 14.5 wats from a load of 4%. I don’t know if that is correct or not.

I tried this in the states line:

state: “{{ states(‘sensor.ups_load’)|int * 0.01 * 2000 * 0.6|round(2) }}”

It showed 14.5 watts but had “48” W in the top info panel. So maybe the float integer is correct for my use?

Thanks for the help. I now have any idea of how many watts my TrueNAS NAS server is using that is connected to my Cyber power UPS.

1 Like

I know this thread has been marked as solved, but I still wanted to chime in with some extra details and a fully working example.

In order to calculate the real power consumption you need to know a few things:

  • The load of your UPS, this is usually a value returned by one of the sensors
  • The maximum configurable power

The maximum configurable power can be expressed in two values: real power, or apparent power. For details what this means, see the Wikipedia article, but it usually boils down to this: apparent power is the total amount of power present in the entire circuit, while the real power is the part of that power that your devices are actually consuming. If you want to know how much power the devices behind your UPS are actually consuming, real power is the value you are looking now. Real power is usually expressed in Watts, while apparent power is usually expressed in Volt-Ampere (V*A, which is technically equal to Watt, but the distinction is made to show the difference between the two types of power).

Now, UPS techincal specs usually show the value for apparent power, for the simple reason that it is a larger number than the real power, and therefore is better from a marketing point of view. For example, if you look at the product page for my UPS, APC BX7510MI, the advertised value is 750 VA. The technical specs also show a value like efficiency or power factor, which can help you determine the real power. In my case, the power factor is 0.63 (or an efficiency rating of 63%) and the apparent power is 750VA, which means that the real power is 750 VA * 0.63 = 472.5 W. So this is the figure you are looking for.

The actual power consumption of the devices behind your UPS is then quite simply: load % * real power. So with a load of 20% that would be: 20 / 100 * 472.5W = 94.5 W.

To create a new sensor for your UPS real power, you need to create an integration of type Template. This allows you to calculate a new value from one or more existing integrations. Very handy in this case. The caveat is that this must be configured in the configuration file in YAML, and cannot be configured in the web interface.

So fire up your favourite editor, and open the configuration.yaml file. If you are using the containerised version of Home Assistant like me, this will be in the Docker volume that you have mounted under /config.

Add the following bit of YAML to the file under the template object, creating it if necessary:

template:
  - sensor:
       - name: "UPS Real Load"
         state_class: measurement
         device_class: power  
         unit_of_measurement: "W"
         state: "{{ states('your_ups_load_sensor')|float * 0.01 * apparent_power * load_factor|round(2) }}"

Be sure to replace the values for your_ups_load_sensor with the name of the sensor that has your UPS load, in percent; apparent_power with the apparent power of your UPS according to the spec, in VA; load_factor with the load factor of your UPS according to the spec, as a number between 0 and 1.

If you only know the real power, you can change the line to:

         state: "{{ states('your_ups_load_sensor')|float * 0.01 * real_power|round(2) }}"

Replacing real_power with the real power of your UPS in W.

Then save the file, and in the Home Assistant web interface, browse to Developer Tools. In the YAML tab, click Check Configuration. This should succeed, which means you are safe to restart Home Assitant. Click the Restart button in the same screen. After a few seconds, Home Assitant will restart, and your new sensor with your calculated value will appear. You can map this like any other sensor.

If you get a YAML validation error, check your input again. Make sure the YAML file is correctly formatted. If Home Assitant restarts, but you do not see your sensor, check your configuration file. You might have a valid YAML file, but there is probably still an error in there. The Home Assitant log file will give you pointers to what is wrong.

EDIT: Changed int to float since on my UPS, the load percentage is not an integer, and converting it to int would remove the fraction of the percentage, making the calculation of the real power less accurate.

6 Likes

Wow!
This really made my day, now i can understand the calculation a bit better, thank you so much for taking you´r time typing this!

I just have one question, i can find the “Power Factor” on my UPS, 0,60. But i don’t understand the “load_factor” in the config, where should i find that?

Thanks!

I assume you’re refering to the your_ups_load_sensor in the Template?

This is in fact the measurement that Home Assistant is reading from your UPS as the load percentage. In my case this is coming from the Network UPS Tools (NUT) integration (because I have my UPS connected to my QNAP NAS, and I am reading it with NUT from the NAS over the network (in QNAP, you can enable this with “Network UPS master”) and is called sensor.qnapups_load.

Either way, you should have a sensor in your UPS integration, whatever method you are reading it, called “Load Percentage” or something like that. It will always be a value between 0 and 100%. This is the value you need to multiply with your UPS rated power factor and apparent power to get the real load in Watts.

No i got that part, it’s the “load_factor” that you are talking about here :slight_smile:

load factor of your UPS according to the spec, as a number between 0 and 1.
state: "{{ states('your_ups_load_sensor')|float * 0.01 * apparent_power * **load_factor**|round(2) }}"

Ah, sorry, load factor or power factor are the same. They are the value between 0 and 1 that I mentioned earlier.

So in your case, with a power factor of 0.60 and an apparent power of 2000 VA, the calculation would be:

state: "{{ states('your_ups_load_sensor')|float * 0.01 * 2000 * 0.6|round(2) }}"

Ah i see!
Thank you for the clarification.

Thanks so much :slight_smile:

After half an hour of fiddling with http://homeassistant.local/developer-tools/template and https://phind.com i finally got the answer by looking at WinNUT-Client/WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb at 8ddab9d3176f99ebf027039c0a2ce956cfdec168 · nutdotnet/WinNUT-Client · GitHub

{{ (2.0 * states('sensor.tecnoware_nominal_input_voltage') | float * 0.8) * (states('sensor.tecnoware_load') | float / 100.0) }}

where 2 is the input.current.nominal (Nominal input current (A)) : 2.0 which the NUT integration does NOT expose to HASS