Closed jjvelar closed 1 year ago
this is an MQTT sensor issue. read the error: it says the attributes: option is not allowed for MQTT sensor.
you can however use the
homeassistent:
customize:
sensor.inverter_bat_status_description:
templates:
icon_color:
version and use a correct js template
Thanks for your quick reply. You guys provide the best customer support.
Tried this but icon is not showing. And if I remove the icon piece, color is also not turning into green or red.:
customize:
sensor.inverter_bat_status_description:
templates:
icon: >
{{'mdi:check-bold' if states('sensor.inverter_bat_status_description') == 'Running' else 'mdi:alert-circle'}}
icon_color: >
{{'green' if states('sensor.inverter_bat_status_description') == 'Running' else 'red'}}
Any help will be highly appreciated. Thanks in advance.
check the docs... as said, you need js templates not the Jinja template we use in HA template sensors.
homeassistant:
customize:
sensor.inverter_bat_status_description:
templates:
icon: >
return (state === 'Running') ? 'mdi:check-bold' : 'mdi:alert-circle';
icon_color: >
return (state === 'Running') ? 'green' : 'red';
That worked. Thanks a lot, Marius.
Hi,
I am trying to add dynamic icon and icon color to an MQTT sensor but it shows an error when verifying the configuration.
Here you've got the code and the error. How can I fix it? Thanks!
Invalid config for [mqtt]: [attributes] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor->31->attributes.