Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motion detection switch #1373

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/homebridge-ring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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`
Expand Down
13 changes: 13 additions & 0 deletions packages/homebridge-ring/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ export class Camera extends BaseDataAccessory<RingCamera> {
})
}

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,
Expand Down
5 changes: 5 additions & 0 deletions packages/homebridge-ring/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -163,6 +167,7 @@
"hideDoorbellSwitch",
"hideCameraLight",
"hideCameraMotionSensor",
"hideCameraMotionDetectionSwitch",
"hideCameraSirenSwitch",
"hideInHomeDoorbellSwitch",
"hideAlarmSirenSwitch",
Expand Down
1 change: 1 addition & 0 deletions packages/homebridge-ring/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface RingPlatformConfig extends RingApiOptions {
hideDoorbellSwitch?: boolean
hideCameraLight?: boolean
hideCameraMotionSensor?: boolean
hideCameraMotionDetectionSwitch?: boolean
hideCameraSirenSwitch?: boolean
hideInHomeDoorbellSwitch?: boolean
hideAlarmSirenSwitch?: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/ring-client-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions packages/ring-client-api/ring-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class RingCamera extends Subscribed {
onData
hasLight
hasSiren
hasMotionDetection

onRequestUpdate = new Subject()
onNewNotification = new Subject<PushNotificationDing>()
Expand Down Expand Up @@ -169,6 +170,8 @@ export class RingCamera extends Subscribed {
this.onData = new BehaviorSubject<AnyCameraData>(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) => {
Expand Down Expand Up @@ -314,6 +317,27 @@ export class RingCamera extends Subscribed {
return true
}

async setMotionDetectionEnabled(enabled: boolean) {
if (!this.hasMotionDetection) {
return false
}

const motionEnabledRequest = {
motion_settings: {
motion_detection_enabled: enabled,
},
}
await this.setDeviceSettings(motionEnabledRequest)

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
Expand Down