Zigbee2mqtt device-specific configuration not working

HI! I’ve been trying to reverse the state of my SNZB-04, as I’ve repurposed it as a bed occupancy sensor (inspiration from here and here). I’ve been trying for hours to reverse the contact sensor state and classify the device as an occupancy sensor when paired. I know that I can create a custom template sensor, but I want it to show up under my Device in HA, so I would like to reverse it at the zigbee2mqtt level

Steps done:

  1. Pair the device to get the device ID (e.g. 0x00124b0024451e30)
  2. Add the custom configuration as suggested here
  3. Delete the device from HA (as outlined here)
  4. Restart zigbee2mqtt

I’ve also tried:

  • Restarting Home Assistant
  • Not deleting the device from Home Assistant
  • Adding the custom device configuration directly to the zigbee2mqtt config
    • Through HA frontend (Settings → Add-ons → Zigbee2mqtt → Configuration)
    • Through File Editor: /config/zigbee2mqtt/configuration.yml
    • Through SSH: /config/zigbee2mqtt/configuration.yml
  • Trying all of the above multiple times in different order etc…

This is my zigbee2mqtt config:

data_path: /share/zigbee2mqtt
socat:
  enabled: false
  master: pty,raw,echo=0,link=/dev/ttyZ2M,mode=777
  slave: tcp-listen:8485,keepalive,nodelay,reuseaddr,keepidle=1,keepintvl=1,keepcnt=5
  options: "-d -d"
  log: false
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://192.xxx.xx.xx:1883
  user: homeassistant
  password: xxx
  availability: true
serial:
  port: >-
    /dev/serial/by-id/usb-Silicon_Labs_slae.sh_cc2652rb_stick_xxx
external_converters: []
devices:
  "0x00124b0024451e30":
    homeassistant:
      contact:
        payload_on: true
        payload_off: false
        device_class: occupancy
        icon: mdi:motion-sensor
  "0x00124b00244523c6":
    friendly_name: Bed config debug
    homeassistant:
      contact:
        payload_on: true
        payload_off: false
        device_class: occupancy
        icon: mdi:motion-sensor
groups: groups.yaml
homeassistant: true
permit_join: false

For the life of me, I can’t seem to affect any of my devices in any way.

I solved my issue halfway through writing this post (rubber duck debugging strikes again!).

I was editing the configuration.yaml and devices.yaml files in the /config/zigbee2mqtt/ directory. The correct file that I needed to edit was /share/zigbee2mqtt/devices.yaml.

What should’ve raised a red flag was that the /config/zigbee2mqtt/devices.yaml file didn’t exist and I had to create it. Eventually re-reading the first post here and using IntellIJ IDEA to visualise the file tree helped me see that there’s another place for zigbee2mqtt configs.

I hope this topic helps some other poor soul that stumbles upon the same issue.

I can not find zigbee2mqtt in the share folder. Only in config I can find it. And the only code with my devices is in the configuration.yaml (config/zigbee2mqtt/configuration.yaml)
Is there changed something?

If your config/zigbee2mqtt/configuration.yaml file reflects what you see in the UI, then it’s probably the right one. If not, I suggest doing a filesystem-wide search for zigbee2mqtt to find the real configuration.yaml. It’s probable that my system has some remnants of the past, as I’ve been running home assistant for years.