Aqara door sensors entities not available in HA

this is how it shows up…

The problem is probably from the HA plugin.
It use the same API than phoscon, if it work on phoscon, need to work too in HA.

You can too check in phoscon/help/API Information to check if your sensors are here, but for me too, all is fine.

I think this error from HA logs is what is causing the entity not to be available

First occurred: September 16, 2023 at 19:28:38 (1 occurrences)
Last logged: September 16, 2023 at 19:28:38
Error while setting up deconz platform for binary_sensor

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 359, in _async_setup_platform
await asyncio.shield(task)
File “/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py”, line 221, in async_setup_entry
gateway.register_platform_add_device_callback(
File “/usr/src/homeassistant/homeassistant/components/deconz/gateway.py”, line 182, in register_platform_add_device_callback
async_add_device(EventType.ADDED, device_id)
File “/usr/src/homeassistant/homeassistant/components/deconz/gateway.py”, line 172, in async_add_device
add_device_callback(EventType.ADDED, device_id)
File “/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py”, line 216, in async_add_sensor
) or description.value_fn(sensor) is None:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py”, line 129, in
value_fn=lambda device: device.open,
^^^^^^^^^^^
File “/usr/local/lib/python3.11/site-packages/pydeconz/models/sensor/open_close.py”, line 28, in open
return self.raw[“state”][“open”]
~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: ‘open’

I think indeed the Home assistant is responsible for this code and for whatever reason it fails.

If it doesn’t report the open state then the device is useless. It would be on deconz side in that case to make sure the device provides the expected properties.

How does the event emitted from deconz looks like?

I have tested the API

"181": {
    "config": {
        "battery": 100,
        "on": true,
        "reachable": true,
        "temperature": 2400
    },
    "ep": 1,
    "etag": "xxxxxxxxxxxxxxxxxx",
    "lastannounced": "2023-09-16T08:15:25Z",
    "lastseen": "2023-09-17T13:41Z",
    "manufacturername": "LUMI",
    "modelid": "lumi.sensor_magnet.aq2",
    "name": "Main Bathroom Door",
    "state": {
        "lastupdated": "2023-09-17T13:41:08.653",
        "open": true
    },
    "swversion": "0.0.0_0003",
    "type": "ZHAOpenClose",
    "uniqueid": "xxxxxxxxxxxxxxxxxx:02-01-0006"
}

This is an older

"18": {
    "config": {
        "battery": 100,
        "on": true,
        "reachable": true,
        "temperature": 2100
    },
    "ep": 1,
    "etag": "xxxxxxxxxxxxxxxxxxxxxxxx",
    "lastannounced": null,
    "lastseen": "2023-09-17T13:04Z",
    "manufacturername": "LUMI",
    "modelid": "lumi.sensor_magnet.aq2",
    "name": "Back Door",
    "state": {
        "lastupdated": "2023-06-27T17:56:57.622",
        "open": true
    },
    "swversion": "0.0.0_0003",
    "type": "ZHAOpenClose",
    "uniqueid": "xxxxxxxxxxxxxc2-01-0006"
}

The only difference I see is that the for sensors that are visible in HA
“lastannounced”: null
Does this ring any bells?

also the number generated does not make sense., it should have been 181 for both battery and temperature…

sorry to shoot so many updates but maybe some of them would make sense to an expert :slight_smile:

But on the DDF, the state/open is present

and both have it Aqara door sensors entities not available in HA - #15 by andys73

Can be a problem where deconz take to much time to fill the complete json ?

That’s fine, better to update as you investigate

Not used by HA

Can you share the event?

It can be found under help - api information .

If I could have a full debug log from ha upstart (enable debug logging for deconz as detailed in deconz integration documentation) as well as the entity_registry and device_registry files I could see what might have changed. Since you anonymised the serials in the previous logs feel free to share the files through a PM on this forum.

There has been no real change to the integration over the last year but deconz has continued to evolve, it could very well be some change in behaviour in the device support in the new device which differs from the old.

The logs could at least shed some light on any differences from when the entities was created in home assistant.

Hi @Robban May thanks, I’ve PM you the files required.

@Mimiix I am not sure I what event.

The event when it opens or closes.

It does not generate any events. I have subscribed to state_changed
I open/closed one of the old sensors and I can see the events.

In phoscon? You can’t subscribe there

When having issues you should first look in your log for any errors :slight_smile:

This error says the binary sensor platform is not setup.

2023-09-17 18:36:52.844 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up deconz platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py", line 221, in async_setup_entry
    gateway.register_platform_add_device_callback(
  File "/usr/src/homeassistant/homeassistant/components/deconz/gateway.py", line 182, in register_platform_add_device_callback
    async_add_device(EventType.ADDED, device_id)
  File "/usr/src/homeassistant/homeassistant/components/deconz/gateway.py", line 172, in async_add_device
    add_device_callback(EventType.ADDED, device_id)
  File "/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py", line 216, in async_add_sensor
    ) or description.value_fn(sensor) is None:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/deconz/binary_sensor.py", line 129, in <lambda>
    value_fn=lambda device: device.open,
                            ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pydeconz/models/sensor/open_close.py", line 28, in open
    return self.raw["state"]["open"]
           ~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'open'

It is due to this sensor not having the state property “open”

             '168': {'config': {'battery': 20,
                                'duration': 1,
                                'locked': False,
                                'on': True,
                                'reachable': True},
                     'etag': '2e18cb0955b460bdca033eea2573a4fa',
                     'lastannounced': None,
                     'lastseen': '2023-09-17T17:36Z',
                     'manufacturername': '_TZE200_htnnfasr',
                     'modelid': 'TS0601',
                     'name': 'OpenClose 168',
                     'state': {'lastupdated': '2023-09-14T23:00:24.280',
                               'seconds_remaining': 0},
                     'type': 'ZHAOpenClose',
                     'uniqueid': 'xxxx:62-01-0500'},

If you remove that device or fix its DDF it will work

So in this case, a broken DDF from another device breaks this one?

Yes. It has happened to a couple of users of a new zigbee water controller from tuya.

Haaaa, nice to know, thx.
So it’s the same issue than here Fix LIDL smart watering timer missing ZHAOpenClose state/open item (_TZE200_htnnfasr) by Smanar · Pull Request #7207 · dresden-elektronik/deconz-rest-plugin · GitHub