Hello,
I struggling with the following in my sensors.yaml file - It works fine right now but it’s showing errors in the log file at boot.
lux_battery_flow:
friendly_name: "Lux - Battery Flow (Live)"
unit_of_measurement: 'W'
value_template: "{{ '-{}'.format(states('sensor.lux_batttery_discharge')) if states('sensor.lux_batttery_discharge')|round > 0 else '+{}'.format(states('sensor.lux_battery_charge')) }}"
In the logs it shows:
TemplateError('TypeError: '>' not supported between instances of 'str' and 'int'') while processing template 'Template("{{ '-{}'.format(states('sensor.lux_batttery_discharge')) if states('sensor.lux_batttery_discharge')|round > 0 else '+{}'.format(states('sensor.lux_battery_charge')) }}")' for attribute '_attr_native_value' in entity 'sensor.lux_battery_flow'
2:08:13 PM – (ERROR) Template
Template warning: 'round' got invalid input '' when rendering template '{{ '-{}'.format(states('sensor.lux_batttery_discharge')) if states('sensor.lux_batttery_discharge')|round > 0 else '+{}'.format(states('sensor.lux_battery_charge')) }}' but no default was specified. Currently 'round' will return '', **however this template will fail to render in Home Assistant core 2022.1**
2:08:13 PM – (WARNING) helpers/template.py - message first occurred at 2:08:12 PM and shows up 2 times
Error while processing template: Template("{{ '-{}'.format(states('sensor.lux_batttery_discharge')) if states('sensor.lux_batttery_discharge')|round > 0 else '+{}'.format(states('sensor.lux_battery_charge')) }}")
Could anyone help me correct this? I’m stuck