0

I have a homeassistant android widget using the html template format:

<font color='blue'>{{ states('sensor.mystate') }}</font>

How can I change the color conditionally based on the value of the sensor? Is it possible to add if/else conditions into the widget html template somehow?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

1
{% if states('sensor.mystate')|int > 75 -%}
  {% set color = 'green' %}
{%- else -%}
  {% set color = 'red' %}
{%- endif %}
{{ color }}

<font color='{{ color }}'>{{ states('sensor.mystate') }}</font>
membersound
  • 81,582
  • 193
  • 585
  • 1,120