muhkuh666
(Muhkuh666)
September 26, 2023, 1:03pm
1
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)}}
tom_l
September 26, 2023, 1:12pm
2
# 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 }}
muhkuh666
(Muhkuh666)
September 26, 2023, 1:16pm
3
Still mentiones ZeroDivisionError: float division by zero when I test it.
tom_l
September 26, 2023, 1:19pm
4
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.
muhkuh666
(Muhkuh666)
September 26, 2023, 1:28pm
5
Battery SOC for example 100% discharge atm is 0,00 kW but if I copy your code to yaml ist still says unavailable…
tom_l
September 26, 2023, 1:30pm
6
Yes that is correct.
Division by zero is mathematically undefined. So the availability template is set to make the value unavailable in this case.
muhkuh666
(Muhkuh666)
September 26, 2023, 1:33pm
7
Can the value only be displayed if equation is not zero? I am a beginner…
muhkuh666
(Muhkuh666)
September 26, 2023, 2:09pm
8
# 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?
tom_l
September 26, 2023, 2:31pm
11
It is only unavailable if the result is undefined, not if the result is 0.