Calculating a value from 2 sensors

Hi,
HA configuration is driving me nuts.
I’m completly lost in configuration.
What is the correct way to configure ha ?
when you search in topics you find some answers but always with yaml configuration file.
I want to add my ups to energy dashboard.
My ups is an apc it doesn’t have an output power but nominal power and load.
i try to make a sensor which would be the result of nominal power * load /100
I understood i have to make a template.
But should i go with gui and helper or with yaml ?
If yaml should i make a templates.yaml file with template: !include templates.yaml declaration in configuration.yaml
or make a sensors.yaml file with sensor: !include sensors.yaml
I don’t like the idea to have config in several places.
Whatever way i choose i also to have to deal with the strange syntax.
For example i tried with gui. I defined a sensor template as follow:

name: ups power
state template: "{{ states('sensor.ups_nominal_output_power')| float * states('sensor.ups_load')| float /100}}"
measurement unit: W
device class: power
state class: measure

and i have this error:

Sensor None has device class 'power', state class 'measurement' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '"104.3"' (<class 'str'>)

i have no other field to configure. Where can i tell ha it’s a numeric value ? i thought the usage of float in state template field was meant to do that. And state class is measure it shouldn’t be a str by default.
For yaml conf i don’t know where to begin and i also see there is a legacy syntax and a new one.
It seems very complicated for such a simple operation.

Did you integrate the UPS into HA? If you haven’t, then the editor is correct. Your sensor doesn’t exist.

yes i configured this integration and have access to the measures.

Ok. Had to make sure. :blush:

If you paste your template into the template editor (Developer Tools > Templates), what do you get?

Most likely I’d say the sensor name might be wrong. You can verify that in either the Entites tab or (what I find easier) is going the integration, click on the sensor, click the small cog at the top of the window and see what the actual entity name is.

i have the correct result but it says type is string.

Just like the Template test tool in the Developer Tools, you don’t use quotation marks around the templates in the UI Template Helper editor… that is what is leading to your error.

2 Likes

thank you :grinning:
so simple. :flushed: