Need Help, division by zero

Hello all,

unfortunately the value can be partly = 0 (states(‘sensor.foxess_bat_discharge_power’), what can I do to make it work anyway? Thank you

    # Batterierest
      - name: Batterie_Rest
        unique_id: "Batterie_Rest"
        unit_of_measurement: h
        state: >
         {{ states('sensor.foxess_bat_soc')|float(1)*8.64/100 / states('sensor.foxess_bat_discharge_power')|float(0)|round(0)}}
    # Batterierest
      - name: Batterie_Rest
        unique_id: "Batterie_Rest"
        unit_of_measurement: h
        state: >
         {{ states('sensor.foxess_bat_soc')|float(1)*8.64/100 / states('sensor.foxess_bat_discharge_power')|float(1)|round(0)}}
        availability: >
         {{ has_value('sensor.foxess_bat_soc') and states('sensor.foxess_bat_discharge_power')|float(0) > 0 }}

Still mentiones ZeroDivisionError: float division by zero when I test it.

Then you must have done something other than what I posted. The availability template is evaluated before the state template and prevents the state template being evaluated if the availability is false.

Battery SOC for example 100% discharge atm is 0,00 kW but if I copy your code to yaml ist still says unavailable…

Yes that is correct.

Division by zero is mathematically undefined. So the availability template is set to make the value unavailable in this case.

Can the value only be displayed if equation is not zero? I am a beginner…

    # Batterierest
      - name: Batterie_Rest
        unique_id: "Batterie_Rest"
        unit_of_measurement: h
        state: >
            {% if states('sensor.foxess_bat_soc')|float(0)* 7.344/100 / states('sensor.foxess_bat_discharge_power')|float(0) > 0 %}
            {{states('sensor.foxess_bat_soc')|float(0)* 7.344/100 / states('sensor.foxess_bat_discharge_power')|float(0)| round (3) }}
            {% else %}
                {{(states ('0.0') | float(0)) |round(3) }}
            {% endif %}    

how can I get rid of “unavailable” if its 0?

It is only unavailable if the result is undefined, not if the result is 0.