tsightler / ring-mqtt

Ring devices to MQTT Bridge
MIT License
557 stars 101 forks source link

No Motion/Ding events for Doorbells/Cameras/Intercoms #643

Closed alexreddy78 closed 1 year ago

alexreddy78 commented 1 year ago

Dear Developer,

Recently was detected that no more mqtt messages comes with motion detected or door dings on Ring DoorBells. However native Ring application is still functional. Is that something with your software or Ring's guys did something bad with software?

Your answer and possible help is very appreciated. There is nothing in logs that I can provide to you. Just no action on motions and dings any more... I see as well few report on community pages.

Thanks

alexreddy78 commented 1 year ago

Update:

Just found comments and issues regarding this problem. Sorry for not being smart from the beginning. Removed all unknown devices from Authorization in Ring application and refreshed token in addon. For the moment all back to normal. But, I noticed, that many users said, that this fix is working only 24hrs. So, will monitor the issue and let you know.

Best Regards

tsightler commented 1 year ago

Thanks @alexreddy78

As you can see we are already quite aware of the issues but we still don't really have an understanding of why this is happening. Our best guess is that Ring has made some changes to how session registration for notifications is handled, and we've tried some experiments, but, so far, we can find out a cause.

Sometimes it even varies for the same user. For example, I run two instances of ring-mqtt, one for my production that runs my actual home automation system, and another that is mostly a duplicate, but that I use for development and testing of ring-mqtt. At this minute the production instance hasn't received a notification for any device in over a week, but the development instance continues to work fine even though they were both restarted at the same time and are nearly identical in every way, other than having different system IDs.

This is impacting far beyond ring-mqtt, to any tool that uses ring-client-api. I'm sure we'll eventually figure it out, but for right now it is quite frustrating, but that's the nature of having to reverse engineer support for vendors that don't otherwise provide supported means for integrating with their products.

I'm going to leave this issue open until it is resolved. Users should monitor this issue for updates.

alexreddy78 commented 1 year ago

Thanks for reply!

Yes, I can confirm, issue after some time get back... :( However, I did a little trick, I installed a native Home Assistant Ring integration and motion events are working there. So temporary I will use events from there and live stream from rinq mqtt. It's real strange that in native integration it's still working. As well thanks for the link to monitor the issue. Hope somehow the answer and solution will be found.

What do you think if I will try to remove device from Ring account, delete account as well and create a new one and again link device. Will it help or you and your colleagues already did such a trick?

Regards!

tsightler commented 1 year ago

Native Ring integration does not use push notifications, but still uses much slower polling (even worse if users have many devices), but also, it's not just about that, many users are also reporting that the native Ring integration stops working after a period of time as well, even though it uses a totally different method to get events, so it's also about how Ring is handling notifications on a per-device basis. For example, I have one installation of ring-mqtt that is working and one that is not, on the very same account.

The problem itself is pretty well understood, unfortunately, the solution is not...yet.

wouterdebie commented 1 year ago

I know it might be annoying when people add "I'm experiencing the same" on a github issue. However, I've tried to reauthorize, but even that doesn't seem to help. I'm using ring-mqtt to monitor the state of my alarm system and it seems I'm not getting any signals from Ring, so my automations don't work. I'll track the issue though

tsightler commented 1 year ago

@wouterdebie The issue described here does not impact Ring alarm or smart lighting devices (basically, devices which use a hub) as those devices use an entirely different protocol and API. If you are having problems with these you should look elsewhere or perhaps open a new issue providing full logs, however, there have been zero other reports of issues with these devices.

The issue documented here impacts only devices which depend on push notifications, i.e. Ring doorbells, cameras and intercoms.

wouterdebie commented 1 year ago

I see. My alarm events stopped working a few days ago, but it might have been something different. I removed all authorized devices from ring.com, reauthenticated and replaced all devices in my automations, which seemed to work. Anyway, thanks for the quick response.

ssamsonice commented 1 year ago

I agree. My Ring alarm works well. It is just my doorbell that has the mentioned issues.

alexreddy78 commented 1 year ago

Will give you some short update: For 2 days already, my Doorbell is working OK! Even I tried to reboot Home Assistant server, no impact :). What I did: I removed from authorization all linked apps and hardware (Alexa Echo 5) and start mqtt ring addon from the scratch, get token and that’s it. So, in my case, deleting of Alexa Echo 5 from access is helping. Did same tricks with Alexa linked to Ring - no success.

Will keep an eye and again update you later on.

Regards!

tsightler commented 1 year ago

For users of ring-mqtt, I'd be pariticularly interested if you could test the current development branch (set branch option to "dev" in config and restart). After doing so you will need to remove devices (including unknown devices) and re-authenticate, however, my hope is that this might have a chance at reducing the issues after this point.

The current dev code is using a highly custom version of ring-client-api which I've hacked up to support persistent FCS tokens instead of the previous way which created new tokens on each startup. I'm hopeful that this might address the issues of notifications not working after a restart. So far it seems to work for me (for me notifications have survived 48 hours on both instances even with mulitple restarts).

However, this is mostly a temporary and experimental fix as we still haven't been able to determine root cause as to why push notifications randomly stop, but this should at least avoid the case where they don't work after a restart. I've noticed that a lot of people do things like have scheduled restarts or have short internet outages which lead to reconnects, and that stops notifications with the current code so hopefully this might help at least a little.

alexreddy78 commented 1 year ago

Dear Tom,

Thanks for fix. Just installed dev version and can say, that motion events are working, but with huge delay :( for example I set motion events expired to 10 sec and addon has to get action after again. Next motion event will happen approx in 40 sec. However this happen only in dev version. So roll back to addon version.

Regards

tsightler commented 1 year ago

@alexreddy78 I'm not really sure what you are even talking about honestly. There are no changes in the code except for the re-use of existing FCM token instead of generating a new one during each startup, there are no changes around timing or anything else.

alexreddy78 commented 1 year ago

@tsightler What is the reason to me for lie? :( I only say what I see…First of all, it’s in my interest that software is working in a proper way. Will do another try and reply back

0546timm commented 1 year ago

@alexreddy78 I'm not really sure what you are even talking about honestly. There are no changes in the code except for the re-use of existing FCM token instead of generating a new one during each startup, there are no changes around timing or anything else.

Unforuntatly the motion issue did not resolve for me with the 'dev' branch :(.

Hoping something will be figured for the main branch, this is the most intense used custom addon in my HA, loving every piece of it and your work :). Thanks for that!!

tsightler commented 1 year ago

@0546timm Did you follow the instructions to remove all previous authentication devices from authorized client devices and re-authenticate? The dev branch will not automatically fix this, this step must be performed manually. The hope is that the fix will keep users from having to repeat these steps on every restart.

tsightler commented 1 year ago

@tsightler What is the reason to me for lie? :( I only say what I see…First of all, it’s in my interest that software is working in a proper way. Will do another try and reply back

I did not, in any way, accuse you of lying, but I guess I could ask you the same question, what reason would I have to lie? I simply stated the fact that I didn't understand what you were talking about (i.e. I don't understand your description of events) and that there were no changes made to the code that would impact this.

If I were to attempt to interpret your previous statement, I would say that you have an expectation that setting motion duration somehow impacts how often Ring will send a notification, but that is not the case, it only controls how long ring-mqtt will leave the sensor in ON state after it receives a motion notification. Ring will not send another motion notification until the camera has stopped recording the previous event because Ring cameras never send notifications while recording.

0546timm commented 1 year ago

@0546timm Did you follow the instructions to remove all previous authentication devices from authorized client devices and re-authenticate? The dev branch will not automatically fix this, this step must be performed manually. The hope is that the fix will keep users from having to repeat these steps on every restart.

Hey,

I did not did it in the order you told. But looking at my Telegram Bot I can see videos coming in again so it seems to work eventually :).

Many many thanks!! Looking forward to the stable release but this helps me tremendously. Thanks for all your efforts!!

0546timm commented 1 year ago

Small update: It's working but detection is not picking up all the events. For example, this morning I've walked passed the camera twice to my car and to feed my dog. They don't appear in my Telegram bot videos. But a few hours earlier it did detect the postman on the sidewalk and an hour after I left my home it also sees a pedestrian walk by with a bike.

No attack or comment, I'm super glad the plugin is functioning at this point as I use it daily. But just so you know :).

Thanks again for all your efforts!!

jeffgraham-hub commented 1 year ago

I've been running the dev version for approximately 48hrs without any issue.

tsightler commented 1 year ago

@0546timm I don't really know what "telegram bot videos" are. Do you mean snapshot images? Without real examples and logs there's not much that can be done with this anecdotal information, however, the code which receives push notifications is unchanged from previous versions, thus I doubt that the behavior is any different than it has ever been. Ring cameras pretty much never pick up all events. I feel like I have to dance in front of my front porch camera sometimes to get it to go off, other times a leaf blows by and it goes off, however, without specific cases of notifications working in the Ring app vs not working in ring-mqtt, there's not really much that can be done.

@jeffgraham-hub Thanks for the update, I'm hopeful that a new version of ring-client-api with support for persistent FCM push tokens will come out soon and then I will push an update with the latest behavior.

I'm also considering re-implementing polling in ring-mqtt itself as a backup, although it's slower and doesn't support sending snapshot images for low-power mode cameras, but I guess that might be better than not working at all.

alexreddy78 commented 1 year ago

@0546timm I don't really know what "telegram bot videos" are. Do you mean snapshot images? Without real examples and logs there's not much that can be done with this anecdotal information, however, the code which receives push notifications is unchanged from previous versions, thus I doubt that the behavior is any different than it has ever been. Ring cameras pretty much never pick up all events. I feel like I have to dance in front of my front porch camera sometimes to get it to go off, other times a leaf blows by and it goes off, however, without specific cases of notifications working in the Ring app vs not working in ring-mqtt, there's not really much that can be done.

@jeffgraham-hub Thanks for the update, I'm hopeful that a new version of ring-client-api with support for persistent FCM push tokens will come out soon and then I will push an update with the latest behavior.

I'm also considering re-implementing polling in ring-mqtt itself as a backup, although it's slower and doesn't support sending snapshot images for low-power mode cameras, but I guess that might be better than not working at all.

Dear Tom,

Thanks for support! Kindly advise of meaning: "re-implementing polling in ring-mqtt itself as a backup" - will this fix somehow influence to the low-power doorbells or function will stay as it's now?

Regards

0546timm commented 1 year ago

@0546timm I don't really know what "telegram bot videos" are. Do you mean snapshot images? Without real examples and logs there's not much that can be done with this anecdotal information, however, the code which receives push notifications is unchanged from previous versions, thus I doubt that the behavior is any different than it has ever been. Ring cameras pretty much never pick up all events. I feel like I have to dance in front of my front porch camera sometimes to get it to go off, other times a leaf blows by and it goes off, however, without specific cases of notifications working in the Ring app vs not working in ring-mqtt, there's not really much that can be done.

Sorry, should've eleborated on that bit.

So, I have an automation that triggers of the motion on the Ring doorbell. Then when triggered I start a video capture of ~15/20 secs which is saved locally and send to my Telegram Bot. This way I get notification on my Telegram when somebody is moving around my front door.

What I ment it, I've changed the addon branch to 'dev'. Then I removed the MQTT application from HomeAssistant, re-added it and tested it. Then I did not saw anything coming through and made the post above.

Went to sleep, woke up with a few notification on my phone again.. Seems like the system of HA or whatever resolved itselve and video's came through again, meaning, the trigger (motion sensor) is working again.

And yes, you are right. Sometimes I get videos of the tree in my front yard moving due to the wind and the motion capturing it. And a few mins later when I pass with the dog it did not went off.. It's not a super sensor indeed.

Again, super happy it's working again, appreciating all your work!!

tsightler commented 1 year ago

@0546timm Thanks for the information

@alexreddy78 I'm afraid I don't understand the question. Event polling is not unique to battery cameras, I'll try to explain below:

When it comes to doorbell dings/motion detection, Ring cameras don't have state, they only have events. If you press a doorbell button, that is a "ding" event, if a camera detects motion, that is a "motion" event. Ring cameras are unable to send events while they are recording, so, once a recording starts, there will not be a new event until recording stops. Historically Ring cameras could be set to record for a specific period of time, 15 seconds, 30 seconds, 60 seconds, with the default being 30 seconds (perhaps 15 seconds for battery cameras, not sure, as I don't own one). More recently, Ring has rolled out adaptive recording where the camera will start recording on motion and record until motion stops.

There are effectively two ways to detect these events, the old way, which required constant polling of the Ring API to a special endpoint, and the more modern way, which uses Googles Firebase Cloud Messaging to receive notifications of events.

Prior to ring-mqtt v5.x (ring-client-api v11.x) only the polling method was used. Basically, every two seconds, ring-client-api would query the "dings" Ring API endpoint and that endpoint would return a response that included any "active" events, which Ring generally considered for 180 seconds or so. This method works of course, but, since it requires polling an API, it's slower (on average notification takes 1 second, but might be up to 2 seconds), it was subject to throttling and other technical issues, but it mostly worked.

The biggest disadvantage of the polling method was for battery/low-power cameras. Ring cameras that operate in low-power mode are unable to take snapshots while recording. Ring cameras always take a snapshot when they detect an event and upload that image to the Ring servers for use with the notification, but the polling API does not include the UUID of this image so the polling method makes it impossible to get a snapshot image of the motiion event from a Ring camera via snapshot.

The newer method, used by all Ring apps and even the web dashboard, is to use push notifications via Firebase Cloud Messaging. This is the same method used to deliver push notifications to the Ring app on Andriod/iOS devices, and also for the Ring web based dashboard. This is the method used in ring-mqtt starting in v5. Push notifications don't require polling, and thus they are much faster. Also, as long as rich notifications are enabled (a feature that requires a Ring subscription), the UUID of the snapshots image uploaded by the camera as part of the event notification is included in the notification data. This makes it possible for ring-mqtt to retrieve that image, even for battery cameras, since it works the same way as the app.

The biggest disadvantage of push notifications is that they are impacted by settings which suppress notifications, for example, smart alerts, while the polling API is not. The second disadvantage is that they just don't seem as reliable across a broad range of environments, although they work very well for me, I still see the occasional missed notification, even in the Ring app.

While ring-client-api completely removed support for the polling API in v11, it's still possible that I could re-implement that support in ring-mqtt itself and use it as a secondary source of events, which is all my comment above was conveying. This is exactly what has been done for Scrypted, for example.

However, now that I've done more digging into push notificiations, and see that none of the Ring apps actually use it at all anymore (at least as far as I can tell), my lean is to hope that the fixes we have implemented for push notifications might be good enough.

tsightler commented 1 year ago

For those monitoring this thread, ring-mqtt v5.3.0 has been released. This release uses a new upstream version of ring-client-api that implements support for persistent FCM tokens. If you are not receiving notifications after upgrading (likely) you will need to follow the steps to remove all previously authenticated ring-mqtt instances from the Ring Control Center and then re-authenticate.

For those who were on the development version, thanks for the testing. Unfortunately, the token format changes between the development version I had hacked together and the upstream version of ring-client-api and I did not implement a migration, so, even if the dev version was working, you will need to repeat the steps of removing all ring-mqtt devices from Ring Control Center and re-authenticating as well. Hopefully this will be the last time.

Now, we still don't know what will happen if/when these FCM tokens expire. Perhaps they don't expire, but that seems, well, optimistic. However, this should at least get things working for periods of weeks/months instead of requiring re-authentication on every restart.

Stefan300381 commented 1 year ago

@tsightler thanks a lot, will give it a try

@0546timm could you share the code you run to capture the video? I'm not sure if you can sent private messages on github, so feel free to send via email to stefan AT haupt DOT xyz

0546timm commented 1 year ago

@0546timm could you share the code you run to capture the video? I'm not sure if you can sent private messages on github, so feel free to send via email to stefan AT haupt DOT xyz

Sure, no problem.

You'll need a Telegram bot and this Ring plugin for it to work obviously.

alias: >-
  Ring - Wanneer Ring motion detecteert, neem 30 seconden beeld op en stuur naar
  Telegram bot
description: Overschrijft elke keer.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.deurbel_motion_2
    from: "off"
    to: "on"
condition: []
action:
  - service: camera.record
    data:
      filename: /media/tmp/ring/ring_motion.mp4
      duration: 30
    target:
      entity_id: camera.ring_voordeur
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: telegram_bot.send_video
    data:
      file: /media/tmp/ring/ring_motion.mp4
      caption: Beweging bij de voordeur!
  - stop: Einde automatisering.
mode: single

So it's is triggered by the ring motion sensor over MQTT. It then records 30 secs of footage and saves it locally in a tmp folder. The Telegram bot is sending that file to my bot which I receive the video from.

Everytime the automation runs the tmp video file is being overwritten.

Stefan300381 commented 1 year ago

@0546timm thanks, I assume this is related to HA. I thought you can provide the final command that connects to ring-mqtt to record the stream. Today I use ffmpeg for the same, but I'm facing some resolution (video stretched) and frame corruption issues. Nevermind, thanks.

tsightler commented 1 year ago

Released 5.4.0 which moves to the released version of ring-client-api with the required updates so closing this now.

snigehere commented 1 year ago

Unfortunately its not solved the issue ... I have just installed 5.4.0, left it for 20 minutes the walked in front of one of my cameras and so motion detection via mqtt ..... Do you want me to open a new ticket or continue with this one?

Snap14

Picture shows the motion timestamp via mqtt vs motion timestamp from the native ring integration as a point of comparison

I have extracted the log from the add on (docker logs addon_03cabcc9_ring_mqtt 2>&1 | gzip > ring-mqtt.log.gz) and don't see any error - happy to share that privately with you but don't want to post on here as it covers all my ring kit.

No errors reported in the system log

I do have one camera that the integration can't get a snapshot from because its disabled in home mode - I mention this for info but do not expect it to cause an issue

The log indicated that the integration continues to receive some topic updates including snapshot updates

I have checked in mqtt explorer (started post the issue) and still see some topics are receiving updates but the list of topics is constrained

Snap15

Normally I would expect to see updates from the following topics (picture taken post a second restart)

Snap16

tsightler commented 1 year ago

@snigehere You didn't describe at all if you've followed the troubleshooting steps to re-enable notifications. Simply upgrading won't solve the problem if you haven't taken these steps, you must delete old device entries in Ring Control Center, restart ring-mqtt and re-authenticate.

Also, comparing ring-mqtt to native integration will never be 100% the same since ring-mqtt depends on notifications and native Ring integration does not. If you use any settings that suppress notifications (smart alerts as just one example) then they will impact ring-mqtt but not native integration.

tsightler commented 1 year ago

@snigehere Also, your screenshots from MQTT Explorer look totally normal. When you restart ring-mqtt the state for all topics is sent every 30 seconds for 3 minutes, but, after that, most topics are only updated when there are changes so the topics won't appear in the MQTT Explorer UI until there is a state change for those topics.

The three topics that do show, info, wireless and event_select, all get scheduled updates. The "info" and "wireless" topics get scheduled updates every 5 minutes, while the event_select topic is updated any time an event URL needs to be refreshed, either due to a new event, or due to the old URL expiring (links to URLs expire typically at least every 10 minutes).

snigehere commented 1 year ago

I have cleared out devices in the ring control centre a few times based on the various tickets I have been following. I have switched from addon to dev and back again along the way as well I have not done it ahead of installing this version so will do it once more. In the past it's solved the issue for a short time but then failed again. I am unsure how a failure in the session would allow some topics to carry on working and other topics to stop... I would have expected all topics for all devices would stop but I am not familiar with the infrastructure so have to accept that is how it works.

I have used your integration since first installing ha.. when I first started mqtt was far more reliable at picking the last motion time correctly.. since then its switched over so the native ring is better. I don't expect the time to always match because there are differences in the way the timestamp is reported.

Whilst I accept that sometimes the timestamp will not match, and that maybe some setting on one camera could impact one camera, i am certain that the settings on my cameras don't change without me making that change, and that a setting on one camera will not cause my 4 other cameras to drop subscriptions to multiple topics. I am therefore confident that comparing timestamps is a valid way to check if the integration is working as expected.

To cope with this issue all of my integrations that work off off movement detection from the cameras (mostly to turn lights on) look at the timestamp from both mqtt and the native integration to try and make sure they work.

snigehere commented 1 year ago

I am familiar how mqtt works ....what you describe is after all the whole point of mqtt. I should have made clear that the screen shot was after an hour of continious monitoring and so I should have seen the other topics update within that timeframe.

tsightler commented 1 year ago

@snigehere Sorry, but there is no way that first screenshot is from an hour continuous monitoring, I'd predict maybe 10-15 minutes at most. Regardless, no need to debate about it, you state you have the logs so just send them over as they offer all the data required.

snigehere commented 1 year ago

You are right - the snapshot I took was not an hour through monitoring but nothing changed after that snapshot and sometime later I restarted the integration... again today I left it for over 2 hours and it was just the same

Snap20

I have sent some logs over by email to your gmail account