Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coloured states not possible? #209

Closed
kamcioo opened this issue Oct 17, 2021 · 4 comments
Closed

Coloured states not possible? #209

kamcioo opened this issue Oct 17, 2021 · 4 comments

Comments

@kamcioo
Copy link

kamcioo commented Oct 17, 2021

I would like to colour the states but I try and try and nothing work:

`type: entities
entities:

  • entity: sensor.temperatur_aussen_temperature
    type: custom:multiple-entity-row
    name: Außen
    secondary_info: last-changed
    show_state: false
    entities:
    • sensor.temperatur_aussen_temperature
    • entity: sensor.temperatur_aussen_humidity
  • entity: sensor.wandthermostat_temperature_2
    type: custom:multiple-entity-row
    name: Flur unten
    secondary_info: last-changed
    show_state: false
    entities:
    • entity: sensor.wandthermostat_temperature_2
      styles:
      color: red
    • entity: sensor.wandthermostat_humidity_2
      styles: >-
      {% if states('sensor.wandthermostat_humidity_2') >= '70' %} color: red
      {% elif states('sensor.wandthermostat_humidity_2') >= '60' %} color:
      orange {% else %} color: green {% endif %}
      `
      with styles, color it works but when I use if & else, it don’t work any more? Do I do something wrong or it isn’t possible to colour the states?

Thank You in advance,
kamil

@ildar170975
Copy link

You are trying to use jinja templates where they are not supported.
For conditional styling, use card-mod or config-template-card.

@fabricioavil
Copy link

Hi,
In case it helps as a workaround, I do it via customize.yaml.
I added examples here.
HTH.

@harrv
Copy link

harrv commented Oct 27, 2021

@kamcioo I've been trying to do nearly the same thing as you've been trying to do. @ildar170975 is right: multiple-entity-row doesn't support using jinja templates in that way. However, it does support card_mod, and I found that to be the easiest way to get the result I wanted. In your case, just install card_mod in HACS, and then replace the styles key and value in your config above with the following card_mod:

card_mod:
  style: |
    :host {
    --paper-item-icon-color:
      {% if (states('sensor.wandthermostat_humidity_2') | int) >= 70 %}
        red
      {% elif (states('sensor.wandthermostat_humidity_2') | int) >= 60 %}
        orange
      {% else %}
        green
      {% endif %}
      ;
    }

Note that this will change the icon color based on the state. From your original post, it's unclear to me whether you are trying to change the icon color or the color of some other UI element.

Also note that you can use the name of a color, or you can use an RGB code like: #03a9f4

You can also use the default color lovelace uses when a device is in the off state by using: var(--state-icon-color)

@ildar170975
Copy link

If styling of secondary items is required:
possible styling is explained here:
https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/1190

@benct benct closed this as completed Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants