Zigbee2mqtt: Battery not appearing for Xiaomi door sensors even after a week

Created on 17 Nov 2018  路  9Comments  路  Source: Koenkk/zigbee2mqtt

Bug report

  • First make sure your on the latest version of zigbee2mqtt.
    tried 0.1.8 and 0.2, same result
  • Make sure you are running the latest CC253X firmware from https://github.com/koenkk/z-stack-firmware.
    yes, latest one
  • Provide a clear description of the problem.
    Every sensor had a battery suatus attached. I can see it in the log, but in home assistant the door sensors aer missing this. I am running it since a week, and sensors are actually providing battery values, but this is not taken into home assistant.
  • If applicable, provide steps how to reproduce the problem.
    Normal steps. Starting npm, staring home assistant, I even tried to restart mqtt.

https://pastebin.com/ZKu2xfwc

Most helpful comment

Hi All
This is a Home Assistant bug/feature that binary sensors do not have JSON attributes.

@ciotlosm worked on it here https://github.com/Koenkk/zigbee2mqtt/issues/106 and https://github.com/home-assistant/home-assistant/pull/14912 and https://github.com/home-assistant/home-assistant/pull/14957 but it didn't get merged.

All 9 comments

Updates. I tried this steps:

  • stopping mosquitto
  • deleting mosquitto db
  • stopping npm
  • stopping home assistant
  • deleting ha db and storage entities

After this, I restarted home assistant and mosquitto. No sensor in ha, perfect.
I started npm after that, and it created all the entities (with alfanumeric names).
Sensor started getting battery values, but door sensors were still without battery.

I can see battery values getting pushed out for door sensors from the npm service, so why they are not appearing in home assistant entities?

If you want a device's battery value to appear as its own entity in Home Assistant, you must create it yourself. Here's what I did for my Xiaomi door sensor.

  1. Name your sensor so it doesn't look like gibberish. In zigbee2mqtt's configuration.yaml:
  '0x00158d000232c0c5':
    friendly_name: the_name_you_want
    retain: false
  1. Restart zigbee2mqtt so HA picks up the device.
  2. In HA's sensors.yaml, create an entry specifically for the battery. Notice that the state_topic is whatever you named your device above, and the name is whatever name you want for your battery value entity:
- platform: mqtt
  name: the_battery_entity_name_you_want
  state_topic: "zigbee2mqtt/the_name_you_want"
  unit_of_measurement: "%"
  value_template: "{{ value_json.battery }}"

I will try that, but why it is properly creating and updating values for everything apart door sensors?
I am using zigbee2mqtt because it autocreate everything, it defeats the purpose having to create everything manually.
Paired with a little plugin that autocreate the battery sensor it's very confortable to use:

https://github.com/notoriousbdg/Home-AssistantConfig/blob/master/packages/battery_alert.yaml

Does it work for "sensor" and not "binary_sensor"? So far for me all sensors are working but my water leak sensor shows up as "binary_sensor" and it does not work.

@nerdosity You'll need to check with the battery_alert add-on's dev, but it sounds like its not creating battery entries for devices that are binary_sensors.

@bbrendon If you're talking about the HA entries I listed above, it works for all the devices I've linked through zigbee2mqtt. FYI, the battery entity is always sensor.something, even if the device's main attribute is listed as binary_senor.something. E.g. the entries in HA above created 2 entities for the same device, binary_sensor.the_name_you_want and sensor.the_battery_entity_name_you_want.

Hi All
This is a Home Assistant bug/feature that binary sensors do not have JSON attributes.

@ciotlosm worked on it here https://github.com/Koenkk/zigbee2mqtt/issues/106 and https://github.com/home-assistant/home-assistant/pull/14912 and https://github.com/home-assistant/home-assistant/pull/14957 but it didn't get merged.

Thanks @ryanbeaton, it makes sense.

Fixed in the dev branch. Battery will now be a separate sensor in homeassistant.

@Koenkk Thanks for adding a stop-gap until HASS gets json attribute support. And thank you @ryanbeaton for explaining the root cause of this mess.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

z4rn0x picture z4rn0x  路  3Comments

andreasbrett picture andreasbrett  路  4Comments

rm2kdev picture rm2kdev  路  3Comments

andreasbrett picture andreasbrett  路  3Comments

CodeFinder2 picture CodeFinder2  路  4Comments