I have a template:
## Percentages in %
solar_percent:
unit_of_measurement: '%'
friendly_name: Current Solar Percentage Realtime
#availability_template: "{{ ((states('sensor.power_consumption_w')|float(0)) + (states('power_production_solar_total')|float(0))) != 0}}"
value_template: >
{% set solar_total_w = states('sensor.power_production_solar_total') | float(0) %}
{% set production_w = states('sensor.power_production_w') | float(0) %}
{% set consumption_w = states('sensor.power_consumption_w') | float(0) %}
{% set consumption_total = states('sensor.power_consumption_total') | float(0) %}
{{ [ (solar_total_w * 100) / (consumption_w + solar_total_w), 0 ] | max | round(0) }}
I get this error:
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:329
First occurred: 08:26:23 (1 occurrences)
Last logged: 08:26:23
TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template<template=({% set solar_total_w = states('sensor.power_production_solar_total') | float(0) %} {% set production_w = states('sensor.power_production_w') | float(0) %} {% set consumption_w = states('sensor.power_consumption_w') | float(0) %} {% set consumption_total = states('sensor.power_consumption_total') | float(0) %} {{ [ (solar_total_w * 100) / (consumption_w + solar_total_w), 0 ] | max | round(0) }}) renders=26>' for attribute '_attr_native_value' in entity 'sensor.solar_percent'
I am trying (with the help of this topic):
https://community.home-assistant.io/t/templateerror-zerodivisionerror-float-division-by-zero-what-is-wrong-in-my-syntax
to decode what the availability template should look like.
But whatever I try I have no success…
I would like to see an example to extract the logic from it. maybe even a “working” line of YAML if possible… Thanks in advance.