Ring Device integration via MQTT w/ Video Streaming

I have created a script to connect Ring alarm devices, including many compatible 3rd party Z-wave devices, as well as cameras and smart lighting, to Home Assistant. Recent versions also include support for live and recorded event video streaming via RTSP. The code includes support for Home Assistant MQTT discovery so the majority of devices appear automatically, only streaming cameras require manual configurations, because they do not support MQTT discovery (the MQTT camera component is for still images only, which is also supported for snapshot).

Auto discovery/configuration was an absolute goal of this project and there were quite a few challenges to solve there, especially around Home Assistant restarts and MQTT disconnects/reconnects, which require auto discovery information to be resent. This script monitors the MQTT connection state and also for birth messages from Home Assistant so that, if Home Assistant is restarted, it will resend all of the auto discovery information. Birth/Last Will messages are now enabled by default in recent versions of Home Assistant so they should work automatically when using default settings of the Home Assistant Mosquitto integraiton.

This script also monitors the state of the websocket to hub devices (alarm and smart lighting) and the polling state for cameras and reports reachability state to Home Assistant if anything interrupts the connection to Ring.

The script can be used directly and I have also published a Home Assistant addon. Please read the instructions carefully to setup 2FA authentication which Ring now requires for all accounts. For those wanting the Home Assistant addon simply add this as a repository to the addon store section of the UI:

If you want to run the script via Docker or natively on Linux (it’s written for NodeJS so it should run on any Linux system):

16 Likes

I’ll give this a try this evening, Thanks in advance!

what happens if home-assistant restarts?

As documented in the readme and mentioned in the OP, you can configure the home assistant MQTT component to issue “birth messages” to the HA state topic. Basically, when home assistant starts it sends an “online” message to the configured topic. The script monitors this topic and, when it sees an “online” message, which indicates that the home assistant service has started, it waits 30 seconds to give HA time to settle (especially after updates) and then resends the auto configuration information.

What this looks like from the UI is that you will see the UI populate with some items showing “unknown entity” but then after 30 seconds or so, all the entities will suddenly appear as normal.

I’m a little concerned that 30 seconds might not be quite enough, especially after upgrades. Normally HA is quite ready to take auto configuration after 30 seconds, but I recently updated on my rpi3b+ from .86 to .88 and that first startup takes quite a bit longer to settle out. It kind of “half worked” (i.e. most devices showed up but a few didn’t) until I restarted HA a second time. I may increase it to 60 seconds just to be sure, or perhaps make it a configurable option in the config file.

Note that it does the same thing if it disconnects from ring (for example an interruption in the internet connection or a Ring service outage), or if the MQTT broker is restarted, although it only waits 5 seconds after the connection is reestablished in those cases. This isn’t absolutely required, but it doesn’t hurt anything since sending the same config again just updates the existing devices and this way it easy to make sure any state changes that happened to the devices while connectivity was interrupted are communicated to HA as soon as that connectivity is reestablished.

I’ve tested all of this pretty extensively and, other than the one glitch above when upgrading HA, it’s worked perfectly, but there could of course be cases that I missed.

need a little assistance, im new to home assistant and linux. is there a certain folder these files need to be put into? when I run chmod +x ring-alarm-mqtt.js in the terminal it doesnt show its doing anything it just goes right back to the command line. am I missing something or doing something wrong? I did the npm install and it installed everything. when I restart home assistant after adding everything to the configuration.yaml and all that it still doesnt show anything. Thanks in advanced for the help, trying to learn as I go.

Just got around to trying this, Works great! thanks for doing this. Now I need to create a startup script.

Thanks for the feedback! Hopefully I’ll get back to working on it soon. I added a sample startup script that I use on my Raspbian install. I typically put my scripts in /opt/<script_folder> and run them as the homeassistant user, so you’d need to modify that as appropriate for your system, but wanted to at least have something out there as an example.

1 Like

Your script is working great! Thanks so much. I did have a question is there an easy way to take what dgreif has done here “https://github.com/dgreif/ring-alarm” and have your scripts discover locks? etc?

Looks like he has discovery scripts for everything.

1 Like

What do you mean by “easy”? :slight_smile:

My code already uses the ring-alarm API from dgrief, so certainly it is possible, however, to make sure I understand the question, I believe the Ring alarm only integrates with 3rd party z-wave locks, i.e. they don’t have their own, right? Are you wanting Home Assistant to be able to see and control these locks via Ring vs just connecting them directly to Home Assistant, which already supports z-wave?

Unfortunately, I don’t have one of these devices, but I’m assuming it would be fairly easy to add support, right now I’m returning all devices, but just ignoring any that I haven’t added specific code to support.

I think “easy” was the wrong word. I know alot of work goes into these and I am grateful for that. I just saw you were using his api and wondered if we could somehow use his files to pull in extra sensor data.

I have flood sensors too, but the lock in home assistant would be great! RING’s lock/pass code setup is so much better than HA. Being able to quickly give guest access on the fly and that code disables the alarm is great. Being z-wave it can only be paired with one device though so that means I cant use the lock in HA or node-red which I would love to be able to do. I could test something out if you would like.

I took a glance at the API to see what it looks like the effort might be to add support for locks. It doesn’t look like it would be too difficult, but I’m not sure I’m a skilled enough coder to manage to pull this off without having a device to test with as I’m still pretty new to Javascript/node.

I do plan to add support for flood/co2/fire sensors because I have those as well, but those are quite easy because they are just state monitor, while for locks, I’m assuming also you’d also want to be able to set lock/unlock state as well. Not that this is super difficult either, just adding a command topic and some code the set the lock state, but not having anything to test ups the ante for me as more of a hacker vs an actual developer. I’ll think about it and, if I get some time, maybe I’ll take a stab at it.

Just used your startup script, works like a charm! Thanks

I’ve created a branch that attempts to add the basics for lock support. Right now it just attempts to create the devices in HA and monitor their state but, if someone that actually has a lock will test this and let me know if it works, I can look at adding support for controlling the lock state as well.

For now this code lives in a separate branch (lock_support), but the only file that is different is the ring-alarm-mqtt.js so you should be able to just pull that down and drop it over the existing one and restart.

Any chance you could document all the COMMAND topics? I’m sure I could figure it out, but would definitely save some time and there might be some nuggets I miss. I’m directly controlling a la MQTT from node-red. Would help others as well. Thx!

Getting this when running…

mosquitto_sub -h localhost -v -t “#”

undefined/alarm/dnrfz2-35lmb-0/alarm_control_panel/12f75594-4d8f-42f1-ad54-fb9abe1fe3fc/command ARM_AWAY
undefined/alarm/dnrfz2-35lmb-0/alarm_control_panel/12f75594-4d8f-42f1-ad54-fb9abe1fe3fc/state armed_away
undefined/alarm/dnrfz2-35lmb-0/binary_sensor/c5e9cbb5-e38a-4072-bdec-c6bd58fa6f76/state OFF
undefined/alarm/dnrfz2-35lmb-0/alarm_control_panel/12f75594-4d8f-42f1-ad54-fb9abe1fe3fc/command DISARM
undefined/alarm/dnrfz2-35lmb-0/alarm_control_panel/12f75594-4d8f-42f1-ad54-fb9abe1fe3fc/state disarmed

Why is it “undefined”?

Ok, I can see that code is looking for ring_topic in config.json, but your canned config has “topic”. Changed to “ring_topic” and removed trailing “/” and looks good.

Yeah, actually I just fixed that bug earlier today and committed it to github just probably an hour ago. I updated the config.json file on github and also coded “ring” as the default topic if someone is still using the old config with just “topic” instead of “ring_topic” so that at least won’t get “undefined”. It managed to sneak through my initial testing because it still worked with Home Assistant due to auto configure.

BTW, you can also run the script on the command line as follows:

DEBUG=ring-alarm-mqtt ./ring-alarm-mqtt

This will give you a nice dump of all discovered devices, and their topics and then you can follow along state changes, etc so you can see any values. The values for the command/state topics follow the Home Assistant defaults for the various MQTT components, so if you want to know the available values you can also just look at the appropriate documentation for the component.

Great work!

I created an addon based on your code (no modifications to ur source). Kept the options exactly the same as well.
The addon does a git pull from your repository - hope that’s all right with you.

The url for the addon is https://github.com/rs1932/ring-alarm-hassio-addon

In the addon starting the script with debug enabled for troubleshooting.

4 Likes

@tsightler Litterally just saw you updated it right after I did my pull. :slightly_smiling_face:

Nice work on this. I was using node-red to detect HASS birth and then issue a “status check” with @acolytec3 script. Great to see you both collaborating on this. Will be testing lock support now…

The script from @acolytec3 really saved me a ton of time, especially understanding the basics of how HA’s MQTT discovery worked. It’s really fun to work on projects like this and have different people contribute.

For example, @rajansub putting together that hassio addon, which I definitely didn’t have plans to do, at least in the short term, because I don’t use hassio. Thanks a lot as I’m sure that will open up more users.

If the lock discovery/monitor works I’ll actually be a little amazed because it only took a few small changes. I really want to refactor the code a little and split the device support into a library, but I’m not sure when I’ll have time for that so I just tried to hack it in with the minimum changes possible and at least see if discovery would work. Definitely interested in the feedback, but make sure you pull the very latest code as a few of the first pushes definitely had some bugs that broke status updates for the alarm panel.