I have a sensor that “computes” the average indoor temperature, based on the current_temperature
attribute of all entities in the climate
domain. However, it fails during startup, probably as some climate readings are not available.
So, in homeassistant’s log it prints.
2022-02-02 09:37:34 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError(‘TypeError: unsupported operand type(s) for +: ‘int’ and ‘NoneType’’) while processing template ‘Template(“{{ ‘%2.1f’ | format(states.climate | map(attribute = ‘attributes.current_temperature’, default = 21.0) | sum / (states.climate | length) | float) }}”)’ for attribute ‘_attr_native_value’ in entity ‘sensor.indoor_temp_avg’
And this is the sensor’s configuration:
sensor:
- platform: template
sensors:
indoor_temp_avg:
unit_of_measurement: '°C'
value_template: "{{ '%2.1f' | format(states.climate | map(attribute = 'attributes.current_temperature', default = 21.0) | sum / (states.climate | length) | float) }}"
Anyway to avoid this by adding just another default value anywhere?