Flip door sensor "closed" state color?

By default, it seems HomeAssistant’s state_color for a “door” class sensor is yellow when the door is open, and blue/default when the door is closed. That makes sense for something like an exterior door, however in my case this is an interior door that is normally open, so I want that to be the blue/default colour while closed is yellow. Can flipping the state colour like this be done?

Yes is possible. It will require card_mod and the method is dependent on the card type. Check out this thread

An alternative method would be theme based changes.

Smth lke (untested)

card_mod:
  style: |
    ha-card {
      --state-binary_sensor-door-on-color: red;
      --state-binary_sensor-door-off-color: green;
    }

if this is a binary_sensor.

Thanks all. I tried a few of these and generally got it working, but it seems the underlying issue is more fundamental (since it affects the graphs and such too). I think I’ll have to switch it to a different device class instead and just try to hack the icon.

Then use this:

which makes your changes global.

1 Like

I ended up just flipping a bunch of the logic in my custom sensor around, and changing the name so that the generic “On”/“Off” binary sensor values made sense.

Ultimately it seems what I wanted was not possible with just UI hackery; it’s a fundamental problem with with binary_sensor device classes in general which has never been addressed (which is a huge disappointment). Thanks though.

I’d share the sensor’s code/logic or at least and example if you are going to mark your post as the solution.

1 Like

I am not getting what is impossible & what was never addressed…
Do you have a link to particular issue or discussion on github?

Basically, I was caught in an X-Y problem. What I was asking for here was the Y, but my real X was that “Home Assistant doesn’t support custom binary sensor device classes”. What I really wanted was some sort of “inverted door” class, and what I meant by “underlying issue” is that even if I managed to get the UI to show how I wanted, internal state storage, automations, etc. were all “flipped” of what they should be (i.e. wanting “door closed” to be “on” and “door open” to be “off”). Unfortunately as per that link, this long-requested feature has never gone anywhere, and you’re stuck with HASS’s default logic of “Door Opened = On”.

So while I’m sure I could’ve made this work relatively well in the UI alone and I appreciate the advice on how to do so, ultimately I decided it was better to simply rename the sensor to “Door Closed” and leave it as a normal binary sensor without a device class, so I get “Door Closed = On/Off” where “On” is the closed state and “Off” is the open state. This ended up making everything consistent by default across not just the UI but all my automations, etc. as well.

I just use the not

If I have a binary_sesor the wrong way round

        value_template: >-
          {{not is_state("binary_sensor.bed_side_r",'on')}}

You also have the option to template your binary sensor as a cover.

UPDATED: This a much cleaner method than I proposed

You could also install the Spook integration and then use the inverse helper to invert the sensor.

The issue is neither option - templating or inverting - would actually change the issue I was having.

Basically if a binary_sensor is entity_class “door”, then “on” is “Open” and “off” is Closed. What I want is to flip that assignment basically. If I were to invert, then that would fix on/off being “wrong” but the device class would still assign those to Open/Closed and now those would be backwards.

Unless someone has a fully working example, so far in my reading (code and documentation) this just isn’t possible. I did have a potential draft PR written up to add a new “inverted_door” device class, but I haven’t submitted it yet because I fear it would just be rejected as unneeded, so I do want to try to exhaust the community’s knowledge first.