(Newbie) Need to convert a solar power sensor from KW to W

Im trying to display my current solar power (FoxESS - PV Power) on my awtrix device, its showing but its expecting W from the sensor but its receiving KW, is there a template or automation that can convert this or create a new sensor?

you read here

and scroll down a bit until you reach

State based sensor - Changing the unit of measurement of another sensor

This example matches your request next to 99%
but you must multiply by 1000 not 1024 and simply replace your entity names and the unit_of_measurement

1 Like
- sensor:
      - name: "Solar Power Watt"
        unit_of_measurement: "W"
        state: "{{ states('sensor.foxess_pv_power')|float * 1000 }}"

i think this has done it? i see the new sensor but now my solar isnt producing anything to test, ill check back in the morning

does that short code look correct if the sensor name is “sensor.foxess_pv_power” that im trying to convert?

You should read the hint given … a 2nd time …

Instead of using the ‘fancy name’ use the entity.name …
in the form sensor.<whatsoever it’s name is>

And ask yourself why you didn’t implement the “availability:” line to ensure that a calculation won’t throw an error in case your original sensor becomes
unknown (unkown * 1000 isn’r a valid calculation, or unavailable (unavailable * 1000) neither.

It helps you to get errormessages pointing to the real error not an error which is a followup to another error.

EDIT: I’d say sensor.foxess_pb_power looks correct.

yeah i found that problem and found the correct sensor. names and now working great, thanks for your help, as i say im VERY new to this and have zero experience writing any kind of code

you can add some more lines to make more from it.

state_class: measurement
device_class: power

Better said, leave the state_class, establish the template sensor and then go to
dev.tools (left menu in HA)>States
and enter ‘power’ in the filter field.
When you located your template entity press the small i in the circle
Remember what you see.
Then add the line starting with state_class and check the same thing.

If being a measurement lets you view the entity in a graphical chart, a line chart for example, without you get bars of values.

device_class is a differnt story, in short “10.1 W” without a device_class is a number, 10.1 with a trailing “W” which your brain translated being a value of type power. But HA hasn’t got your brain, since so if you want to let HA know it’s a power value you must define it.
For the sake to use a Rieman sum helper and create an energy energy entity from it.
And again … if you would do so, the energy entity would fails in case this power entity fails if only your foxess entity failed since the last one depends upon it’s feeding entities. (availability … is important)

1 Like