Features Wishlist

Make Icon and Background Colours Template-able

bigwaveSuggested this wish ·

What would you like to add

Allow the colour of icons and the background change depending on the state of an entity.

How this relates to Home Assistant

I currently have a number of sensors indicating the online/offline status of devices. In Home Assistant I have the following that that makes offline devices much more obvious on dashboards by making their icons bright red.

Would it be possible to change the icon colour (or background colour) based on an entity state?

homeassistant:
  customize_glob:
    "binary_sensor.*":
      icon: mdi:console-network-outline
      templates:
        icon_color: if (state === 'on') return 'green';if (state === 'OK') return 'green';return 'red';

Image

Pictures, mockups, or examples

No response

Before submitting

  • I searched the existing issues and this has not already been requested

Originally shared on GitHubOriginal authors and dates are preserved.

View original

Discussion 1

Add a comment
bigwave

Figured out how to do this in override.yaml, it's a bit "fragile" as it hard codes the tile id, but it seems to work.

script:
  - id: update_background
    then:
      - if:
          condition:
            binary_sensor.is_on: ha_sonoffr2_1_problem
          then:
            # When Light is ON -> Set widget bg to Green
            - lvgl.widget.update:
                id: tile2
                bg_color: 0x00FF00
          else:
            # When Light is OFF -> Set widget bg to Dark Grey
            - lvgl.widget.update:
                id: tile2
                bg_color: 0x333333
binary_sensor:
    - platform: homeassistant
      entity_id: binary_sensor.sonoffr2_1_problem
      id: ha_sonoffr2_1_problem
      on_state:
        then:
          - script.execute:
              id: update_background

api:
  on_client_connected:
    then:
      - logger.log: "Connected to Home Assistant!"
      - script.execute:
          id: update_background

Original on GitHub

Add your thoughts, a screenshot or a useful link.

Markdown & basic HTML
Paste or drop images · URLs on their own line become previews0 / 10,000
Sign in with GitHub to commentYour draft stays in this browser tab.