Zigbee2MQTT: Disable discovery, but still get entities associated with device

I’m currently experimenting with all the different gateways. The idea of having my Zigbee network decoupled from HA is lucrative, so Zigbee2MQTT is an option I’m trying as well.

I would ideally want a “file-as-configuration” set-up, where I specify all the devices in my network, and a completely new HA install would add them because they are exposed via the Z2M gateway. In other words, I want discovery OFF for maximum flexibility.

However I noticed that when discovery is off, no devices are ever added to HA. Instead, you expose each entity of a device separately, and there is no grouping between them whatsoever (unless you create a group manually, also via yml files).

Is there an option to have the cake and eat it too? Expose device-per-device, through config-files, and still get entities belonging to the same device to show be grouped like so?

For example the Aqara temperature sensor exposes: temperature, humidity, etc…I’d like to have those grouped under the same device in the UI while NOT using MQTT in discovery mode.

I don‘t get it, devices that are known to Zigbee2MQTT get discovered by HA‘s MQTT discovery feature including all entities. Of course the entities are associated with the device.

That’s what I don’t want. I don’t want devices added automatically. I want to be able to choose which device is added, meaning I want discovery OFF (HA will only recognize devices what’s defined in its config files, and Z2M exposes only those devices).

Yes but it requires more work.

First, you have to disable Zigbee2MQTT’s use of MQTT Discovery. In Zigbee2MQTT’s configuration.yaml file, set homeassistant: false (and restart it). All of the Zigbee devices and entities that have been discovered by Home Assistant will disappear.

Second, you must define the entities. However, as you have already discovered, in YAML you can only create entities manually not devices. In other words you cannot manually create a device (in YAML), with associated entities, it can only be created via MQTT Discovery. In fact, it even mentions that in the documentation for MQTT Sensor:

device map (Optional)

Information about the device this sensor is a part of to tie it into the device registry. Only works through MQTT discovery and when unique_id is set.

The solution is to create a script that uses MQTT Discovery. In other words, you will use a script to create the device and entities using the same technique that Zigbee2MQTT employs. However, because it’s a script, you have complete control over how it creates a device and entities.

I posted an example of how to make a script that creates devices and entities here:

For your purposes, here’s an example of a script that create two sensor entities that belong to the same device:

  example_1:
    alias: 'Create one device with two entities'
    sequence:
      - service: mqtt.publish
        data:
          topic: homeassistant/sensor/temperature1/config
          retain: true
          payload: >
            {
              "name": "Indoor Temperature",
              "state_topic": "home/indoor/temp",
              "unique_id": "abc123",
              "device": {
                  "identifiers": ["aqara"],
                  "name": "Aqara Sensor",
                  "model": "Aqara",
                  "manufacturer": "xiaomi",
                  "sw_version": "1.X"
              }
            }

      - service: mqtt.publish
        data:
          topic: homeassistant/sensor/humidity1/config
          retain: true
          payload: >
            {
              "name": "Indoor Humidity",
              "state_topic": "home/humidity/temp",
              "unique_id": "xyz789",
              "device": {
                  "identifiers": ["aqara"],
                  "name": "Aqara Sensor",
                  "model": "Aqara",
                  "manufacturer": "xiaomi",
                  "sw_version": "1.X"
              }
            }
1 Like

Thanks @123. I wonder if I’m fluent with Python, maybe I can even make this more reusable/powerful and make a generic script that can add any device + entities mapping…hmmm.

Are we taking about HA‘s general discovery feature (using UPnP etc) or MQTT discovery? With the later, devices of your Zigbee network will be added to HA, but only them.

Revisiting this thread and just saw your reply: what @123 specified is what I need. As I’m about to set up an 100+ devices network from scratch (moving to a new house) - I’m deliberating whether this is worth the effort or not.