diff --git a/docs/MQTT.md b/docs/MQTT.md index 29bc2a8..7bb9a44 100644 --- a/docs/MQTT.md +++ b/docs/MQTT.md @@ -54,6 +54,7 @@ The topics and messages that `homebridge-unifi-access` publishes are: | Topic | Message Published |-----------------------|---------------------------------- +| `doorbell` | `true` or `false` when a UniFi Access hub is ringing the doorbell. | `lock` | `true` or `false` when a UniFi Access hub has locked or unlocked the door lock relay. Messages are published to MQTT when an action occurs on an Access device that triggers the respective event, or when an MQTT message is received for one of the topics `homebridge-unifi-access` subscribes to. @@ -63,6 +64,7 @@ The topics that `homebridge-unifi-access` subscribes to are: | Topic | Message Expected |-------------------------|---------------------------------- +| `doorbell/get` | `true` will trigger a publish event of the current doorbell ring status for a UniFi Access hub. | `lock/get` | `true` will trigger a publish event of the current door lock relay state for a UniFi Access hub. | `lock/set` | `true` will unlock the door lock relay for a UniFi Access hub. `false` will unlock. diff --git a/src/access-hub.ts b/src/access-hub.ts index 924fb06..71a9629 100644 --- a/src/access-hub.ts +++ b/src/access-hub.ts @@ -242,7 +242,13 @@ export class AccessHub extends AccessDevice { return false; } - // MQTT status. + // MQTT doorbell status. + this.controller.mqtt?.subscribeGet(this.accessory, "doorbell", "Doorbell ring", () => { + + return this.doorbellRingRequestId !== null ? "true" : "false"; + }); + + // MQTT lock status. this.controller.mqtt?.subscribeGet(this.accessory, "lock", "Lock", () => { switch(this.hkLockState) { @@ -264,7 +270,7 @@ export class AccessHub extends AccessDevice { } }); - // MQTT status. + // MQTT lock status. this.controller.mqtt?.subscribeSet(this.accessory, "lock", "Lock", (value: string) => { switch(value) { @@ -383,6 +389,9 @@ export class AccessHub extends AccessDevice { // Update our doorbell trigger, if needed. this.accessory.getServiceById(this.hap.Service.Switch, AccessReservedNames.SWITCH_DOORBELL_TRIGGER)?.updateCharacteristic(this.hap.Characteristic.On, true); + // Publish to MQTT, if configured to do so. + this.controller.mqtt?.publish(this.accessory, "doorbell", "true"); + if(this.hints.logDoorbell) { this.log.info("Doorbell ring detected."); @@ -403,6 +412,9 @@ export class AccessHub extends AccessDevice { // Update our doorbell trigger, if needed. this.accessory.getServiceById(this.hap.Service.Switch, AccessReservedNames.SWITCH_DOORBELL_TRIGGER)?.updateCharacteristic(this.hap.Characteristic.On, false); + // Publish to MQTT, if configured to do so. + this.controller.mqtt?.publish(this.accessory, "doorbell", "false"); + if(this.hints.logDoorbell) { this.log.info("Doorbell ring cancelled.");