Template Design Notes - WillCodeForCats/solaredge-modbus-multi GitHub Wiki

When an inverter goes offline (returns an error, incomplete read, timeout, or other errors) entities will change state to unavailable so that stale or bad data is not reported: this a by design, not a bug. Templates that use these entities should be updated to handle this condition.

This is a template issue that needs to be modified to check the entity is numeric, add a default value, or possibly add availability_template to it. (Note: the integration author does not use templates so these suggestions should be tested and/or updated then remove this note.)

Use states() rounded flag

When you see an error like this:

2023-08-11 22:57:25.547 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: round got invalid input 'unavailable' when rendering template '{{ states('sensor.solaredge_b1_state_of_energy') | round(0) }}' but no default was specified') while processing template 'Template<template=({{ states('sensor.solaredge_b1_state_of_energy') | round(0) }}) renders=786>' for attribute '_attr_native_value' in entity 'sensor.battery_in_percent'

Instead of using round() use the rounded flag like this:

{{ states('sensor.solaredge_b1_state_of_energy', rounded=True) }}

Using the rounded flag not only avoids the use of round(0), but also applies the entity the default precision setting.

Use availability_template

Use availability templates to flag templates as unavailable. Without an availability template, template sensors assume always available.

https://www.home-assistant.io/integrations/template/#availability_template

https://www.home-assistant.io/docs/configuration/templating/#states

https://community.home-assistant.io/t/template-sensor-with-unavailable-sensor/416676

https://community.home-assistant.io/t/how-to-prevent-unavailable-in-template-sensors/398409/3