Confused about entity state values and colors

Hi folks. I’m a long time C software engineer but pretty novice with yaml. I’m very confused by certain states, state displays, and colors in HA/Lovelace.

I’m trying to use custom:button-card so I can change the icon for the gate and the garage door when it’s open or closed. FYI, I have an insteon TriggerLinc (door sensor) on the gate and an Insteon Garage Door Kit (IO-Linc switch and sensor) on the garage, both connected to ISY994i, exposed to HA through the ISY994 integration.

I think my problem is that the cover.garage_door returns state values open and closed, and the icon stays white. Strangely, the raw sensor for the gate TriggerLinc seems to return on and off, which changes the icon to the standard on and off colors in the theme. This is what I would like to get on the garage door icon.

I don’t want to necessarily set them to explicit colors because if I change the theme it’ll be all wrong. So I either have to get a state value that produces the right colors, or maybe extract the theme’s on and off color values? I’ve done all kinds of searches and I can’t figure out how to get colors from the theme.

Now, really strangely, my TriggerLinc gate sensor seems to return on/off state (given the “if” conditions), but the state shown in the custom:button-card state label is open/closed. This is what has me totally confused. The garage cover template seems to go to great length to return state values of open and closed in order for the state display to say the right thing.

Bottom Line: How can I get the Garage Door icon (pictured in the middle below) to change to the right colors?

Here are my cards, followed by my card code and template code.

image

image

type: horizontal-stack
cards:
  - type: 'custom:button-card'
    entity: binary_sensor.gate_triggerlinc_open
    name: Driveway Gate
    show_state: true
    state:
      - value: 'on'
        icon: 'mdi:gate-arrow-right'
      - value: 'off'
        icon: 'mdi:gate'
  - type: 'custom:button-card'
    tap_action:
      action: toggle
    entity: cover.garage_door
    show_state: true
    state:
      - value: open
        icon: 'mdi:garage-open'
      - value: closed
        icon: 'mdi:garage'
  - type: button
    tap_action:
      action: toggle
    entity: cover.garage_door
    name: Garage
    show_state: true
    hold_action:
      action: more-info
    icon: 'mdi:garage'
cover:
  - platform: template
    covers:
      garage_door:
        device_class: garage
        friendly_name: "Garage Door"
        open_cover:
          service: switch.toggle
          data:
            entity_id: switch.garage_door
        close_cover:
          service: switch.toggle
          data:
            entity_id: switch.garage_door
        icon_template: >-
          {% if (states.cover.garage_door.state) == "closed" %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

I don’t see it as an option in the Horizontal Stack GUI, but what happens if you add this to the code:

state_color: true

Thanks, but already tried that, and it didn’t change things. It’s reputed to default to “true” anyway.

It’s something about the state value open/closed not invoking the color. If instead of using the garage door cover template as the entity, I use the IO-Link input sensor (“entity: binary_sensor.garage_door_iolinc_sensor”) or the switch itself (“entity: switch.garage_door”), It appears to return state values on and off. It assumes the proper colors, and I have to use state values of on and off to get the icons to work (as depicted by the code below), but understandably it puts “On” and “Off” for the state label on the display as you can see in the image below.

What I need is the On and Off colors but the Open and Closed labels.

What I find confusing is that the Gate ToggleLinc sensor entity apparently returns state values on and off so the colors work, but the state label displays as Open and Closed, which is what I want, but it boggles the mind why. And gives me no clue of whether I can get the garage door to do the same thing.

entity: binary_sensor.garage_door_iolinc_sensor
state:
  - value: on
    icon: 'mdi:garage-open'
  - value: off
    icon: 'mdi:garage'

image

OH… Wait a minute.

So on the topic of why the gate TriggerLinc works correctly, look at the entity:

entity: binary_sensor.gate_triggerlinc_open

Notice it’s not called “gate_triggerlinc”, but rather “gate_triggerlinc_open”. This is a special ISY994i construct, and I think it returns neither On/Off nor Open/Closed. I think it returns something else, something that represents “true” and “false” conditions of it being “open”, and it is interpreted in the “if” yaml as on and off, but interpreted by the state display as Open and Closed.

FYI, trying to use 1 and 0 in the state/icon selector of the Gate button doesn’t work. It requires “on” or “off”. Super weird.

I’m fairly new to all of this myself, so just throwing out some ideas to try…
I’ve switched some of my motion sensors from reporting on or off to Motion/No Motion using a value template like below.

I’ve also switched the device class on some. I did that a while ago, so from memory I believe I did it to show the correct icon, but I’m not sure if that is any different than setting the icon manually. It may change the way your colors are displayed.

binary_sensor.door_front:
  device_class: door
      rear_patio_motion_sensor_status:
         value_template: '{% if states("binary_sensor.rear_patio_motion_sensor") %}
           {% if states("binary_sensor.rear_patio_motion_sensor") == "off" %}
             No Motion
           {% else %}
             Motion
           {% endif %}
           {% else %}
           n/a
           {% endif %}'
         friendly_name: Rear Patio Motion
         icon_template: "{% if is_state('binary_sensor.rear_patio_motion_sensor', 'on') %}mdi:motion-sensor{% else %}mdi:motion-sensor-off{% endif %}"

I think you’re onto something with the device class. I was looking at the Gate TriggerLinc sensor definition in the Developer Tools | States list, and in its attributes it says,

  device_class:opening

I tried changing the garage_door cover template to a “device_class:opening” and it gave me an error – it conflicted with the “cover” template. I think my main problem here is the “cover” template type. Since the garage door isn’t really a cover that starts and stops, it doesn’t really need the attributes of a “cover”. So I’m going to change its class type and see if I can get it to assume the “device_class:opening” attribute. And then still return the Open/Closed value in the manner you outlined above so I can get the status label display that I want. Hopefully this will make it work like the Gate IO-Linc sensor.

I have a basic question: Why do you apparently sometimes have to have single quotes around the if-then-else clause, and sometimes you don’t? I’ve seen it both ways. Does it matter?

Thanks again.

End result: I got the garage door cover to indicate open and closed icons, and I got them to change colors in doing so to the standard “on” and “off” colors of the theme.

I finally figured it out. There are so many tiny details that have to be right or something doesn’t work. The general take-away was to uncover the intended base operation; don’t try to do too many fancy overrides. They just complicate things. There’s a lot built in. Too bad most of it is “occult”.

Never did figure out why some sensors change the color and others don’t.

What worked for me is listed below. It turned out the critical elements were:

  1. Keep the cover template simple. Just do the switch functions. Don’t try to manipulate the value or the icon. (Note that my switch is a toggle-open toggle-close, yours may be different.)
  2. Customize it with the “garage” device type. Why the garage cover wouldn’t take the garage device type is beyond me. The “garage_door” device type did NOT work IIRC.
  3. Use the standard button card. The cover functionality is not supported by the ‘custom:button-card’.

(Ignore my use of friendly_name. It was just for debugging.)

cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garage Door"
        open_cover:
          service: switch.toggle
          data:
            entity_id: switch.garage_door
        close_cover:
          service: switch.toggle
          data:
            entity_id: switch.garage_door
homeassistant:
  name: Home
  unit_system: metric
  # etc

  customize:
    # Add an entry for each entity that you want to overwrite.
    cover.garage_door:
      friendly_name: "Garage Opener"
      device_class: garage

And in the Lovelace:

  - type: button
    name: Garage
    tap_action:
      action: toggle
    entity: cover.garage_door
    show_state: true
    hold_action:
      action: more-info