Ring Device integration via MQTT w/ Video Streaming

Interesting that you had to do this as the Mosquitto addon should create this user automatically, at least, the script for it is supposed to.

Is it possible to get the definitive snapshot for a given motion event? You say with the new version, you now get the UUID of the snapshot with the notification into ring2mqtt, but I don’t see where that is presented in a single place in HA (but then I haven’t looked at any events you may be emitting from the addon).

Previously I have detected a change on the motion or ding sensor and then wait for a change in timestamp and url on the snapshot camera, but I’m hoping with the new push notifications there is a better way than this.

I don’t really understand the query, the UUID is just used so that ring-mqtt can get the notification snapshot directly from the Ring API, it’s sent to the snapshot camera like any other snapshot, it’s simply sent as quickly as it can be retrieved after a motion event is detected (usually <200ms but can vary based on bandwidth, Ring API response time, etc).

Previously I have detected a change on the motion or ding sensor and then wait for a change in timestamp and url on the snapshot camera, but I’m hoping with the new push notifications there is a better way than this.

It’s difficult for me to understand what way could possibly be better than this. Since all other snapshot types are blocked when motion events are detected, you can be sure that any update after a motion event is the best snapshot that ring-mqtt could retrieve for the event, whether via UUID or forced snapshot request (valid for high-power cameras only). I feel like this logic is exactly the correct thing to do.

I suppose I could possibly include the UUID as an attribute of both the motion event and the snapshot, but this seems unnecessarily complicated, especially since there are weird corner cases where a UUID isn’t available so automations would have to deal with that case.

I think the challenge is that I’m rely on HA entities and those take time to process. To give what I see as a sequence of changes to states and attributes on the binary_sensor.motion_sensor and the camera.snapshot sensors

  1. BS - State change to On
  2. Cam - timestamp is changed (600ms)
  3. Cam - access token is changed (76000ms)

I’ve added at the end of each line the time (approx) from the first event indicating a motion. So it takes over a minute for the HA entity to be updated with the snapshot picture. However the timestamp on the camera entity and lastMotion on the snapshot are only 1ms apart.

It therefore becomes difficult to identify which snapshot relates to the motion since you have to wait over a minute to have it presented in HA (or maybe my problem is it takes that long to reach NodeRed, but I haven’t had that long to wait before).

It could be I’m misinterpreting what the access token represents. I thought it was a link to an individual image, but I’m sure during my testing that I’ve seen two different tokens link to same image, and I’ve seen the image change against a single token.

So I’m not sure if I can act on the binary_sensor state change, wait 5-10 seconds and then process the snapshot camera image, or whether it is more complex than that.

Edit: I note that the state on the snapshot camera never changes from Idle, so it isn’t possible to automate based on that, it has to be done on attributes of the camera.

Just configured my flow back like this, and this causes it to download the previous snapshot, not the current one.

I’m going to look and see if I can just work off the MQTT updates, because it looks like the snapshot is in there, so it would remove the delays in HA.

Edit: And this is fallible, because there is nothing that links the motion event to the snapshot. It could be it is doing its occasional snapshot, just before the one that would shown in the notification. As just happened to me the next snapshot I processed from MQTT was a few seconds before the one shown in my Ring app notification.

So yes, I think it would be useful to have the UUID of the snapshot in both motion sensor and snapshot, so it can be tied up.

It could be I’m misinterpreting what the access token represents

The access token is a temporary authentication token, it changes every 10 minutes or so when the old one expires, it’s not tied to any image and should not be used as a trigger for anything.

It’s difficult for me to understand how a UUID is really useful. When a motion event is detected all other snapshots are paused (interval snapshots don’t update while motion = ON) so you can be assured that the next image received after a motion event is the best image, regardless of UUID. Honestly, it’s very, very rare that this update takes longer than 200ms, so just pausing a single second should work reliably enough in the vast majority of cases, unless there’s something HA that’s causing additional delay. The logs show how long it takes from motion notification to snapshot update so you can see if you are seeing delays much longer than this.

Thanks for coming back and I really appreciate the enormous amount of effort you put in.

I do my automation in Node-Red, and that was showing at least 600ms for the image update to come through. I can’t tell if it is quicker in HA native automation because I don’t use it and I think the automation I’m trying to do (as ever) is too complex for it.

From what you said, and from looking at it again I think the MQTT feed into Node-Red is working fine, a little time will tell. I know HA is driven by MQTT, but it seems that getting the snapshot from the MQTT message is quicker than waiting for HA to update. I’m running this on a VM on a Mac Mini M1 so I know I’m not short on compute power.

I’m a little surprised at 600ms, feels longer than almost any time I’ve seen in nearly 1000 events that I’ve monitored (I’ve seen a few cases where Ring API response was slow). The logs should clearly show how long ring-mqtt itself took to push on the motion event and then the image, here’s what an event from one of my cameras looks like:

2022-05-16T17:48:06.573Z ring-mqtt [Front Garage Side] Received motion push notification, expires in 180 seconds
2022-05-16T17:48:06.573Z ring-mqtt [Front Garage Side] Requesting motion snapshot using notification image UUID: 8e42969a-3fee-4468-938a-7b8aba1afb5a:18308579
2022-05-16T17:48:06.573Z ring-mqtt [Front Garage Side] ring/a9ce28cb-fafb-421c-4508-29d54f48cbd3/camera/3045113e46e4/motion/state ON
2022-05-16T17:48:06.574Z ring-attr [Front Garage Side] ring/a9ce28cb-fafb-421c-4508-29d54f48cbd3/camera/3045113e46e4/motion/attributes {"lastMotion":1652723286,"lastMotionTime":"2022-05-16T17:48:06Z","personDetected":false,"motionDetectionEnabled":true}
2022-05-16T17:48:06.709Z ring-mqtt [Front Garage Side] Successfully retrieved updated snapshot
2022-05-16T17:48:06.709Z ring-mqtt [Front Garage Side] ring/a9ce28cb-fafb-421c-4508-29d54f48cbd3/camera/3045113e46e4/snapshot/image <binary_image_data>
2022-05-16T17:48:06.710Z ring-attr [Front Garage Side] ring/a9ce28cb-fafb-421c-4508-29d54f48cbd3/camera/3045113e46e4/snapshot/attributes {"timestamp":1652723287}

So you can see that, from the time the notification is received, until the time the snapshot image is sent, is actually only 137ms. This example uses rich notifications with UUID to retrieve the snapshot.
It would be interesting to see if the delay in your logs is significantly higher because I personally think <200ms is pretty good.

These are the timestamps for MQTT feed into Node-Red, and me pushing the log info to a file. It’s about 600ms which to be honest I’m reasonably happy with.

{"time":"2022-05-18T11:42:23.485Z","topic":"ring/17e5f81c-2128-4f1c-9baa-de18de0202d5/camera/54e01981fb8c/motion/state","payload":"ON"}
{"time":"2022-05-18T11:42:23.490Z","topic":"ring/17e5f81c-2128-4f1c-9baa-de18de0202d5/camera/54e01981fb8c/motion/attributes","payload":"{\"lastMotion\":1652874143,\"lastMotionTime\":\"2022-05-18T11:42:23Z\",\"personDetected\":true,\"motionDetectionEnabled\":true}"}
{"time":"2022-05-18T11:42:24.105Z","topic":"ring/17e5f81c-2128-4f1c-9baa-de18de0202d5/camera/54e01981fb8c/snapshot/image","payload":{"type":"Buffer","data":}}
{"time":"2022-05-18T11:42:24.116Z","topic":"ring/17e5f81c-2128-4f1c-9baa-de18de0202d5/camera/54e01981fb8c/snapshot/attributes","payload":"{\"timestamp\":1652874144}"}

These are (I think) the matching HA state changes, which are also about 600ms apart:

{"time":"2022-05-18T11:42:23.495Z","topic":"binary_sensor.front_door_motion_2","payload":"on","data":{"entity_id":"binary_sensor.front_door_motion_2","old_state":{"entity_id":"binary_sensor.front_door_motion_2","state":"off","attributes":{"lastMotion":1652873400,"lastMotionTime":"2022-05-18T11:30:00Z","personDetected":true,"motionDetectionEnabled":true,"device_class":"motion","friendly_name":"Front Door Motion"},"last_changed":"2022-05-18T11:33:01.349282+00:00","last_updated":"2022-05-18T11:33:01.349282+00:00","context":{"id":"0180d6f153255315ab552490ad1773e2","parent_id":null,"user_id":null},"original_state":"off"},"new_state":{"entity_id":"binary_sensor.front_door_motion_2","state":"on","attributes":{"lastMotion":1652873400,"lastMotionTime":"2022-05-18T11:30:00Z","personDetected":true,"motionDetectionEnabled":true,"device_class":"motion","friendly_name":"Front Door Motion"},"last_changed":"2022-05-18T11:42:23.487427+00:00","last_updated":"2022-05-18T11:42:23.487427+00:00","context":{"id":"0180d6f9e6ff894b9d471ba50a6c32f7","parent_id":null,"user_id":null},"original_state":"on","timeSinceChangedMs":5}}}
{"time":"2022-05-18T11:42:23.502Z","topic":"binary_sensor.front_door_motion_2","payload":"on","data":{"entity_id":"binary_sensor.front_door_motion_2","old_state":{"entity_id":"binary_sensor.front_door_motion_2","state":"on","attributes":{"lastMotion":1652873400,"lastMotionTime":"2022-05-18T11:30:00Z","personDetected":true,"motionDetectionEnabled":true,"device_class":"motion","friendly_name":"Front Door Motion"},"last_changed":"2022-05-18T11:42:23.487427+00:00","last_updated":"2022-05-18T11:42:23.487427+00:00","context":{"id":"0180d6f9e6ff894b9d471ba50a6c32f7","parent_id":null,"user_id":null},"original_state":"on"},"new_state":{"entity_id":"binary_sensor.front_door_motion_2","state":"on","attributes":{"lastMotion":1652874143,"lastMotionTime":"2022-05-18T11:42:23Z","personDetected":true,"motionDetectionEnabled":true,"device_class":"motion","friendly_name":"Front Door Motion"},"last_changed":"2022-05-18T11:42:23.487427+00:00","last_updated":"2022-05-18T11:42:23.491472+00:00","context":{"id":"0180d6f9e70359093ee512fef9bc34c7","parent_id":null,"user_id":null},"original_state":"on","timeSinceChangedMs":14}}}
{"time":"2022-05-18T11:42:24.121Z","topic":"camera.front_door_snapshot","payload":"idle","data":{"entity_id":"camera.front_door_snapshot","old_state":{"entity_id":"camera.front_door_snapshot","state":"idle","attributes":{"access_token":"3af04d953c635bb94fc682b580b6494ab579833878d4b4cc5b58e11905d809e3","timestamp":1652874134,"entity_picture":"/api/camera_proxy/camera.front_door_snapshot?token=3af04d953c635bb94fc682b580b6494ab579833878d4b4cc5b58e11905d809e3","friendly_name":"Front Door Snapshot","supported_features":0},"last_changed":"2022-05-17T18:31:16.974880+00:00","last_updated":"2022-05-18T11:42:13.638782+00:00","context":{"id":"0180d6f9c086d3ca21ceba357f893e83","parent_id":null,"user_id":null},"original_state":"idle"},"new_state":{"entity_id":"camera.front_door_snapshot","state":"idle","attributes":{"access_token":"3af04d953c635bb94fc682b580b6494ab579833878d4b4cc5b58e11905d809e3","timestamp":1652874144,"entity_picture":"/api/camera_proxy/camera.front_door_snapshot?token=3af04d953c635bb94fc682b580b6494ab579833878d4b4cc5b58e11905d809e3","friendly_name":"Front Door Snapshot","supported_features":0},"last_changed":"2022-05-17T18:31:16.974880+00:00","last_updated":"2022-05-18T11:42:24.105544+00:00","context":{"id":"0180d6f9e9694ab7a3581977a06de930","parent_id":null,"user_id":null},"original_state":"idle","timeSinceChangedMs":61867146}}}

That said, it looks like capturing the image either way (via MQTT or HA events) is working fine. I had a method which was clearly wrong (and was providing unreliable results) based on HA events which was confusing things. A simple motion, wait a few seconds, capture image from HA api url seems to work.

Edit: I’ll run in parallel for a couple of days to see if I get reliable results. HA method is simpler, but MQTT has the actual image in the message, so you know you have it.

Hello. I I am using webrtc with ring camera abs the stream will not stop. Is there a simple line of code I need to allow it to time out?

Thank you for ring-Mqtt it’s all work it’s just not timing out

Not sure what you mean exactly, what webrtc are you using specifically? If you are just using the normal Home Assistant UI then it uses stream backend which is based on HLS, this times out after 5 minutes (too long, but hard coded, I can’t do anything about it), as long as you have followed the recommended setup and not enabled pre-load stream or “live” settings in UI.

Thanks, I actually had it open in my computer browser along with my iPhone. That’s why it kept streaming lol

One more quick question is there a way to integrate the microphone into this that you would normally see on the Ring app? If not it’s not a big deal I just figured I would ask

Not currently. The native HLS stream component in HA is not bi-directional. Now, in the future, if the Home Assistant WebRTC support continues to improve, then I’m guessing they could just use the native stream directly from Ring.com and not even need anything in ring-mqtt and, in that case, microphone support could come, but that day is not today!

1 Like

Live stream is no longer working. This from the logs:

2022-05-20T19:56:19.122Z ring-rtsp INF [RTSP] [conn 172.30.32.1:50340] opened
2022-05-20T19:56:19.504Z ring-rtsp INF [API] [conn 127.0.0.1:49198] GET /v1/paths/list
2022-05-20T19:56:19.507Z ring-mqtt [Front Door] Ring live stream has stopped publishing, killing the keepalive stream
2022-05-20T19:56:19.511Z ring-mqtt [Front Door] The keepalive stream has stopped
2022-05-20T19:56:24.503Z ring-rtsp INF [path e04f43a47a81_live] runOnDemand command stopped
2022-05-20T19:56:24.504Z ring-rtsp INF [RTSP] [conn 172.30.32.1:50340] closed (source of path 'e04f43a47a81_live' has timed out)
2022-05-20T19:56:24.504Z ring-rtsp INF [RTSP] [conn 127.0.0.1:51576] closed (source of path 'e04f43a47a81_live' has timed out)
2022-05-20T19:56:24.505Z ring-rtsp [Front Door] Deactivating live stream due to signal from RTSP server (no more active clients or publisher ended stream)
2022-05-20T19:56:24.517Z ring-mqtt [Front Door] Received set live stream state OFF
2022-05-20T19:56:24.517Z ring-mqtt [Front Door] Stopping live stream session on workerId 1

Any ideas?

Hopefully someone can help me. I’m trying to set a generic camera with rtsp, but I can’t figure it out.
I’m using the docker install along with mosquitto in docker. The device is found and snapshots work just fine.

The logs show this when starting the container

2022-05-23T14:05:46.080Z ring-mqtt Detected 8 CPU cores, starting 4 live stream workers
2022-05-23T14:05:47.096Z ring-rtsp ------------------------------------------------------------------------------------------
2022-05-23T14:05:47.096Z ring-rtsp Starting rtsp-simple-server process...
2022-05-23T14:05:47.162Z ring-rtsp INF rtsp-simple-server v0.18.2
2022-05-23T14:05:47.163Z ring-rtsp INF [RTSP] listener opened on 0.0.0.0:8554 (TCP)
2022-05-23T14:05:47.163Z ring-rtsp INF [API] listener opened on 127.0.0.1:8880
2022-05-23T14:05:48.143Z ring-rtsp Creating RTSP paths for all cameras...
2022-05-23T14:05:48.157Z ring-rtsp INF [API] [conn 127.0.0.1:45662] POST /v1/config/paths/add/9c7613398876_live
2022-05-23T14:05:48.159Z ring-rtsp INF reloading configuration (API request)
2022-05-23T14:05:48.173Z ring-rtsp INF [API] [conn 127.0.0.1:45664] POST /v1/config/paths/add/9c7613398876_event
2022-05-23T14:05:48.174Z ring-rtsp INF reloading configuration (API request)

And the the info sensor show the following data:

rtsp://user:[email protected]:8554/9c7613398876_live

When using this info with the generic camera component it throws an unknown error ocurred.

Can someone give me a hand here please?

Cheers

Edit: For completion, this is what the logs say about the RTSP service

2022-05-24T10:12:06.784Z ring-mqtt [Front Door] Received set live stream state ON
2022-05-24T10:12:06.784Z ring-mqtt [Front Door] Starting a keepalive stream for camera
2022-05-24T10:12:06.811Z ring-mqtt [Front Door] The keepalive stream has started
2022-05-24T10:12:06.821Z ring-rtsp INF [RTSP] [conn 127.0.0.1:40772] opened
2022-05-24T10:12:06.822Z ring-rtsp INF [path 9c7613398876_live] runOnDemand command started
2022-05-24T10:12:06.826Z ring-rtsp [Front Door] Sending command to activate live stream ON-DEMAND
2022-05-24T10:12:06.841Z ring-mqtt [Front Door] Received set live stream state ON-DEMAND
2022-05-24T10:12:06.842Z ring-mqtt [Front Door] ring/ad5195e5-48d9-4198-84d1-6893943d3f1a/camera/9c7613398876/stream/state ON
2022-05-24T10:12:06.842Z ring-attr [Front Door] ring/ad5195e5-48d9-4198-84d1-6893943d3f1a/camera/9c7613398876/stream/attributes {"status":"activating"}
2022-05-24T10:12:06.846Z ring-mqtt [Front Door] Starting a live stream session via Ring servers
2022-05-24T10:12:06.946Z ring-rtsp [Front Door] State indicates live stream is activating
2022-05-24T10:12:07.470Z ring-mqtt [Front Door] Live stream assigned to worker 1 with 0 current active sessions
2022-05-24T10:12:11.817Z ring-rtsp INF [API] [conn 127.0.0.1:43038] GET /v1/paths/list
2022-05-24T10:12:11.819Z ring-mqtt [Front Door] Ring live stream has stopped publishing, killing the keepalive stream
2022-05-24T10:12:11.822Z ring-mqtt [Front Door] The keepalive stream has stopped
2022-05-24T10:12:14.897Z ring-mqtt [Front Door] Requesting an updated interval snapshot
2022-05-24T10:12:15.508Z ring-mqtt [Front Door] Successfully retrieved updated snapshot
2022-05-24T10:12:15.508Z ring-mqtt [Front Door] ring/ad5195e5-48d9-4198-84d1-6893943d3f1a/camera/9c7613398876/snapshot/image <binary_image_data>
2022-05-24T10:12:15.508Z ring-attr [Front Door] ring/ad5195e5-48d9-4198-84d1-6893943d3f1a/camera/9c7613398876/snapshot/attributes {"timestamp":1653387136}
2022-05-24T10:12:16.823Z ring-rtsp INF [path 9c7613398876_live] runOnDemand command stopped
2022-05-24T10:12:16.823Z ring-rtsp INF [RTSP] [conn 127.0.0.1:40772] closed (source of path '9c7613398876_live' has timed out)
2022-05-24T10:12:16.824Z ring-rtsp [Front Door] Deactivating live stream due to signal from RTSP server (no more active clients or publisher ended stream)
2022-05-24T10:12:16.836Z ring-mqtt [Front Door] Received set live stream state OFF
2022-05-24T10:12:16.836Z ring-mqtt [Front Door] Stopping live stream session on workerId 1
2022-05-24T10:12:44.903Z ring-mqtt [Front Door] Requesting an updated interval snapshot
2022-05-24T10:12:56.652Z ring-rtsp INF [RTSP] [conn 127.0.0.1:39506] opened
2022-05-24T10:12:56.656Z ring-rtsp INF [path 9c7613398876_live] runOnDemand command started
2022-05-24T10:12:56.662Z ring-rtsp [Front Door] Sending command to activate live stream ON-DEMAND
2022-05-24T10:12:56.678Z ring-mqtt [Front Door] Received set live stream state ON-DEMAND
2022-05-24T10:12:59.904Z ring-mqtt [Front Door] Error: Snapshot for Front Door (doorbell_graham_cracker - Doorbell Wired) failed to refresh after 15 seconds
2022-05-24T10:12:59.904Z ring-mqtt [Front Door] Failed to retrieve updated snapshot
2022-05-24T10:13:06.659Z ring-rtsp INF [path 9c7613398876_live] runOnDemand command stopped
2022-05-24T10:13:06.659Z ring-rtsp INF [RTSP] [conn 127.0.0.1:39506] closed (source of path '9c7613398876_live' has timed out)
2022-05-24T10:13:06.659Z ring-rtsp [Front Door] Deactivating live stream due to signal from RTSP server (no more active clients or publisher ended stream)
2022-05-24T10:13:06.667Z ring-mqtt [Front Door] Received set live stream state OFF
2022-05-24T10:13:06.667Z ring-mqtt [Front Door] Stopping live stream session on workerId 1
2022-05-24T10:13:13.478Z ring-rtsp INF [RTSP] [conn 127.0.0.1:40990] opened

This has something to do with MQTT no passing the data? I’ve read somewhere in this post about this possibility.

1 Like

Hi could anyone help? Getting error on my log “s6-overlay-suexec: fatal: can only run as pid 1” fresh install with latest vestion HA

Thanks Steve

Mine closes from time to time and I have to restart the addon and then it works again.

This is the log, when it crashes:

2022-05-25T04:44:30.029Z ring-rtsp INF [RTSP] [conn 172.30.32.1:59200] opened
2022-05-25T04:44:30.030Z ring-rtsp INF [path 9c7613348770_live] runOnDemand command started
2022-05-25T04:44:30.032Z ring-rtsp [Haustür] Sending command to activate live stream ON-DEMAND
2022-05-25T04:44:30.036Z ring-mqtt [Haustür] Received set live stream state ON-DEMAND
2022-05-25T04:44:40.031Z ring-rtsp INF [path 9c7613348770_live] runOnDemand command stopped
2022-05-25T04:44:40.034Z ring-rtsp INF [RTSP] [conn 172.30.32.1:59200] closed (source of path '9c7613348770_live' has timed out)
2022-05-25T04:44:40.034Z ring-rtsp [Haustür] Deactivating live stream due to signal from RTSP server (no more active clients or publisher ended stream)
2022-05-25T04:44:40.037Z ring-mqtt [Haustür] Received set live stream state OFF
2022-05-25T04:44:40.037Z ring-mqtt [Haustür] Stopping live stream session on workerId 1
2022-05-25T04:44:50.065Z ring-mqtt [Haustür] Snapshots are unavailable, check if motion capture is disabled manually or via modes settings
2022-05-25T04:45:20.065Z ring-mqtt [Haustür] Snapshots are unavailable, check if motion capture is disabled manually or via modes settings

It looks like Timed out… Any ideas what could solve this? This happens every day once but not on the same time.

Currently running version 5.0.1, and curious if live streaming of video from Ring door bells still works, or is it just snapshot support on the latest versions?

For me everything works just like before. What are you experiencing?

@mhoogenbosch previously I had the camera video entity added to a picture glance card, and when you clicked on it it would open the live feed in a pop-up. Now the pop-up opens with the title bar, but no video loads. Nothing has changed on my Ring setup, just various HA updates, etc.

I’m getting the error below in the logs:

Logger: homeassistant.components.stream.stream.camera.front_door_video
Source: components/stream/__init__.py:347
Integration: Stream ([documentation](https://www.home-assistant.io/integrations/stream), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+stream%22))
First occurred: 26 May 2022, 19:04:44 (113 occurrences)
Last logged: 12:48:58

Error from stream worker: Error opening stream (INVALIDDATA, Invalid data found when processing input) rtsp://xxx-ring-mqtt:8554/f8369b2e97f7_live

But I have confirmed that the stream URL matches what is under the camera attributes:

Attributes

BatteryLevel
97

FirmwareStatus
Up to Date

LastUpdate
27 May 2022, 05:27:09

WirelessNetwork
xxx-iot

WirelessSignal
-51

Stream Source
rtsp://xxx-ring-mqtt:8554/f8369b2e97f7_live

Still Image URL
https://homeassistant:8123{{ states.camera.front_door_snapshot.attributes.entity_picture }}

I did also spot this in the logs:

Loading generic IP camera via configuration.yaml is deprecated, it will be automatically imported. Once you have confirmed correct operation, please remove 'generic' (IP camera) section(s) from configuration.yaml

But the doco still mentions configuring the generic camera, so I assume that is still the recommended option? Video Streaming · tsightler/ring-mqtt Wiki · GitHub

Cheers,
Zolt