andrey-git / home-assistant-custom-ui

Custom UI elements for https://home-assistant.io
https://home-assistant.io
MIT License
528 stars 97 forks source link

icon_color templates doesn't work for 0.77.1 #150

Closed RomRider closed 6 years ago

RomRider commented 6 years ago

Checklist

Browser + Version: 68.0.3440.106

CustomUI version: 20180806

Home Assistant release (hass --version): 0.77.1

Problem-relevant configuration.yaml entries:

    sensor.dyson_pure_cool_link_bedroom_air_quality:
      friendly_name: Bedroom Dyson Fan Air Quality
      hidden: false
      group:
        group.bedroom.*:
          friendly_name: Air Quality
      templates:
        icon: mdi:recycle
        icon_color: >
          if (state >= 0 && state <= 3) return 'rgb(0, 255, 0)';
          else if (state >= 4 && state <= 6) return 'rgb(255,255,0)';
          else if (state >= 7 && state <= 8) return 'rgb(255, 140, 0)';
          else if (state == 9) return 'rgb(255, 0, 0)';
        _stateDisplay: >
          if (state >= 0 && state <= 3) return 'Good';
          else if (state >= 4 && state <= 6) return 'Good Enough';
          else if (state >= 7 && state <= 8) return 'Mediocre';
          else if (state == 9) return 'Bad';
          else return state

My entity looks like this in the entity state viewer:

unit_of_measurement: level
friendly_name: Bedroom Dyson Fan Air Quality
custom_ui_state_card: state-card-custom-ui
hidden: false
group: {
  "group.bedroom.*": {
    "friendly_name": "Air Quality"
  }
}
templates: {
  "icon": "mdi:recycle",
  "icon_color": "if (state >= 0 && state <= 3) return 'rgb(0, 255, 0)'; else if (state >= 4 && state <= 6) return 'rgb(255,255,0)'; else if (state >= 7 && state <= 8) return 'rgb(255, 140, 0)'; else if (state == 9) return 'rgb(255, 0, 0)';\n",
  "_stateDisplay": "if (state >= 0 && state <= 3) return 'Good'; else if (state >= 4 && state <= 6) return 'Good Enough'; else if (state >= 7 && state <= 8) return 'Mediocre'; else if (state == 9) return 'Bad'; else return state\n"
}
icon: mdi:recycle
icon_color: rgb(0, 255, 0)
_stateDisplay: Good

In the current state, the icon should be green, but it keeps the default color. The code is correctly evaluated because the icon_color attribute has the right value (icon_color: rgb(0, 255, 0)) but it doesn't change the icon color.

Problem-relevant Home Assistant log entries: No entry.

Any errors from browser Javascript console: Nothing.

bratanon commented 6 years ago

Same issue here

RomRider commented 6 years ago

@bratanon, I issued a PR, you can modify your local files directly if you don't want to wait, see #151

andrey-git commented 6 years ago

Fixed by #151