Change a Binary Sensor to a Door or Window Device_Class?

Sorry for the long post, but I’m pulling out what little hair I have left and have read so many posts that provide examples that aren’t working but are also several years old, so I’m not sure if I’m doing things wrong or if those are just out of date…

Anyway, I have several binary sensors that are ST multipurpose sensors and are attached to doors and windows (as open/close sensors). They are using the Zigbee integration and showing as binary_sensors (with entity id’s ending in ‘_ias_zone’).

I would like to change their device_class to be doors and windows so they show up correctly without having to manually change them in the UI. Actually, what I really want is to be able to create dynamic groups for doors and windows by using the device_class similar to what I do for lights.

What I’ve tried:

  • Based on the binary_sensor integrations page, I’m assuming I can set a device_class to window or door.

  • So the first thing I tried was setting up a ‘window’ section similar to my ‘light’ section:

Light Section:

light:
  - platform: switch
    name: Master Bedroom Closet Light
    entity_id: switch.mbc_switch_closet
  - platform: switch
    name: Pantry Light
    entity_id: switch.kit_switch_pantry

Similar solution for Window (but just gives an Integration error: Integration ‘window’ not found. error when I do a ‘Check Configuration’).

window:
  - platform: binary_sensor
    name: Game Room Window
    entity_id: binary_sensor.game_sensor_window_ias_zone
  - platform: binary_sensor
    name: Loft Window
    entity_id: binary_sensor.loft_sensor_window_ias_zone
  • The next thing was trying to decipher the customizing devices page, which gives two options: UI or YAML:

    • UI: The page only describes changing the entity id name (without modifying the domain portion), but not what, if any, change I’m supposed to make to reflect a new device_class. So does changing the entity name (e.g., from ‘binary_sensor.game_sensor_window_ias_zone’) somehow change the device_class? If so, what is the appropriate new name?

    • YAML: The page also describes a YAML change which includes an option for ‘device_class’, but doesn’t provide good info on the customization syntax. Further down the page, it provides some examples.

I tried the following, but it gives a configuration error: Integration error: customize - Integration ‘customize’ not found.

customize:
  binary_sensor.game_sensor_window_ias_zone:
    device_class: window
  binary_sensor.loft_sensor_window_ias_zone:
    device_class: window

The same page (and various forum posts) mention that the ‘customize’ needs to be in the ‘homeassistant:’ section as:

homeassistant:
  name: Home
  unit_system: metric
  # etc

  customize:

But I don’t have a ‘homeassistant:’ section in my configuration.yaml and didn’t want to add it without a better understanding (especially since there is also a reference to an include for customize.yaml, which I also don’t have (the include or the corresponding .yaml file)).

So I’m a bit at a loss as to how to get door and window device_classes set up correctly.

Any help would be appreciated! Thanks in advance!

Find the entity list under your configuration menu and then click the sensor you want to change and select the option you want in the Show as field.

This is where you change it in GUI

It’s no problem creating these “missing” files.
I believe if you add the lines of yaml and not create the files then all you get is a warning or error in the logs until you create the file.
Adding the customize file means you can (with custom-UI) specify the color and or icon depending on states.
Example:

customize.yaml:

input_boolean.kaffe_andreas:
  templates:
    icon_color: if (state === 'on') return 'rgb(0,255,0)'; else return 'rgb(255,0,0)';
    icon: if (state === 'on') return 'mdi:coffee'; if (state === 'off') return 'mdi:coffee-off-outline';

Change icon and color depending on the state. And you can also change icons depending on other entities states:

sensor.nya_plattan_battery_level:
  friendly_name: Nya plattan battery level
  templates:
    icon_color: if (entities['sensor.nya_plattan_battery_state'].state == 'charging')
      return 'rgb(0, 255, 0)'; if (entities['sensor.nya_plattan_battery_state'].state
      == 'discharging') return 'rgb(255, 205, 0)';

Here is my entities list for the door and window sensors (plus a motion sensor):

All of the door and windows are ST multipurpose sensors.

But, I can only change the “Show as” on two of them (which is why I didn’t see this yesterday). Here is one of the two that are “working”:

and here is a non-working one:

Notably, the only difference I can see between the ones that are working and the ones that are not is that the working ones are “gen 2” multipurpose sensors (the rounded ones) versus all the ones that are not working are “gen 1” (the rectangular ones).

Any ideas on why some are working and some are not? Any ideas on getting the gen 1’s to work (if that is, indeed, the problem)?

Door and Window can only be selected on binary_sensors.
Can it be that the non-working sensors are not following the rules for what values a binary sensor can have?

They are all listed as binary_sensors.

Not sure how I would determine that they are not following the rules for what values a binary sensor can have. Per the logbook for one of them, it is listed as having “turned on” and “turned off” many times without any other values.

I am sorry, but you need someone with more knowledge on the workings behind the HA GUI than me. :slight_smile:

Perhaps you can try the customize.yaml approach?

Just to close this out, I was able to create a “customize.yaml” file and add the Windows and Doors to it. I included the customize.yaml in my configuration.yaml after the usual includes as:

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize: !include customize.yaml

My customize.yaml file looks like this:

# Windows
binary_sensor.gameroom_window_ias_zone:
  friendly_name: Gameroom Window
  device_class: window
binary_sensor.loft_sensor_window_ias_zone:
  friendly_name: Loft Window
  device_class: window
binary_sensor.mb_sensor_pauls_window_ias_zone:
  friendly_name: Pauls Window
  device_class: window

# Doors
binary_sensor.laundry_sensor_back_door_ias_zone:
  friendly_name: Laundry Closet Door
  device_class: door
binary_sensor.kit_sensor_pantry_ias_zone:
  friendly_name: Pantry Door
  device_class: door
binary_sensor.kit_sensor_sliding_ias_zone:
  friendly_name: Kitchen Slider
  device_class: door

Which so far seems to work. Still fiddling with my lovelace dashboard to switch from using groups to using the devices (doors, windows).

Thanks for the directions!

1 Like