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.