If then —> green or red

Hi, I would like to code a helper but I unfortunately I don‘t know what is the best way :slightly_frowning_face:

If entity A is higher then B a helper should show a „Yes“. Else the helper should show a „No“. Both entities are humidity sensors which display the absolute humidity in g/m3. It would ideal if there is a way to work with colours instead of „yes“ and „no“. That means, if A is bigger then B the helper shows a green circle.

What kind of helper is appropiate and how could look the code? It would be great if I could get support.

Many thanks in advance.

Create a Template Sensor helper.

Here’s the template it will use (change the entity_ids to match your own)

{{ iif(states('sensor.humidity1') | float(0) > states('sensor.humidity2') | float(0), 'Yes', 'No') }}

An entity’s state value is displayed by a card. However, the standard set of cards don’t provide control of the value’s color (other than the Markdown card, using an HTML Font tag).

Certain custom cards support it and I believe, a custom ‘card helper’ called card-mod.

Let me know when you have created the Template Sensor helper and we can take it from there.

1 Like

Thanks! It works…at least the output „yes“ or „no“. I will try to implement the colour green or red alone with your helpfull tips. Thanks a lot.

Don’t do it alone. At least share your final solution because someone else will have a similar question in the future.

The Markdown card’s template will look something like this:

{% set x = states('sensor.your_template_sensor') -%}
{% set c = iif(x == 'yes', 'red', 'green') -%}
High humidity: <font color='{{c}}'>{{x}}</font>