Skip to content

Commit

Permalink
Doorbell related MQTT support.
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhjd committed Mar 13, 2024
1 parent 91170ec commit 8fb586d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/MQTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down
16 changes: 14 additions & 2 deletions src/access-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down

0 comments on commit 8fb586d

Please sign in to comment.