Custom device classes

Rather than maintaining an ever growing list of binary type device classes to support things like people having windows that open horizontally or gates or mailboxes, etc…

Could a custom device class option be implemented that would be defined something like this:

device_class:
  - binary_sensor:
      - <device_class_name>:
          state_off: <off state word>
          state_on: <on state word>
          icon_off: <mdi icon for off state>
          icon_on: <mdi icon for on state>

All options under name would be optional with undefined options defaulting to the device_class: none states and icons.

e.g.

device_class:
  - binary_sensor:
      - gate:
          state_off: 'Closed'
          state_on: 'Open'
          icon_off: 'mdi:gate'
          icon_on: 'mdi:gate-open'
      - maibox:
          state_off: 'Empty'
          state_on: 'Full'
          icon_off: 'mdi:mailbox'
          icon_on: 'mdi:mailbox-up'

EDIT: Cover and switch device classes too, see post 5 in this FR.

I would also appreciate the ability to use custom device classes like this. I’ve got some binary sensors that don’t fit into the “normal” categories. Some are alarms, some are status (like steam pressure OK vs LOW), and some are RUNNING vs FAULT. Tom has presented a good idea that I could use as-is.

I voted support for this also.

I was only really looking for a way to customise the mdi icons for the binary sensor motion device class.

  • I find the current ones (person and beacony thing with and without a slash) to be busy and not readily discernable.
    But it appears this customisation connot be done.
    I can customise the device class of all my sensors by a glob match… to, say “movement” but then the text isnt quite right.
    I can also do customisation at UI level but its then a per-entity type thing and a lot of work/maintenance.

Toms proposed approach is much more generalised… I think it’s a good idea.

This is a great idea. I was actually searching to see if someone had suggested an active/inactive device_class (of which I would have 3-4 already), but making device_class completely customizable is probably the best option.

A similar method could be used for covers and switches:

device_class:
  - binary_sensor:
      - gate:
          state_off: 'Closed'
          state_on: 'Open'
          icon_off: 'mdi:gate'
          icon_on: 'mdi:gate-open'
      - maibox:
          state_off: 'Empty'
          state_on: 'Full'
          icon_off: 'mdi:mailbox'
          icon_on: 'mdi:mailbox-up'
  - cover:
      - double_garage:
          state_off: 'Closed'
          state_on: Open'
          icon_off: 'mdi:garage-variant'
          icon_on: 'mdi:garage-open-variant'
  - switch:
      - television:
          icon_off: 'mdi:television-classic-off'
          icon_on: 'mdi:television-classic'
2 Likes

I’m glad I’m not the only one that would like something like this. I currently have been sifting for an option to show pressed(on) and released(off). Please guys can we fit this in.

any news about it? I think it would be really interesting

Nope. I was hoping there would be a WTH month this year as part of the “streamlining” theme in which I could bring it up. But this has not happened.

Hard to believe this is still not implemented. It’s such a no-brainer. The hard coded device classes are really limiting, considering the amount of novel smart devices entering the market and all the DIY devices around.

2 Likes

I would like to add closing and opening here as well for this FR as this are states with (not that beautiful) icons, etc. for cover as well.

This is very very needed function.

Another vote! great idea

Where to put this config? I was try put in configuration.yaml but end with Integration error: device_class - Integration ‘device_class’ not found. when I do config validation…

You don’t put it anywhere.

Look at the category where this is posted, “Feature Requests”.

It is a request for adding this feature. It does not exist yet.

Vote for it and it might.

ohh…, okay. Vote done.

besides this (+1 mine is there) I also wroteup add on/off options for icon · Discussion #13700 · home-assistant/frontend · GitHub

so we can set an on/off icon on any entity, and not only a generic icon and not specifically requiring a device_class at all.
Tbh, its a bit if a mystery the current HA frontend lacks that rather basic functionality in UX and feedback.

(just so you are aware: all of these options/wishes on states used for the icon selecting mentioned above are available with custom-ui, but I dont want to advertise that anymore…)

I think an easier starting point is simply if I assign an icon x=mdi:gate
then if x-open exists (mdi:gate-open), then use it when the state is on/open.
Most icons are already named like this. It wouldn’t need any definitions at all.

1 Like

This proposal far more flexible and powerful. Feel free to open your own request.

But not all and therein lies the problem… There’s no control over the MDI set (from HA) and there are other sets people use too. This is what’s called a tight coupling between “systems” which generally is a bad idea.

2 Likes

Another vote from me!

1 Like