tsightler / ring-mqtt

Ring devices to MQTT Bridge
MIT License
603 stars 106 forks source link

Support for “Modes” feature #64

Closed denniswham closed 4 years ago

denniswham commented 4 years ago

The ring-client-api has been updated to support location mode switch as off version 7.1.0. Is it possible to update the ring-mqtt script and the new Hass.io addon to support this switch and as a result be able to control the Ring Modes from Home Assistant?

tsightler commented 4 years ago

Maybe. The challenge is that I have the alarm system at all of my locations so modes already work for that case. That means I either need to try to guess at how it works with camera only locations by looking at the homebridge code or, perhaps more likely, buy a camera (or maybe reallocate one of my existing one's temporarily, but that's a pain) and setup a dummy location to test against and try to get it working . Just a quick glance through the code makes it seem doable without too much trouble, but, unfortunately, I'm going to say the chances of me having time to do either of those options in the near future is pretty low, but I'd consider PRs to add support for this.

tsightler commented 4 years ago

Hmm...maybe I'm wrong, perhaps simply having an alarm doesn't automatically mean modes work, looking at it seems I don't have the modes feature enabled on my account. That's going to make it particularly difficult to develop/test.

tsightler commented 4 years ago

Interestingly, tonight, the "Modes" feature was enabled on my account and I received the notification in my Ring app. What a coincidence. I'll think about buying a camera and working on this since I've been considering purchasing an indoor camera anyway.

denniswham commented 4 years ago

What a coincidence indeed. My coding qualities are low, but if there is anything I can provide or test, please let me know. Always happy to help.

denniswham commented 4 years ago

Here's more info about the modes: https://support.ring.com/hc/en-us/articles/360036107792-Control-All-your-Ring-Cameras-with-Modes

tsightler commented 4 years ago

It makes me wonder if they detected me clicking on the modes feature in the app and looking at all the options (the option was there for alarm devices, but not for cameras, now suddenly there's an "Enable Mode Settings for Cameras" option). Anyway, now that my account actually has the feature available I'll consider taking a look at it, but I'll probably have to buy a camera first so it could still be a few weeks. Just looking at the code it seems easy enough to implement, basically create an alarm control panel component even for sites that only have cameras and call some slightly different functions to set the modes.

erenfro commented 4 years ago

I may or may not be able to help much code-wise, as I do not know nodejs very much myself. But, I currently am looking at ring-mqtt because of the HASS Ring.com integration being so buggy and causing startup delays, even startup issues, especially when ring API servers are having issues (or so I'm guessing).

I have a cam-only setup and a HASS virtual alarm system based on presence (with no direct automation to unlock/allow entry, just auto-disarming on proximity). At first, I was confused, since nothing ever showed up, but then, suddenly, I enabled cameras and tada, things started populating. LOL

Really good work I will say. And I do wish I could integrate the security modes in somehow. FYI, the Homebridge Ring plugin has done this, so maybe worth looking at what they're doing for it? I'm thinking "Modes" as in, "Disarm", "Home", and "Away", if that's what everyone else is thinking?

tsightler commented 4 years ago

Yeah, it's not too difficult to add support for modes, I just haven't had any time to work on this project lately and have lots of things I need to address first. It probably doesn't help that I don't use this feature.

In theory I believe it should be really easy, mostly just copy the existing alarm-panel code and modify it to set modes instead of alarm arming state. But I probably also need some logic to show or not show modes based on whether people have alarm, etc.

If I ever manage to get some time to work on this project again, I'll certainly try to add it, but it's probably 3-4 on the priority list behind some other critical fixes and more in demand features.

tsightler commented 4 years ago

I've started a branch for modes support and pushed a version that I was able to do some basic testing on. It requires adding a new setting "enable_modes" to the config.json but if someone could possibly try it that would be great.

I was able to do a little bit of testing and it seems to work OK, but because I have an alarm certain things just aren't possible unless I create a new location without an alarm but I don't currently have any devices I can register to a new location.

If someone who is interested in this feature could clone the "modes" branch and give it a spin I would be grateful, otherwise it may be a week or so before I can get another camera to test with.

For the modes panel to be created the location must have cameras but no alarm and you must manually set the "enable_modes" option in the config.json to true. Also, it's important to note that modes are a "polled" resource, so updates are not immediate and can take as much as 20 seconds. This also means there's more activity when modes support is enabled (part of why it's an option).

https://github.com/tsightler/ring-mqtt/tree/modes

denniswham commented 4 years ago

I run the HA add-on, how can I have that looking to the modes branche of the ring-mqtt repo?

tsightler commented 4 years ago

Other than attaching to the container and updating the code manually, there's not really any other way. I guess I could build a specific addon just for this but seems like overkill. I found a few small bugs in some of my changes during my own testing so I'll try to fix those and perhaps promote this code to the dev tree as I already have an addon that pulls it.

tsightler commented 4 years ago

I've fixed the small bugs I found and merged this into the dev branch. If you want to test it via add-on you'll need to use the "Development" add-on available here:

https://github.com/tsightler/ring-mqtt-ha-addon-dev

This version of the add-on automatically pulls the latest ring-mqtt from the dev branch instead of the production branch. While you can't run both add-ons at the same time (well, you can, but results are unpredictable), you can have them both installed and simply activate one or the other.

denniswham commented 4 years ago

Ran the dev addon, no sign of a Ring Modes entity in the MQTT integration. This is what I see in the log.

2020-08-13T15:59:22.975Z ring-mqtt Using configuration file: /data/options.json 2020-08-13T15:59:22.989Z ring-mqtt File /data/ring-state.json not found. No saved state data available. 2020-08-13T15:59:22.990Z ring-mqtt No refresh token was found in saved state file or config file. 2020-08-13T15:59:23.026Z ring-mqtt Go to http://:55123/ to generate a valid token. (node:7) UnhandledPromiseRejectionWarning: Error: Your Ring account is configured to use 2-factor authentication (2fa). See https://github.com/dgreif/ring/wiki/Refresh-Tokens for details. at RingRestClient. (/ring-mqtt/node_modules/ring-client-api/lib/api/rest-client.js:154:27) at Generator.throw () at rejected (/ring-mqtt/node_modules/ring-client-api/lib/api/rest-client.js:25:65) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 2020-08-13T16:00:05.081Z ring-mqtt Your Ring account is configured to use 2-factor authentication (2fa). See https://github.com/dgreif/ring/wiki/Refresh-Tokens for details. 2020-08-13T16:00:05.082Z ring-mqtt Username/Password was accepted, waiting for 2FA code to be entered. 2020-08-13T16:00:19.806Z ring-mqtt Using configuration file: /data/options.json 2020-08-13T16:00:19.808Z ring-mqtt Using refresh token generated via web UI. 2020-08-13T16:00:19.933Z ring-mqtt Attempting connection to Ring API using generated refresh token. 2020-08-13T16:00:23.232Z ring-mqtt Connection to Ring API successful 2020-08-13T16:00:23.236Z ring-mqtt Starting connection to MQTT broker... 2020-08-13T16:00:23.893Z ring-mqtt File /data/ring-state.json saved with updated refresh token. 2020-08-13T16:00:25.173Z ring-mqtt MQTT connection established, sending config/state information in 5 seconds. 2020-08-13T16:00:30.184Z ring-mqtt No devices found for location ID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

tsightler commented 4 years ago

Well, it found no devices. You won't get a mode panel if there are no devices to set modes on. Did you enable camera and modes support in the config?

denniswham commented 4 years ago

My bad, indeed didn't enable camera and modes in the config. Once I did there, it came to life :) and I see a new alarm_panel entity.

However it continuously keeps changing status from home to armed_away, and the same with home and arrmed_home.

In the log I see multiple of these lines "Socket error on client mqttjs_c142ea8a, disconnecting"

Get Outlook for Androidhttps://aka.ms/ghei36


From: tsightler notifications@github.com Sent: Thursday, August 13, 2020 6:09:05 PM To: tsightler/ring-mqtt ring-mqtt@noreply.github.com Cc: Dennis Ham dennisw.ham@outlook.com; Author author@noreply.github.com Subject: Re: [tsightler/ring-mqtt] Support for “Modes” feature (#64)

Well, it found no devices. You want get a mode panel if there are no devices to set modes on. Did you enable camera and modes support in the config?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftsightler%2Fring-mqtt%2Fissues%2F64%23issuecomment-673567731&data=02%7C01%7C%7C1cf8defdb6ce4aa2488808d83fa33483%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637329317468137085&sdata=18mQa85BzeHhEgZ5T9nw3aML8zt4rfm7RqUpptwAqKA%3D&reserved=0, or unsubscribehttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKI5DJ4VOB7A4TTL45U5J7LSAQF2DANCNFSM4LGLY2FA&data=02%7C01%7C%7C1cf8defdb6ce4aa2488808d83fa33483%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637329317468147080&sdata=zrTzf5Y%2FBHFm7UvgoyCFz0j4B%2F%2Bru56DeOSYrE8g47Y%3D&reserved=0.

tsightler commented 4 years ago

Hmm...OK, interesting, I don't see this behavior with the changing modes, but I might have an idea about it. No ideas about the mqtt socket error though, that's weird, I've not changed anything with regard to the MQTT code at all. Any chance you could send me the logs? If you don't want to post them here you can sent them to my personal email, same username but with gmail. I should have time to look at it tonight, I think it's close.

tsightler commented 4 years ago

I was able to pull one of my cameras into a separate location and give this code a more through run through. After a few battles I believe that it should be working pretty well now. @denniswham If you could rebuild your dev add-on and try it again and report I would appreciate it.

One thing I did notice, even though the mode changes it takes a VERY long time for this to show in the Ring App, unless you completely exit the app and restart it.

denniswham commented 4 years ago

Works like a charm now!

When changing the mode in the Ring app, I see the change in HA within 5-10 secs 👍

In the add-on I have logged in my Ring account with my own account. When changing the status, as you said I don't see it in my Ring app (on Android), but my wife sees it in her Ring app (logged in with her account on her iPhone) almost instantly. So the different experience could be caused by the platform on which the app runs, or because of the different user account. Haven't tested it with her account logged in in the add-on.

I'm very happy with the result, thanks a lot!

denniswham commented 4 years ago

I rebuilt the "production" ring-mqtt add-on and see that the version is changed to 3.3.0. In the config I can choose to set location modes to true. However the location mode doesn't show up as an entity.

tsightler commented 4 years ago

Did you also enable cameras? Did you look at the logs and see what it says? Did you click the "rebuild" option on the add-on? What version of the ring-mqtt.js script does the addon show it is using when you start it?

denniswham commented 4 years ago

Also enabled cameras and those showing up in the log. But when starting it says

ring-mqtt.js version 3.2.1

So that's why the mode isnt showing up

Get Outlook for Androidhttps://aka.ms/ghei36


From: tsightler notifications@github.com Sent: Friday, August 14, 2020 7:43:08 PM To: tsightler/ring-mqtt ring-mqtt@noreply.github.com Cc: Dennis Ham dennisw.ham@outlook.com; Mention mention@noreply.github.com Subject: Re: [tsightler/ring-mqtt] Support for “Modes” feature (#64)

Did you also enable cameras? Did you look at the logs and see what it says? Did you click the "rebuild" option on the add-on? What version of the ring-mqtt.js script does the addon show it is using when you start it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftsightler%2Fring-mqtt%2Fissues%2F64%23issuecomment-674187709&data=02%7C01%7C%7Cec4a382ea97b4966a0a708d840798278%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637330237902630577&sdata=%2Fd7hMlCVSbCqAuQsofc%2Ff7q3k0dZvaQ5pl1oOMjxnnE%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAKI5DJ3OFRMTB2QMWALROWTSAVZSZANCNFSM4LGLY2FA&data=02%7C01%7C%7Cec4a382ea97b4966a0a708d840798278%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637330237902640570&sdata=LGf1eaz8KlzPVa3L75rJjKMOSEKkhjn9kTBn390R%2BDI%3D&reserved=0.

tsightler commented 4 years ago

Stopping the addon, clicking rebuild and waiting for that to finish, then restarting should pull the latest script version. I just went through this exact process in my own lab setup.

Today the addon is not really tied to the script version in any way, upgrading the addon doesn't automatically upgrade the script. They've mostly kind of followed each other version wise because new versions of the scripts have required minor tweaks to the addon, but there's nothing technically linking the two at all.

When I bump to version 4.0 with, which will include for support for the HA device model, I'll probably also switch the addon to using pre-built docker images which should fix that issue.

denniswham commented 4 years ago

Tried exactly what you described but the ring-mqtt.js version stays at version 3.2.1. Even uninstalled the add-on and re-installed (followed by a rebuild) and that didn't change it...

tsightler commented 4 years ago

I don't really know how that is possible. Not saying your lying, I've actually had one other report of something similar, but I just can't see how. The add-on does nothing but pull the latest git version from the master branch, that's it. Without logs from Home Assistant I don't know how to even make a guess as to the issue but it's certainly outside of the addon/script. I guess you could try completely removing the repository and re-adding.

denniswham commented 4 years ago

Solved! And thanks to you, you’re awesome!

Here’ what I did because of your remarks:

Hopefully the above is also helping the other users which are experiencing the same issue. Thanks so much for our support!

padzster commented 10 months ago

Did you enable camera and modes support in the config?

Hi, how can I do this?