Unable to change sensor scale :(


Probably so simple you will laugh … sorry in advance but I’m searching for hours without success.

My Solaredge photovoltaic inverter gives me energy and power sensors in Wh and W, I want them in kWh and kW.

Here, the Solaredge entity unique ID is solaredge_energie_totale and I want to create an emtity called solaredge_energie_totale_kWh, (divided by 1000 from previous) with friendly name Solaredge energie totale [kWh], so I went to templates and tried this in the template dev tool :

  -  name: "Solaredge energie totale [kWh]"
  unique_id: solaredge_energie_totale_kWh
  unit_of_measurement: 'kWh'
  state > {{ states('solaredge_energie_totale') | int * 0.001 }}

witch returns this error :

ValueError: Template error: int got invalid input ‘unknown’ when rendering template ‘sensor: - name: “Solaredge energie totale [kWh]” unique_id: solaredge_energie_totale_kWh unit_of_measurement: ‘kWh’ state > {{ states(‘solaredge_energie_totale’) | int * 0.001 }}’ but no default was specified

Do I need to declare the new sensor entity somewhere ?

Any help will be welcome …


Remember to prefix sensor.

Try with:

  - sensor:
      - name: "Solaredge energie totale [kWh]"
        unique_id: solaredge_energie_totale_kWh
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.solaredge_energie_totale') | int(0) * 0.001 }}"
        availability: "{{ has_value('sensor.solaredge_energie_totale') }}"
1 Like

You really should add the availability template if you ever plan to use the sensor in an energy dashboard or utility meter. Otherwise you get weird spikes in your statistics.

The energy dashboard won’t accept the sensor if you do not set the state_class also.

Last but not least, the indenting is broken in your example. Check the indenting to match the documentation exactly. It matters. the last three lines should match up exactly with name.

1 Like

That’s it, thank you.

But now, where do I find the entity “solaredge_energie_totale_kWh” ? It doesn’t show up anywhere :thinking:

If you’re only going to display this new value, then you don’t need an unnecessary sensor. You can change the unit prefix and precision on the UI: Click on the entity and go to its settings.

You have to restart HA or reload the integration.

I did (restart and reload), still not listed.

Not listed where? Where are you looking for this sensor?

BTW the indentation of your code in the first post is totally off.
Did you add this to your configuration.yaml or another YAML file, or are you creating a template sensor under Helpers?

Yep, some ident and typo check later, it works as expected, thanks to everybody !