New binary_sensor device class 'relay'

There are an awful lot of relay boards out there being used with HA, but there’s no way to directly represent them without resorting to template hacks, and even that gets ugly when you’re dealing with things like 8-16 channel relay boards. This is a request to add a new device class ‘relay’, icons mdi:electric-switch and mdi:electric-switch-closed, for use with relay boards.

Why not use switch?
Your icons are even switches, that is not a relay.

There’s no switch device class. Unless it’s there but not documented.

Just tried it, there’s no device_class: switch, even an undocumented one.

Switch is a domain. e.g.


You control switches. Like you control if your relay is on or off.

Why are you using a binary sensor?

Binary sensors are inputs that you do not control.

I was trying to avoid getting get bogged down in lots of low-level detail, it eventually ends up in Modbus devices which have non-orthogonal reads and writes of coils, the Modbus term for inputs and outputs. Coils are read in groups with one bit per coil but written using a different command set using magic values to set, clear, toggle, and other things, a coil. Everything’s going via an MQTT broker, which is an extra level of abstraction.

All I need for now is the ability to display the state of various inputs and outputs, which is just a straight read of the state value, and that’s representing “contact open” and “contact closed” for which a switch device-class and icon seemed perfect.

You can easily change the icon if you want.
But not sure what the benefit of a new device class is.
What should it report? On/off?
That is what the standard binary sensor also reports.
As far as I know, the reason you can choose different classes is to make it report as open/closed or something else than on/off.
In this request you want to just change the icon?

Edit sorry, didn’t see the contact open/closed.

While I was searching for possible solutions for this I noticed that there seem to be quite a number of relay and digitial I/O boards and devices out there for use with HA, so it seemed like it’d be a useful addition to have and (hopefully) not a big amount of work to add.

The thing is, people connect relays to something to be controlled. That something is what you then set as your device class.

A relay connected to a garage door controller use the device class garage_door.


Sure, but a lot of the stuff being controlled doesn’t fit into any device class, for which ‘relay’ is a generic type that describes the function and shows the contact state. For example one of the things I’m monitoring, or at least planning to monitor, is a set of contactors for load-shedding in electrical equipment, for which no device class even begins to describe what they do. A generic “relay contact open/closed” OTOH fits it pretty well.

On off seems appropriate.
I really don’t see the benefit here. I have never thought of a smart plug as a relay even though it is.
I see it as the connected device.
I think your thinking is rather unique. Nothing wrong with that.

But as mentioned before. This is the binary sensor we are talking about here.
There is also a switch that actually controls the relay.

1 Like

You might like to vote for this: Custom device classes

Ah, yeah that would fit perfectly. Thanks.