Koenkk / zigbee-herdsman-converters

Collection of device converters to be used with zigbee-herdsman
MIT License
886 stars 2.96k forks source link

Help on creating a device with multiple endpoints of the same cluster type #5060

Closed pvginkel closed 1 year ago

pvginkel commented 1 year ago

I'm playing around with ZigBee on Arduino. I have the protocol implemented and can create ZigBee Home Automation devices. I have a few examples, and they work fine with zigbee2mqtt and Home Automation.

I'm now trying a few more complex scenarios. I'm trying to create a sensor device. I have five sensors on it:

I want to map the photoresistors to a msIlluminanceMeasurement cluster and I have done so in the device. The device is reporting endpoints as follows:

image

The idea here is that endpoint 2, 3 and 4 are of the same cluster type (msIlluminanceMeasurement), but they're reporting different values.

I'm not sure how I can map this in a custom device. I've tried a few different things. If I don't do anything special, the three values overwrite each other. I've tried creating custom fromZigbee-s and expose-s, but I think I'm now getting into trouble with the cluster types.

Could you give a suggestion on how I can get this to work? I'd prefer not creating custom cluster types, so if there's a way to maybe map data of the same cluster type on different endpoints to different values, I'm good.

The primary thing I want to do with this is get it as some data point into Home Assistant so I can take actions based on it. So it's fine if the values aren't called "illuminance".

My definition file is here:

https://github.com/pvginkel/ZigBeeHomeAutomation/blob/325977194d565498e6468d8c5cc5c7ba8813cdc3/Sensors.js

(The bottom part is commented out. I'm not sure how I could get that to work.)

It's just a simple device definition with temperature, humidity and illuminance in fromZigbee and exposes.

This does work:

image

I can change things around in endpoint numbers and device ID's if that would help. The sketch is here if you're interested:

https://github.com/pvginkel/ZigBeeHomeAutomation/blob/325977194d565498e6468d8c5cc5c7ba8813cdc3/ZigBeeHomeAutomation.ino.

Btw, cool project. I could never have gotten this to work without herdsman. It's been tremendous help and I hope I can get this to a state I can share it with a larger community.

pvginkel commented 1 year ago

I worked around this by now by reporting three custom attributes on the same cluster. I'd still like to know whether it's possible to have the same cluster type on a device multiple times. See:

https://github.com/pvginkel/ZigBeeHomeAutomation/blob/b19e810c0c1b83b0fe8590c83d3d046dca8040a1/Sensors.js

danieledwardgeorgehitchcock commented 1 year ago

This is possible.

Your external converter must have a multiEndpoint: True meta option set, and your fromZigbee and toZigbee converters will need to be modified slightly to prefix the endpoint as part of the state response

pvginkel commented 1 year ago

Yes, that worked. It took a bit of tinkering, but I have it working.

The least obvious change was the to the converters. If I search the zigbee-herdsman-converters project for multiEndpoint, there are plenty of examples to show how to implement this. For the next person finding this, you do have to change the names of the attributes you're returning form convert. If you search the zigbee-herdsman-converters project for calls to utils.postfixWithEndpointName, you'll find examples on how.

Thank you for the direction. This was very helpful.