Show state without measurement on glance card

Hi all,

I’m using the MéteoFrance integration to get weather information. I’d like to show the state without the unit of measurement. For example, if the UV level is 4 UV level, in the States section of Develoer Tools, it shows that for the sensor (let’s call it sensor.uv), the state is 4, and in the attribute, “unit_of_measurement: UV index”.

When using the glance card, I can’t seem to get rid of the unit of measurement. It always shows “4 UV index”. I’m successfully using card_mod to change the color based on the level of the UV index, but I don’t want it to say 4 UV index, just “4”.

Can someone point me in the right direction please?

Thank you in advance.

One round-about way is to create a new template sensor that has the same value but no unit.

@jchh

Thank you for your suggestion. I was hoping to avoid this! :wink:

This is what I have so far.

type: glance
card_mod:
  style: |
    ha-card {
      margin: -20px 0px 0px 0px;
      padding: 0px;
      --ha-card-border-radius: 0px 0px 12px 12px;
      --ha-card-background: silver;
      border-top: 1px solid gray;
    }
    ha-card .entities.no-header {
      padding-top: 6px;
      padding-bottom: 5px;
    }
    ha-card .entity {
      font-weight: bold;
      margin-bottom: 0px;
    }   
entities:
  - entity: sensor.berlin_center_uv
    name: UV Index
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int <= 2 %} 
              green
            {% elif states(config.entity) | int <= 5 %} 
              yellow
            {% elif states(config.entity) | int <= 7 %}
              orange
            {% elif states(config.entity) | int <= 10 %}
              red
            {% elif states(config.entity) | int >10 %}
              maroon
            {% endif %}
            ;
        }
        .name {
          font-weight: normal;
          color: #404040;
        }

This gives me this:
image

What I want is this:
image

Thank you.

Does it have to be a glance card? There are easy ways to do this (without creating a template sensor) with the entities card or custom:button-card for example.

The glance card doesn’t allow for templating (hence my question).

Let me try the custom:button-card again. I tried before, but I can’t remember why I went to the glance card. Standby …

let me know if you need help.

Thanks @jchh,

Decided to try different things. The button-card may work, but now I’m trying to complicate things even more by putting in gauges, etc. etc.

I’ll post what I end up with !

1 Like