From 351f59f9428bdd59d68bbc6ef6ed84a1955abcec Mon Sep 17 00:00:00 2001 From: "github@davidrthomas.co.uk" Date: Tue, 5 Dec 2023 00:07:36 +0000 Subject: [PATCH 1/3] add motion detection switch --- packages/homebridge-ring/camera.ts | 13 +++++++++++ packages/homebridge-ring/config.schema.json | 5 +++++ packages/homebridge-ring/config.ts | 1 + packages/ring-client-api/ring-camera.ts | 24 +++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/packages/homebridge-ring/camera.ts b/packages/homebridge-ring/camera.ts index 01001faa..d05180bf 100644 --- a/packages/homebridge-ring/camera.ts +++ b/packages/homebridge-ring/camera.ts @@ -117,6 +117,19 @@ export class Camera extends BaseDataAccessory { }) } + if (device.hasMotionDetection && !config.hideCameraMotionDetectionSwitch) { + this.registerCharacteristic({ + characteristicType: Characteristic.On, + serviceType: Service.Switch, + name: device.name + ' Motion Detection Enabled', + getValue: (data) => { + return Boolean(data.settings.motion_detection_enabled) + }, + setValue: (value) => device.setMotionDetectionEnabled(value), + requestUpdate: () => device.requestUpdate(), + }) + } + if (device.hasSiren && !config.hideCameraSirenSwitch) { this.registerCharacteristic({ characteristicType: Characteristic.On, diff --git a/packages/homebridge-ring/config.schema.json b/packages/homebridge-ring/config.schema.json index 03ea0be1..1062707e 100644 --- a/packages/homebridge-ring/config.schema.json +++ b/packages/homebridge-ring/config.schema.json @@ -44,6 +44,10 @@ "title": "Hide Camera Motion Sensors", "type": "boolean" }, + "hideCameraMotionDetectionSwitch": { + "title": "Hide Camera Motion Detection Switch", + "type": "boolean" + }, "hideCameraSirenSwitch": { "title": "Hide Camera Siren Switch", "type": "boolean" @@ -163,6 +167,7 @@ "hideDoorbellSwitch", "hideCameraLight", "hideCameraMotionSensor", + "hideCameraMotionDetectionSwitch", "hideCameraSirenSwitch", "hideInHomeDoorbellSwitch", "hideAlarmSirenSwitch", diff --git a/packages/homebridge-ring/config.ts b/packages/homebridge-ring/config.ts index 2b8c43e7..0ceb4b57 100644 --- a/packages/homebridge-ring/config.ts +++ b/packages/homebridge-ring/config.ts @@ -15,6 +15,7 @@ export interface RingPlatformConfig extends RingApiOptions { hideDoorbellSwitch?: boolean hideCameraLight?: boolean hideCameraMotionSensor?: boolean + hideCameraMotionDetectionSwitch?: boolean hideCameraSirenSwitch?: boolean hideInHomeDoorbellSwitch?: boolean hideAlarmSirenSwitch?: boolean diff --git a/packages/ring-client-api/ring-camera.ts b/packages/ring-client-api/ring-camera.ts index 23cfbd31..9c184e78 100644 --- a/packages/ring-client-api/ring-camera.ts +++ b/packages/ring-client-api/ring-camera.ts @@ -125,6 +125,7 @@ export class RingCamera extends Subscribed { onData hasLight hasSiren + hasMotionDetection onRequestUpdate = new Subject() onNewNotification = new Subject() @@ -169,6 +170,8 @@ export class RingCamera extends Subscribed { this.onData = new BehaviorSubject(this.initialData) this.hasLight = this.initialData.led_status !== undefined this.hasSiren = this.initialData.siren_status !== undefined + this.hasMotionDetection = + this.initialData.settings.motion_detection_enabled !== undefined this.onBatteryLevel = this.onData.pipe( map((data) => { @@ -314,6 +317,27 @@ export class RingCamera extends Subscribed { return true } + async setMotionDetectionEnabled(enabled: boolean) { + if (!this.hasMotionDetection) { + return false + } + + const motionReq = { + motion_settings: { + motion_detection_enabled: enabled, + }, + } + await this.setDeviceSettings(motionReq) + + const settings = { + ...this.data.settings, + motion_detection_enabled: enabled, + } + + this.updateData({ ...this.data, settings: settings }) + return enabled + } + async setSiren(on: boolean) { if (!this.hasSiren) { return false From 49238eab4b5f0d19e44d25c44c29ce1c43f2525e Mon Sep 17 00:00:00 2001 From: "github@davidrthomas.co.uk" Date: Wed, 6 Dec 2023 22:34:54 +0000 Subject: [PATCH 2/3] add motinon detection switch --- packages/ring-client-api/ring-camera.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ring-client-api/ring-camera.ts b/packages/ring-client-api/ring-camera.ts index 9c184e78..baecd5fa 100644 --- a/packages/ring-client-api/ring-camera.ts +++ b/packages/ring-client-api/ring-camera.ts @@ -322,12 +322,12 @@ export class RingCamera extends Subscribed { return false } - const motionReq = { + const motionEnabledRequest = { motion_settings: { motion_detection_enabled: enabled, }, } - await this.setDeviceSettings(motionReq) + await this.setDeviceSettings(motionEnabledRequest) const settings = { ...this.data.settings, From 1d13e4b0593d0fc470f9770e7cd485d5f8b193b7 Mon Sep 17 00:00:00 2001 From: "github@davidrthomas.co.uk" Date: Wed, 6 Dec 2023 23:42:13 +0000 Subject: [PATCH 3/3] add motion detection switch --- packages/homebridge-ring/README.md | 3 +++ packages/ring-client-api/README.md | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/homebridge-ring/README.md b/packages/homebridge-ring/README.md index bf931d29..adc78640 100644 --- a/packages/homebridge-ring/README.md +++ b/packages/homebridge-ring/README.md @@ -90,6 +90,7 @@ Only include an optional parameter if you actually need it. Default behavior wit | `hideDoorbellSwitch` | `false` | If you have a Ring video doorbell, you will see a Programmable Switch associated with it. This switch can be used to perform actions on when the doorbell is pressed using "Single Press" actions. If you do not care to perform actions when the doorbell is pressed, you can hide the Programmable Switch by setting this option to `true`. You will still be able to receive _notifications_ from the doorbell even if the Programmable Switch is hidden (notifications can be configured in the settings for the doorbell camera in the Home app) | | `hideCameraLight` | `false` | If `true`, hides the light for Ring cameras in HomeKit. | | `hideCameraMotionSensor` | `false` | If `true`, hides the motion sensor for Ring cameras in HomeKit. | +| `hideCameraMotionDetectionSwitch` | `false` | If `true`, hides the motion detected switch for Ring cameras in HomeKit. | | `hideCameraSirenSwitch` | `false` | If `true`, hides the siren switch for Ring cameras in HomeKit. | | `hideInHomeDoorbellSwitch` | `false` | If `true`, hides the switch for in-home doorbells in HomeKit. | | `hideAlarmSirenSwitch` | `false` | If you have a Ring Alarm, you will see both the alarm and a "Siren" switch in HomeKit. The siren switch can sometimes get triggered by Siri commands by accident, which is loud and annoying. Set this option to `true` to hide the siren switch. | @@ -113,6 +114,8 @@ The plugin supports all Ring camera models, as well as ONVIF cameras connected v - Shows a live feed from the camera if you click on it. The feed supports video and 2-way audio, but requires that you have `ffmpeg` with `libfdk_aac` installed. A pre-built `ffmpeg` will be automatically installed on most platforms using `ffmpeg-for-homebridge`. See the [FFmpeg wiki](https://github.com/dgreif/ring/wiki/FFmpeg) for details. 2-way audio may not work for ONVIF cameras. - Motion Sensor - Can be hidden with `hideCameraMotionSensor` +- Motion Detection Switch + - Can be hidden with `hideCameraMotionDetectionSwitch` - Light (if camera is equipped) - Siren Switch (if camera is equipped) - Can be hidden with `hideCameraSirenSwitch` diff --git a/packages/ring-client-api/README.md b/packages/ring-client-api/README.md index 8ecaa0be..2e9ca37f 100644 --- a/packages/ring-client-api/README.md +++ b/packages/ring-client-api/README.md @@ -108,6 +108,7 @@ camera.onData.subscribe((data) => { // called every time new data is fetched for this camera }) camera.setLight(true) // turn light on/off +camera.setMotionDetectionEnabled(true) // turn motion detection on/off camera.setSiren(true) // turn siren on/off camera.getHealth() // fetch health info like wifi status camera.startVideoOnDemand() // ask the camera to start a new video stream