Giving an device_class to a input_boolean

See title, should end this be possible? Or am I missing something?

Like this:

input_boolean:
  guest:
    name: guest
    icon: mdi:account-outline
    device_class: presence

or like this:

But both don’t work

Why don’t you just create a binary_sensor using the relevent input_binary then apply the device_class to the binary_sensor ? That way you have a device to act on and a device to display.
(BTW you can apply custmisation to the input_boolean to make its icon different or even dynamic according to state (not necessarily it’s own)

1 Like

Giving an device_class to a input_boolean

Why?

Binary_sensors support device_class and it influences their appearance (icon and text) in the Lovelace UI. For example, if device_class is door, its icon will be a door and the displayed text will be open or closed (instead of on/off).

So if an input_boolean had a device_class, how would that change its appearance in the UI? An input_boolean doesn’t display text so is this Feature Request just to control the icon’s appearance? If so, there are already other ways of doing that.

Yes, it is purely a user experience (ui) question/ request. And maybe only with a very small use case, but it’s buggy me for some time now. That’s why I decided to requist this. Sorry for not explaining myself further in the first request.

Concistancy
On the page customizing-devices it explains how to customize entities, why not keep it consistent for all entities including input_boolean? Or explain for witch entities types this does and does not work for.

My situation
Many of my automation ar dependent on somebody being home or not (alarm, lights, music, etc). The precence of my family goes automatic, but there are always exceptions aka guest. Like a baby sitter.

On top of my main view i now have a row of badges with my family members including the boolean guest. All the person.xxx entities all have a icon and blow the text home or away. Except the guest boolean.
I know I can change this with a template sensor, but this feels hacky and removes the ability to click on it to change it manually.
badge

If I miss something or some way to do this differently, I am definitely interested.

1 Like

I need this just to change the input boolean state from on/off (default) to home/away (device_class: presence)
Why not a binary sensor? because I change the input_boolean’s state directly from the UI.

2 Likes

The state names of input_booleans and binary_sensors are unchangeable. Both use on and off. Go to Developer Tools > States and confirm this for yourself. For example, the shed_door is closed so its state is off.

Screenshot from 2020-04-08 11-31-03

The sole difference with binary_sensors is that they support device_class which can translate on and off to something else for display in the Lovelace UI. For example, the shed_door’s device_class is door so a state of off is displayed as Closed.

Screenshot from 2020-04-08 11-33-26

There’s no point in adding device_class to input_booleans because, in the Lovelace UI, they do not display their state names. For example, Fan Power is off but that text is not displayed in the UI.

Screenshot from 2020-04-08 11-32-11

Ok understood.

But I display my input boolean like this:


And I would like the Guest boolean to display “Home” or “Away” like my other sensor. The difference here is that by clicking on the input_boolean I can change its state which will impact my automation.

It is just a small UI thing :slight_smile:

2 Likes

You’re using a custom card to render the input_boolean. That’s what I implied when I stated in my previous post; “there are already other ways of doing that”. Just use the custom card to translate the input_boolean’s state to whatever you desire (and, optionally, in whatever language desired). This is the standard way of handling this requirement.

No custom card here, I’m using the glance card:

entities:
  - entity: person.x
  - entity: person.y
  - entity: binary_sensor.esp_garage_presence_car
    name: Car
  - entity: input_boolean.guest_at_home
    tap_action:
      action: toggle
state_color: false
type: glance

I understand that I may be doing this with a custom card but I avoid everything custom for HA (there are enough breaking changes with each releases :slight_smile: )

The point is that unless you “take control” of the Lovelace UI, the default rendering of an input_boolean is the entities card which does not display state values for an input_boolean. Depending on which other card you use, it may offer the ability to display an input_boolean’s state names using whatever terminology you prefer (which makes it unnecessary to require a device_class).

In contrast, the default rendering of a binary_sensor is a badge that does display the state names so the concept of device_class is useful.

Still no update on this? I find this suggestion super helpful too.

I created an input boolean to record the state of a cheap RF433 contact sensor. I want it to show green when in contact and red when apart. The interface is in reverse now. If I reverse the boolean definition, the state in Lovelace cards is then in reverse: lighting up when in contact and going off when apart.

It’s too much burden to create another sensor just for some additional UI beauty.

5 Likes

There’s a textual representation of input_boolean’s state at the default entity card. And it still says just “On” or “Off”. It’ll be really helpful to have such ability… yes/no, home/away, occupied/not.

2 Likes