homebridge-fibaro-home-center icon indicating copy to clipboard operation
homebridge-fibaro-home-center copied to clipboard

Expose services in a single HomeKit ​accessory for multiple services accessories like Flood/Smoke Sensor

Open lboue opened this issue 3 years ago • 4 comments

Hello,

Would it be possible to group services in a single accessory with multiple switches? I think we could publish multiple services into an accessory with HomeKit to do that :

This is an image

For exemple, I own a multi-switch device 'Greenwave PowerNode'. This is an image

I noticed a 'parentId' variable so we just have to group published services by parentId number.

{
    "id": 62,
    "name": "Multiprise P6 PC",
    "roomID": 221,
    "type": "com.fibaro.binarySwitch",
    "baseType": "com.fibaro.actor",
    "enabled": true,
    "visible": true,
    "isPlugin": false,
    "parentId": 43,
    "remoteGatewayId": 0,
    "interfaces": [
        "deviceGrouping",
        "energy",
        "power",
        "zwave",
        "zwaveProtection"
    ],
    "properties": {
        "parameters": [
            {
                "id": 2,
                "lastReportedValue": 129,
                "lastSetValue": 129,
                "size": 1,
                "value": 129
            }
        ],
        "pollingTimeSec": 0,
        "zwaveCompany": "GreenWave Reality Inc.",
        "zwaveInfo": "3,3,41",
        "zwaveVersion": "4.27",
        "RFProtectionState": "0",
        "RFProtectionSupport": "0",
        "categories": "[\"multimedia\"]",
        "configured": true,
        "dead": "false",
        "deadReason": "",
        "deviceControlType": "12",
        "deviceGroup": "[]",
        "deviceGroupMaster": "0",
        "deviceIcon": "10",
        "emailNotificationID": "0",
        "emailNotificationType": "0",
        "endPointId": "1",
        "energy": "0.41",
        "localProtectionState": "0",
        "localProtectionSupport": "0",
        "log": "",
        "logTemp": "",
        "manufacturer": "",
        "markAsDead": "true",
        "model": "",
        "nodeId": "7",
        "parametersTemplate": "315",
        "power": "40.30",
        "productInfo": "0,153,0,3,0,4,4,27",
        "protectionExclusiveControl": "0",
        "protectionExclusiveControlSupport": "false",
        "protectionState": "0",
        "protectionTimeout": "0",
        "protectionTimeoutSupport": "false",
        "pushNotificationID": "0",
        "pushNotificationType": "0",
        "remoteGatewayId": "0",
        "saveLogs": "true",
        "serialNumber": "",
        "showEnergy": "true",
        "smsNotificationID": "0",
        "smsNotificationType": "0",
        "useTemplate": "false",
        "userDescription": "",
        "value": "true"
    },
    "actions": {
        "reconfigure": 0,
        "reset": 0,
        "turnOff": 0,
        "turnOn": 0
    },
    "created": 1637956513,
    "modified": 1637956513,
    "sortOrder": 14
}

Does this seem possible?

Regards Ludovic

lboue avatar Dec 17 '21 17:12 lboue

This is working for Philips Hue devices like Philips Hue motion sensor which is also have additionnal services (Temp and Light sensors).

Hue sensor

This would be possible to group together the services presented by Fibaro accessories. For example :

Fibaro FGFS-101-ZW5 "Flood Sensor"

  • Smoke Sensor
  • Temp sensor

Fibaro FGSD "Smoke Sensor"

  • Smoke Sensor
  • Temp sensor

FGSD

Regards Ludovic

lboue avatar Dec 18 '21 10:12 lboue

Maybe there is a link with this already existing piece of code checking for device.parentId:

https://github.com/ilcato/homebridge-fibaro-home-center/blob/d4a25f2d881222233efb9af326645befaf827901/src/platform.ts#L247

  findSiblingDevices(device, devices) {
    const siblings = new Map<string, unknown>();

    devices.map((s) => {
      if (s.visible === true && s.name.charAt(0) !== '_') {
        if (device.parentId === s.parentId && device.id !== s.id) {
          siblings.set(s.type, s);
        }
      }
    });

    return siblings;
  }

There is also the variable "nodeId" which would identify and group the services.

lboue avatar Dec 18 '21 10:12 lboue

I think I understood my device is not recognized as multi-service. Indeed the current implementation is based on the name of the device and not the identifier of the parent device. But my slave devices has not the same name, so it fails.

https://github.com/ilcato/homebridge-fibaro-home-center/blob/d4a25f2d881222233efb9af326645befaf827901/src/platform.ts#L202

Is there a reason not to use the parentId variable instead?

lboue avatar Dec 18 '21 21:12 lboue

When I set the same name to slave devices, I am getting errors from the log console as you can see below:

[18/12/2021, 22:59:33] [Fibaro-Testing] Getting value from device:  171  parameter: Current Temperature
[18/12/2021, 22:59:33] [Fibaro-Testing] Getting value from device:  170  parameter: Smoke Detected
[18/12/2021, 22:59:33] [Fibaro-Testing] Getting value from device:  170  parameter: Battery Level
[18/12/2021, 22:59:33] [Fibaro-Testing] Getting value from device:  170  parameter: Battery Level
(node:21239) UnhandledPromiseRejectionWarning: Error: This callback function has already been called by someone else; it can only be called one time.
    at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:6:13
    at FibaroAccessory.getCharacteristicValue (/usr/lib/node_modules/homebridge-fibaro-home-center/src/fibaroAccessory.ts:440:9)
    at BatteryLevel.<anonymous> (/usr/lib/node_modules/homebridge-fibaro-home-center/src/fibaroAccessory.ts:331:16)
    at BatteryLevel.emit (events.js:412:35)
    at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1544:14
    at new Promise (<anonymous>)
    at BatteryLevel.<anonymous> (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1542:12)
    at step (/usr/lib/node_modules/homebridge/node_modules/tslib/tslib.js:143:27)
    at Object.next (/usr/lib/node_modules/homebridge/node_modules/tslib/tslib.js:124:57)
    at /usr/lib/node_modules/homebridge/node_modules/tslib/tslib.js:117:75
(node:21239) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 40)

lboue avatar Dec 18 '21 22:12 lboue