athombv / homey-apps-sdk-issues

This issue tracker is for Homey Developers using the Apps SDK.
21 stars 4 forks source link

Add support for Zigbee Enrollment #157

Closed JohanBendz closed 1 year ago

JohanBendz commented 3 years ago

There are 2 types of devices, the CIE (coordinator/Homey), and the IAS Zone device (like PIR, motion, fire etc).

  1. CIE sends Write Request to cluster 0x0500 (1280), attribute 0x0010 (16), data type IEEE address (0x0000000000000000), value CIE's 64-bit address.
  2. CIE receives Write Response, indicating success or failure.
  3. CIE receives Zone Enroll Request.
  4. CIE sends Zone Enroll Response. To trigger the change again, unroll by changing the address to 0x0000000000000000 and then back to CIE's. Confirm that end device in enrolled by issuing Read Request on cluster 0x0500 (1280), attribute 0x0000 (ZoneState).

Here is an extension of the iasZone cluster that is needed to have it work: IASZoneBoundCluster.js

'use strict';
const { BoundCluster } = require('zigbee-clusters');
class IASZoneBoundCluster extends BoundCluster {
    constructor({
        onZoneStatusChangeNotification,
    }) {
        super();
        this._onZoneStatusChangeNotification = onZoneStatusChangeNotification;
    }
    zoneStatusChangeNotification(payload) {
        if (typeof this._onZoneStatusChangeNotification === 'function') {
        this._onZoneStatusChangeNotification(payload);
        }
    }
    static get COMMANDS() {
        return {
          ...super.COMMANDS,
          iasZoneEnroll: {
            id: 0x08,
            manufacturerId: 0x117C,
            args: {
              mode: ZCLDataTypes.enum8({
                up: 0,
                down: 1,
              }),
              transitionTime: ZCLDataTypes.uint16,
            },
          },
          zoneEnrollResponse: {
            id: 0,
            args: {
              enrollResponseCode: ZCLDataTypes.enum16({
                success: 0, // 0x00 Success | Success
                notSupported: 1, // 0x01 Not supported | This specific Zone type is not known to the CIE and is not supported.
                noEnrollPermit: 2, // 0x02 No enroll permit | CIE does not permit new zones to enroll at this time.
                tooManyZones: 3, // 0x03 Too many zones | CIE reached its limit of number of enrolled zones
              }),
              zoneID: ZCLDataTypes.uint16,
            },
          },
          zoneStatusChangeNotification: {
            id: 0,
            args: {
              zoneStatus: ZONE_STATUS_DATA_TYPE,
              extendedStatus: ZCLDataTypes.uint8,
              zoneId: ZCLDataTypes.uint8,
              delay: ZCLDataTypes.uint16,
            },
          },
        };
    }
}
module.exports = IASZoneBoundCluster;

This is the code to write the CIE Address to the node: await zclNode.endpoints[1].clusters.iasZone.writeAttributes({iasCIEAddress: 0x0000000000000000});

RobinBol commented 3 years ago

To summarise this issue, if I am correct, the issue is that you can't access the IEEE address of Homey from within a Homey app? Is that the blocker for you to handle IASZone enrolment?

JohanBendz commented 3 years ago

Yes, I can't make the app handle enrollment unless it can fetch the IEEE address. I could ask the user to go to dev portal and read it and enter it as a setting but that is not very user friendly.

TedTolboom commented 3 years ago

@RobinBol to enable IAS zone enrollment, the following steps need to be taken (as per 8.2.2.2.3 Implementation Guidelines):

Auto-Enroll-Response

  1. After an IAS Zone server is commissioned to a network, the IAS CIE MAY perform service discovery.
  2. If the IAS CIE determines it wants to enroll the IAS Zone server, it SHALL send a Write Attribute command on the IAS Zone server’s CIE_IAS_Address attribute with its IEEE address.
  3. The IAS Zone server MAY configure a binding table entry for the IAS CIE’s address because all of its communication will be directed to the IAS CIE.
  4. The IAS CIE SHALL send a Zone Enroll Response, which assigns the IAS Zone server’s ZoneID attribute.
  5. The IAS Zone server SHALL change its ZoneState attribute to 0x01 (enrolled).

Practically:

  1. the device (IAS Zone server) shall send a Zone Enroll Request command (Commands GENERATED ID 1) to the IAS CIE (Homey), which Homey will need to capture
  2. Homey should write the homey's IEEE address to attribute IAS_CIE_Address
  3. Homey should respond with the Zone Enroll Response (Commands RECEIVED ID 0)
  4. the device will change its ZoneState attribute to enrolled

In order to make this work, we need:

  1. to be able to access Homey's IEEE address to write it to the device's IAS_CIE_Address (see original request)
  2. be able to differentiate 2 different command sets (GENERATED and RECEIVED).

For most clusters, there is only one command set, which Homey either will send (normal), or will receive (bound cluster). In this case, we need to be able to receive the bound the commands GENERATED set (to capture the enroll request) and still be able to use the commands RECEIVED set (to send the enroll response).

frodeheg commented 2 years ago

Is there any progress in this. Lack of IASZONE support in Homey is also blocking the com.elko app from adding support for smart motion sensors. I really want my motion sensors to work in Homey.

JohanBendz commented 2 years ago

@RobinBol, still waiting for this one. I now have several new brands/sensors that I am unable to add to Homey. Any plans to implement this in any way?

RobinBol commented 1 year ago

We've made some progress related to IAS support, it should be possible now to do a IAS zone enrollment on Homey Pro v8.1.1. Homey Cloud will follow soon. Please check the docs here: https://apps.developer.homey.app/wireless/zigbee#zcl-intruder-alarm-systems-ias, and the related zigbee-clusters PR here: https://github.com/athombv/node-zigbee-clusters/pull/109.

I am considering this issue solved for now, but please let me know if anything is unclear or should be clarified in the docs.

JohanBendz commented 1 year ago

Thanks @RobinBol, I'll give it a go after Christmas. Ping @TedTolboom

TedTolboom commented 1 year ago

Thanks @RobinBol... will give it a try and test if this can replace my containment solution...