Given that zigbee2mqtt supports Home Assistant’s MQTT Discovery, it’s advantageous to use it.
There is another option. You can continue to define the entity manually and use MQTT Discovery. Create a script that publishes the sensor’s configuration to the appropriate discovery topic.
For example, here’s a simple script that creates two binary_sensors via MQTT Discovery:
#script:
create_entities:
alias: Create entities via MQTT Discovery
sequence:
- service: mqtt.publish
data:
topic: homeassistant/binary_sensor/bathroom_door/config
payload: '{"name": "Bathroom Door", "state_topic": "home/sensor1", "device_class": "door", "unique_id": "abc123xyz"}'
retain: true
- service: mqtt.publish
data:
topic: homeassistant/binary_sensor/hallway_motion/config
payload: '{"name": "Hallway Motion", "state_topic": "home/sensor2", "device_class": "motion", "off_delay": 5, "unique_id": "jkl789mno"}'
retain: true
In your case, payload’s value will need to be more complex. Here’s a partial example (you’ll need to complete it) of the payload:
'{"name": "frontdoor_contact_linkquality", "device_class": "signal_strength", "state_topic": "zigbee2mqtt/0x00158d000232a9ad", "unique_id": "0x00158d000232a9ad_linkquality_zigbee2mqtt", "device": {"identifiers": ["zigbee2mqtt_0x00158d000232a9ad"],"name": "0x00158d000232a9ad", "model": "Aqara door & window contact sensor (MCCGQ11LM)", "manufacturer": "Xiaomi", "sw_version": "Zigbee2mqtt 1.12.2"}}'
The topic will be:
homeassistant/sensor/frontdoor_contact_linkquality/config
Resulting (partial) example is this:
- service: mqtt.publish
data:
topic: homeassistant/sensor/frontdoor_contact_linkquality/config
payload: >
{
"name": "frontdoor_contact_linkquality",
"device_class": "signal_strength",
"state_topic": "zigbee2mqtt/0x00158d000232a9ad",
"unique_id": "0x00158d000232a9ad_linkquality_zigbee2mqtt",
"device": {
"identifiers": ["zigbee2mqtt_0x00158d000232a9ad"],
"name": "0x00158d000232a9ad",
"model": "Aqara door & window contact sensor (MCCGQ11LM)",
"manufacturer": "Xiaomi",
"sw_version": "Zigbee2mqtt 1.12.2"
}
}