Template - no variable value

Hi Community,

I am brand new to Home Assistant and am currently trying to create a working template for a sensor. Somehow I have a problem that I can’t solve on my own:

I am trying to map the power loss of my inverter to a sensor. I have added and subtracted values from a few existing sensors. The result actually looks good (see upper part of screenshot developer tools/template)

However, when I query the newly created sensor, I only ever get the constant value “10” displayed
(see lower part of screenshot developer tools/template)

I created the sensor in the file editor, as shown

Actually, I thought that everything was correct

But something must have gone wrong :slight_smile: Why do I only get the static value “10 W” when I query the created sensor? But when I test the whole thing under developer tools/templates, I get a variable (always changing) value displayed?

Many thanks for your help
Holger

I don’t see anything obviously wrong with the template itself.

As an experiment, add the following line to the Template Sensor’s configuration and then execute Developer Tools → YAML → Reload Template Entities

      device_class: power

bingo - this did the trick! - but why? What did this line do exactly?

And one more question: It now seems, the “analog display card” , only dispalys values up to “100”?! Can this be fixed, since the value can most like be more than 100W…

Thanks again
Holger

My guess is the device class did not change anything, but it made it easier to see if you actually loaded the yaml that was shown. I think you’ve demonstrated that the template wasn’t loaded properly.

As for the card, it is most likely auto setting a range if you did not set one? You can set the minimum and maximum in the gauge card (if that is the card you used, I do not know anything named analog display).

Your template worked properly in the Template Editor but not when used in the Template Sensor. It means something in the Template Sensor’s configuration was responsible for the malfunction.

When using the state_class option, other options are needed to ensure its proper functioning (unit_of_measurement and device_class).

The upper limit of a Gauge Card is controlled by its max option. By default it’s 100 but you can set it higher.

max integer (optional, default: 100)

Maximum value for graph.