Template warning: ‘float’ got invalid input ‘unavailable’ when rendering template ‘{% set total = states(‘sensor.growattmodbus_output_power’) | float %} {% set production = states(‘sensor.power_production’) | float * 1000 %} {% set consumption = states(‘sensor.power_consumption’) | float * 1000 %} {{ [ total - production -consumption, 0 ] | max | round(0) }}’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2021.12
my sensor: yaml:
solar_percent:
value_template: "{{ ((states('sensor.growattmodbus_output_power')|float * 100) / ((states('sensor.power_consumption')|float * 1000) + states('sensor.growattmodbus_output_power')|float))|round(1) }}"
unit_of_measurement: '%'
friendly_name: Current Solar Percentage Realtime
Seems ((states(‘sensor.power_consumption’)|float(0) * 1000) + states(‘sensor.growattmodbus_output_power’)|float(0))) returned 0, and dividing by 0 is not allowed.
use an availability_template so no divides by 0 happen.
And I get Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['sensors']['solar_percent']['availability_template']. Got "{{ ((states('sensor.power_consumption')|float(0) * 1000) + states('sensor.growattmodbus_output_power')|float(0))) != 0}}". (See ?, line ?).
To avoid dividing by 0. the availability_template will prohibit the sensor to have an invalid value, but for now the value_template is still processed (but not used if availability is false). There is a PR to fix this.