dgreif / ring

Unofficial packages for Ring Doorbells, Cameras, Alarm System, and Smart Lighting
MIT License
1.23k stars 162 forks source link

Ring Smart Lighting Support? #23

Closed wondergit113 closed 5 years ago

wondergit113 commented 5 years ago

Is the ring api used for this plugin also able to access the newly launched Ring Smart Lighting?

dgreif commented 5 years ago

@jamesg311 I’m 99% sure the api for the lights is very similar to the api for the alarm based on the source code for the ring web app. I’ve got a floodlight being delivered today, and have already started implementing the additional devices within the ring-alarm homebridge plugin. Should have an update out in a week or two assuming I can find time to work on it more.

wondergit113 commented 5 years ago

Rad! Let me know how I can help. I’ve got a floodlight and a few pathlights.

On May 19, 2019, at 1:55 PM, Dusty Greif notifications@github.com wrote:

@jamesg311 I’m 99% sure the api for the lights is very similar to the api for the alarm based on the source code for the ring web app. I’ve got a floodlight being delivered today, and have already started implementing the additional devices within the ring-alarm homebridge plugin. Should have an update out in a week or two assuming I can find time to work on it more.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

dgreif commented 5 years ago

Great, it would be nice to have you test it out with the pathlights when I'm done. I'm still trying to decide if I want to get those. They are way bigger than I expected. How is the light radius on them?

wondergit113 commented 5 years ago

They are bigger than I expected too. And the packaging is a bit wasteful. But the lights are bright!

Here they are in near pitch black. When the lights are off my camera can’t even pick up any light.

https://i.imgur.com/jWS1mGy.jpg

codahq commented 5 years ago

The beams bridge has a ZID that is used as "dst" in the web service calls just like the alarm's bases devices. All of the beams and alarm devices updates come over the same WS connection. I haven't reversed many of the calls for the lights yet but I can seem all of the chatter from them over the WS for the alarm. You've probably discovered the same.

dgreif commented 5 years ago

@codahq thanks for the tip on using dst, that definitely saved me some time. v2.0.0 is out with ring smart lighting, along with multi-level switches (need someone to test these with a third party switch). Let me know how the lighting works for you @jamesg311 !

codahq commented 5 years ago

I should have double-checked before I spoke... They're not all the same. A single lights on/off goes through the WS:

Here's an example of a single light on: [ "message", { "body": [ { "zid": "${id_of_light_to_change}", "command": { "v1": [ { "commandType": "light-mode.set", "data": { "lightMode": "on", "duration": 60 } } ] } } ], "datatype": "DeviceInfoSetType", "dst": "${beams_bridge_asset_id_sometimes_called_zid}", "msg": "DeviceInfoSet", "seq": 3 } ]

It looks like most of the on/off requests for groups just go through the cloud end points though. Real-time responses come back through the WS.

Here's an example group on: POST https://api.ring.com/groups/v1/locations/${location_id}/groups/${device_group_id}/devices with a body like: {"lights_on":{"duration_seconds":60,"enabled":true}}

Lots of places to get ${location_id} ${device_group_id} comes from GET https://api.ring.com/groups/v1/locations/${location_id}/groups

Responses from WS look like: [ "DataUpdate", { "msg": "DataUpdate", "datatype": "DeviceInfoDocType", "seq": 30440, "src": "${beams_bridge_asset_id_sometimes_called_zid}", "body": [ ... "impulse" { "v1": [ { ... "impulseType": "halo-stats.latency" } ] ... ] "context": ... } ]

And then a bunch of responses for each light in the group. [ "DataUpdate", { "msg": "DataUpdate", "datatype": "DeviceInfoDocType", "seq": 30441, "src": "${beams_bridge_zid}", "body": [ { "general": { "v2": { "adapterType": "ringnet", "catalogId": null, "deviceType": "switch.multilevel.beams", "lastUpdate": 1558422992019, "zid": "${id_of_light_that_changed}" } }, "device": { "v1": { "lightMode": "default", "on": false, "onUntil": null } }, "context": { "v1": { ... "categoryId": 2, "device": { "v1": { "autoShutoffTime": 0, "duskToDawnMode": "disabled", "glowStatus": "off", "level": 1.0, "lightMode": "default", "lightSensorEnabled": true, "lightSensorThreshold": 88, "lightSensorThresholdDefault": 88, "motionSensorEnabled": true, "motionStatus": "clear", "on": false, "sensitivity": 127, "sensitivityMin": 255 } }, "deviceName": "${name_of_light_that_changed}", "roomName": "No Room Assigned", "subCategoryId": 0 } }, "impulse": { "v1": [ { "data": {}, "impulseType": "light-mode.default" } ] } } ], "context": { ... "affectedEntityType": "device", "affectedEntityId": "${id_of_light_that_changed}", "affectedEntityName": "${name_of_light_that_changed}", ... "assetId": "${beams_bridge_zid}", "assetKind": "beams_bridge_v1" } } ]

And then a response for the virtual device that is the group.

dgreif commented 5 years ago

@codahq interesting that they have a rest endpoint. I have lighting groups in the homebridge plugin update and they are working perfectly for me just using websockets. As with most of these APIs from Ring, it seems like there are many ways to accomplish the same task (probably because of legacy clients). A great example of that is the change from v1/rs/connections to v1/clap/tickets https://github.com/dgreif/ring-alarm/commit/976d1afd1519845b77edc05e83e56aded4402f51?diff=split#diff-c9c03ff56d42197e419fcb53c7328756R189. Just curious, how are you tracking down the api calls? So far I've just been looking at network traffic and prettified source code from the web app.

codahq commented 5 years ago

The web app only got me so far. For some reason at times either the web app doesn't implement all functionality or my account is flagged to be on previous versions. For example, when you were mentioning you were using the web app to watch alarm traffic I had never had the alarm available in my web app. I also don't have the beams available in the web app now.

Instead, I've decided to start watching traffic from the android app. It took a lot of doing because of the pinned certificate embedded in the app but at this point I can see everything I think. With a pinned certificate you only have a couple of options to watch SSL traffic; modify the apk or modify the OS. It was easier to modify the OS in this case so I rooted and added a cert and then used an XPOSED module to get around the pinned cert. Let me know if you have questions about the details.

dgreif commented 5 years ago

Wow, sounds like a lot of work to intercept the traffic! I also do not have access to the lights via the web app yet, but the source code seems to all be there (minified). I mostly just monitored the websocket traffic as I made changes to the lights from the app, and applied the alarm techniques to send commands like what I was seeing from the lights. Seems to be working great. Let me know if either of you get a chance to test it out.

codahq commented 5 years ago

It was kind of a lot of work but at the end of the day it will be worth it to me I think. I have a few other APIs I want to reverse (Anova, August and maybe poke around Wyze) and I don't think any of them have web apps and their phone apps are also likely to have pinned certs.

*edit: The funny thing is... I figured this is what you were doing. At the time I found your project the web app for me didn't support the alarm yet. I was hoping to avoid having to root and do Android hackery. It worked out because I reversed control and response for locks, contact sensors, motion sensors, keypad and the security panel. The one thing I haven't tried yet is subscribing to notifications for the cameras but I'm pretty sure I saw your library doing that so I'll take a look. If you figured that out, was it just a post to a subscription URL to give them a call back POST URL?

wondergit113 commented 5 years ago

Added them to Homebridge/Home Kit today and they were all setup nicely. My groups passed through fine as well as individual lights and motion sensors. Works great.

Question: is it possible to include serial number or other attributes here? Is there a reason these are all lower case and named the way they are? https://i.imgur.com/2vZMklU.jpg

dgreif commented 5 years ago

@jamesg311 I do currently list the serial numbers for any real hardware devices. Model is something that I could definitely improve on, but currently it shows the value from deviceType. Ring does not supply any nice lists of device type to device model mapping, but I could manually create a list the device names if that would be helpful. As for the light group that you sent an image of, it's a fictional device so there is no actual serial number. The only other field I can think of that would be useful would be FirmwareRevision, which I could add. What fields were you looking for in particular?

wondergit113 commented 5 years ago

It’s more of a nit, not super important. Thanks for the info, though.

On May 22, 2019, at 9:43 AM, Dusty Greif notifications@github.com wrote:

@jamesg311 I do currently list the serial numbers for any real hardware devices. Model is something that I could definitely improve on, but currently it shows the value from deviceType. Ring does not supply any nice lists of device type to device model mapping, but I could manually create a list the device names if that would be helpful. As for the light group that you sent an image of, it's a fictional device so there is no actual serial number. The only other field I can think of that would be useful would be FirmwareRevision, which I could add. What fields were you looking for in particular?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

dgreif commented 5 years ago

@codahq would you mind linking me to some of the info you used to set up you https monitoring? The pinned certs definitely make this more difficult...