Unable to read Cluster attribute (new ZigBeeDevice driver)

Hi,

I’m developing a new driver for a Zigbee Occupancy Sensor (SONOFF SNZB-06P) using the ZigBeeDevice library.
I’m able to add the device into HomeyPro App and I do see in the debug the occupancy status change correctly and a report being received in Homey. But I cannot read its occupancy status.
The reason is that the reportParser in ZigBeeDevice.js is not able to read the attribute value in the Cluster report as a 0 or 1.
Instead, in the debug I see the the attribute is printed as a Bitmap [ ]. See below two examples of this attribute when occupancy is detected or not.

Below, the payloadReport is the output of: console.log(‘payload[report]:’, payload[report]);

##== OCCUPANCY = FALSE

2024-01-02T15:36:44.391Z [log] [ManagerDrivers] [Driver:snzb-06p-occupancy-sensor] [Device:8a4597e6-f717-438f-a69d-7f9aef124a80] [dbg] get → alarm_motion → read attribute (cluster: occupancySensing, attributeId: occupancy, endpoint: 1) → raw result: { occupancy: Bitmap [ ] }
2024-01-02T15:36:44.392Z [log] [ManagerDrivers] [Driver:snzb-06p-occupancy-sensor] [Device:8a4597e6-f717-438f-a69d-7f9aef124a80] [dbg] handle report (cluster: occupancySensing, capability: alarm_motion), raw payload: { occupancy: Bitmap [ ] }
payload[report]: Bitmap [ ]

##== OCCUPANCY = TRUE
2024-01-02T15:42:34.308Z [log] [ManagerDrivers] [Driver:snzb-06p-occupancy-sensor] [Device:8a4597e6-f717-438f-a69d-7f9aef124a80] [dbg] handle report (cluster: occupancySensing, capability: alarm_motion), raw payload: { occupancy: Bitmap [ occupied ] }
payload[report]: Bitmap [ occupied ]

I’ve tried reading this attribute in several ways: I tried comparing with integer 1 or char ‘1’, treat it as an Array and access position [0], without success.

Any hint on how I can read the Bitmap [ ] value of this attribute?
According to the ZCL this should be a bit set to 0 or 1.

Disclaimer: This is my first attempt at writing an App for HomeyPro :grinning: and I’m not a pro developer, even though I’ve programmed in Java, C++, C, etc in University.

Cheers,
Ricardo

I believe the cluster definition for this sensor may require update, as it has a TODO comment in the Homey cluster definition (file: zigbee-clusters/lib/clusters/occupancySensing.js):

–snip–
const ATTRIBUTES = {
occupancy: { id: 0, type: ZCLDataTypes.map8(‘occupied’) }, // TODO: verify this bitmap
–snip–

I’ll look into it, but in case there’s some insight on how to correct it, it’s highly appreciated.
Thanks!

Cheers,
Ricardo

Try getBit(0) (or possibly getBit(1)).

It worked with getBit(0), @robertklep!
Many thanks for the hint and very fast reply. :wink:

Cheers,
Ricardo

I couldn’t find anything related to this in the documentation, I had to search through the various modules to find where Bitmap was defined and how to use it :thinking:

Any chance you can point me where to find it in the modules?
I’m new to programming in Homey and not sure where to find it.

Thanks.

I linked to the relevant module, @athombv/data-types: GitHub - athombv/node-data-types: Binary Data Parsers

Many thanks @robertklep!
This is really helpful.

Cheers,
Ricardo