Solis Self-Consumption Formula Error with If/Then

Hello everyone,

I have a question for this forum that I just can’t seem to solve.

To determine the self-consumption of my SOLIS inverter, I created the following template, but it’s giving an incorrect
result after %else%.

If I enter this template into the template editor, it produces the correct result, meaning the sensors after “else” are
being read correctly and are delivering the right result.

The first part of the status shows the power when the battery is discharging, and the second part shows it when it’s
charging instead of discharging.
"

  • sensor:
  # Solis internal current consumption
    name: solis_intern_aktuell
    unique_id: solis_intern_aktuell

    state: >-
      {% if states('sensor.solis_s6_eh1p_battery_discharge_power_2') | float(0) > 0%}
         
        {{ ( states("sensor.solis_s6_eh1p_battery_discharge_power_2") |float (0) |abs
           - states("sensor.solis_s6_eh1p_ac_grid_port_power") |float (0)|abs )  
        }}

      {% else %}          

        {{ ( states("sensor.solis_s6_eh1p_ac_grid_port_power") |float (0) |abs
           - states("sensor.solis_s6_eh1p_battery_charge_power_2") |float (0) |abs )

         }}

      {% endif %}

"

When I enter this exact template into my YAML configuration, the result of the second part is incorrect. It returns the value of a
different entity that isn’t even being queried in the template.

I’ve tried everything, but I’m stuck. Could someone please help me in case I’ve done something wrong?

thank You and many greetings
Wolfgang

Create TopicClose