Change color label text with if statement for other entity on or off

Hi, I am trying to change the color of the text value and prefix for an entity when the status of another entity is on or off.

I have done the below, but it does not change the color. what am I missing or doing wrong?

type: picture-elements
elements:
  - type: state-label
    entity: sensor.ithodaalderop_amber_domestic_hot_water_temperature
    prefix: "TW (boiler): "
    card_mod:
      style: |
        :host {
          background: {{ 'red' if is_state(binary_sensor.ithodaalderop_amber_water_flow_switch, 'on') else 'black' }};
           }
    style:
      top: 4%
      left: 29%


And I tried with a variabel set:

  - type: state-label
    entity: sensor.ithodaalderop_amber_domestic_hot_water_temperature
    prefix: "TW (boiler): "
    card_mod:
      style: >-
        ha-card {
        --boiler_heat: {% if state_attr('binary_sensor.ithodaalderop_amber_water_flow_switch') =="on" %} red {% else %} black {% endif %}
        }
    style:
      top: 4%
      left: 29%
      color: var(--boiler_heat)

What am I doing wrong? or what is missing?

You are missing Docs and a proper syntax.

is_state('binary_sensor.xxx','on')

state_attr('binary_sensor.xxx','name_of_attr')

1 Like

Thank you very much! That solved it!

1 Like