Minimalist UI - use if condition in labels

Hey there,

is there a way to us interactive labels for minimalis ui? I use the custom room card and realy like it’s look. I wanted to add a voc-index to the label not showing the numbers, but like green-orange-red status. Is there a way to configure conditional statements?

- type: grid
  columns: 2
  square: false
  cards:
    - type: custom:button-card
      template:
        - card_esh_room
        - yellow_on
      name: Arbeitszimmer
      entity: switch.arbeitszimmer
      icon: mdi:desk
      tap_action:
        action: navigate
        navigation_path: arbeitszimmer
      variables:
        ulm_custom_card_esh_room_light_entity: switch.arbeitszimmer
      label: >
        [[[
          return "🌡️ " + states['sensor.temperatur_arbeitszimmer'].state + " °C" + " 💧 " + states['sensor.luftfeuchtigkeit_arbeitszimmer'].state + " % "
        ]]]

          {% if states('sensor.voc_index') > 150 %}
            rot
          {% else %}
            grün
          {% endif %}

          states["sensor.voc_index"] > 150 ? 'rot' : 'grün'

Thanks a lot for your help,
Anduril

I found the solution myself. The correct code for the label part is:

return "🌡️ " + states['sensor.temperatur_arbeitszimmer'].state + " °C" + " 💧 " + states['sensor.luftfeuchtigkeit_arbeitszimmer'].state + " % " + (states["sensor.voc_index"] > 250 ? '🟠' : (states["sensor.voc_index"] > 150 ? '🟡' : '🟢'))

well this does result in a green circle, but does not correctly represents yellow and red. I suppose the ? term is not correct, but I don’t find any documentation about that…

How to use shorthand for if/else statement in JavaScript | bobbyhadz :slight_smile:

thank you for that docs, that’s the way I tried to use it.
I just build a little test code in my dashboard: a number input to influence the label of the title card above. But this always shows the “no”… I don’t know why

  - type: 'custom:button-card'
    template: card_title
    name: If/Then/Else Tester
    label: >
              [[[
                return ((states["input_number.test"] > 70.0) ? "yes" : "no" )
              ]]]

  - type: entities
    entities:
      - entity: input_number.test

grafik

[[[
  return ((states["input_number.test"].state > 70.0) ? "yes" : "no" )
]]]

You need the state as well, but I’m not sure, what type the state in this case is (string or int). Maybe you need to add an int filter as well.

[[[
  return ((states["input_number.test"].state | int > 70) ? "yes" : "no" )
]]]

Try it. :slight_smile:

Thank you very much, I forgot the .state and now it works.

1 Like