I have a few Xiaomi temperature/humidity sensors. They work on the Zigbee protocol and connect to zigbee2mqtt which pushes to MQTT
- their “declaration” for autodiscovery
- their status (temperature or humidity)
It happens sometimes, though, that the devices simply vanish from HA, which states that they are unknown (in yellow in the UI). zigbee2mqtt is still sending information to the MQTT broker so form that side everything works, the “vanishing” is on HA side.
I think (wildly speculating) that HA loses access to the autodiscovery information (which is supposed to be retained on the broker).
One fix for that would be to get rid of the autodiscovery and manually declare the sensors in configuration.yaml. My question is: what to actually put in the declaration?
Autodiscovery provides the following information:
3/7/2019, 3:11:43 PM - info: MQTT publish: topic 'homeassistant/sensor/0x00158d0002c77517/temperature/config', payload '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.temperature }}","state_topic":"zigbee2mqtt/0x00158d0002c77517","json_attributes_topic":"zigbee2mqtt/0x00158d0002c77517","name":"0x00158d0002c77517_temperature","unique_id":"0x00158d0002c77517_temperature_zigbee2mqtt","device":{"identifiers":"zigbee2mqtt_0x00158d0002c77517","name":"0x00158d0002c77517","sw_version":"Zigbee2mqtt 1.1.1","model":"Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)","manufacturer":"Xiaomi"},"availability_topic":"zigbee2mqtt/bridge/state"}'
The formatted JSON up there is:
{
"unit_of_measurement": "°C",
"device_class": "temperature",
"value_template": "{{ value_json.temperature }}",
"state_topic": "zigbee2mqtt/0x00158d0002c77517",
"json_attributes_topic": "zigbee2mqtt/0x00158d0002c77517",
"name": "0x00158d0002c77517_temperature",
"unique_id": "0x00158d0002c77517_temperature_zigbee2mqtt",
"device": {
"identifiers": "zigbee2mqtt_0x00158d0002c77517",
"name": "0x00158d0002c77517",
"sw_version": "Zigbee2mqtt 1.1.1",
"model": "Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)",
"manufacturer": "Xiaomi"
},
"availability_topic": "zigbee2mqtt/bridge/state"
}
What should the declaration of this sensor look like in HA? Should all the fields be translated to YAML such as below?
sensor:
- unit_of_measurement: "°C"
device_class: temperature
value_template: "{{ value_json.temperature }}"
state_topic: zigbee2mqtt/0x00158d0002c77517
json_attributes_topic: zigbee2mqtt/0x00158d0002c77517
name: 0x00158d0002c77517_temperature
unique_id: 0x00158d0002c77517_temperature_zigbee2mqtt
device:
identifiers: zigbee2mqtt_0x00158d0002c77517
name: '0x00158d0002c77517'
sw_version: Zigbee2mqtt 1.1.1
model: Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)
manufacturer: Xiaomi
availability_topic: zigbee2mqtt/bridge/state
