Sensor State unavailable

Hi,
first time trying to build my own sensor. It should give me the kW of my Battery-Pack, which has 6,2kW in total and has an entity that shows it in %
So I included a template.yaml in my configuration.yaml and added the following in the template.yaml:

- sensor:
  - name: Batterie Kapazität kW
    unique_id: solax_battery_capacity_kW
    unit_of_measurement: kW
    icon: mdi:battery-sync
    state: >
      {{ (states('sensor.solax_battery_capacity_2')/100*6.2 |round(2)) }}

In the developer tools the sensor shows up but with an “unavailable” state. The state of the “%”-entitiy was 65.
If I write it in the template-editor, it shows the state “4,03”, which is the right kW-Value.
What’s wrong with the template?

Hi ZaphodB72,

Is there a sensor.solax_battery_capacity it’s finding internally instead.

No, there is no other sensor and
{{ (states(‘sensor.solax_battery_capacity_2’)/100*6.2 |round(2)) }}
shows the right state “4,03” when entering in the template editor.

shouldn’t it be converted to float first?

1 Like

Solved: simply created a helper

{{ (float(states(‘sensor.solax_battery_capacity_2’))/100*6.2) |float |round(2) }}