blakeblackshear / frigate

NVR with realtime local object detection for IP cameras
https://frigate.video
MIT License
18.09k stars 1.65k forks source link

Feature Request: Send MQTT message that camera is offline #1536

Closed hathalud closed 2 years ago

hathalud commented 3 years ago

I have 2 cameras and one of them likes to go offline fairly frequently (Wyze not supporting RTSP with more than the 2 firmware releases they've done is a bummer). It seems obvious to me that Frigate should be able to tell when a stream source is unresponsive and send a MQTT message to Home Assistant that it's offline so that HA can perform whatever automation is created for that situation. In my case, I'd have the switch for that smart plug reset via an automation.

itkfilelor commented 3 years ago

With this use case, I'd caution that it should trigger a timer first, in case the camera is doing an update. In the mean time you should be able to set up a log parser within the frigate container that searches for the "no route to host" message frigate throws when a camera is down and send your own MQTT message.

you could also, have HA or which ever runa ping every so often as well.

hathalud commented 3 years ago

I appreciate the suggestion and good intentions from what I discern to be a fellow user. Please correct me if my deduction there is wrong.

Currently I have the camera rebooted once a day via Wyze's built-in api. That seems to be sufficient at keeping it from hanging again. But you never know when it might happen again despite that precaution. Or if another camera bites the dust in some form or fashion. Depending on the circumstances I'd want to know as soon as possible that the camera had gone offline to either rectify it or make arrangements because of it.

For instance, my Wyze cam is used to watch my front door for packages so that I know when a delivery has been made. (I selected it because of the two cameras I have, it's not PTZ and I didn't want PTZ to be a feature that would cause neighbors to complain to my apt management about privacy concerns.) If I knew that a camera was offline (let's assume worst case scenario, the camera is bricked) then I'd know that I have to manually check my front door if I was expecting packages that day. In an ideal world, I would have an automation setup that would to notify me that the camera was offline, reboot the camera and if it doesn't come back online in a sufficient period of time/number of tries, I would get another notification that it was rebooted and still not back online again.

Side note: I wish there was built in package detection, as that's a large part of why I setup the cameras and Frigate. lol And yes, I know I could train that into the system if I had the time, understanding and means to do so. I'm not that sophisticated and resourceful.

For what it's worth, there's no OTA update for Wyze cameras running the RTSP firmware. Short of a serious flaw, they have no intention of releasing another update for that version of the firmware. In the couple of years that I've had this camera, they have only released two RTSP firmware updates that I had to manually install myself. That's probably a large factor in why this camera's stream seems to freeze so often. Buggy coding but it's not a priority to them to fix since they can't make additional revenue off of the feature and are too focused on other development projects.

Last of all for the benefit of any devs looking at this, a Ping or log check for a No-Route-To-Host wouldn't work as the Wyze camera usually is online, but for whatever reason the RTSP stream has stopped. I've been able to login to the camera via Wyze's app and reboot it from there when this happens. I am not sure how Frigate is able to check that the streams to it are active in general, but I will mention that both of my cameras have the time and date overlaid into the stream. Assuming that a camera might freeze streaming in such a way that it sends the last frame constantly, that should be enough of a change (or lack thereof) over the span of a few seconds to see if the stream has changed any or is frozen. Maybe there could be a feature where instead of a blanket motion mask, there is a time and date mask. Then on one hand Frigate knows to ignore that as part of the motion it's not looking for, but is also a mask to see if the frames have changed at all if otherwise the environment is too static to reflect a change in the stream's greater content.

When I first noticed that the camera stream had frozen I checked my HA logs to see if Frigate had sent any kind of signal for HA to act on and was surprised to not find one. I had assumed that there would be one as it seems both important and obvious to me. At the very least being able to trigger a notification or some other automation that a camera was not streaming anymore is enough of a priority to add by default in addition to the usual motion and object detection triggers sent.

itkfilelor commented 3 years ago

If you are certain there won't be any auto OTA's then the timer is unnecessary. The idea behind it is to prevent a brick if you cut power mid flash. My second suggestion was to implement your own message to HA until the feature could be implemented. =) I haven't done this myself as I am using amcrest cameras and the amcrest integration, as well as the amcrest2mqtt (for the doorbell) docker container have a connection check. I do agree this would be a great feature, as it would allow me to remove the amcrest integration since that's all I use it for atm.

hathalud commented 3 years ago

You could consider running the pre-established integration for Amcrest since it's probably less overhead than an additional docker container. https://www.home-assistant.io/integrations/amcrest/

How would I run my own check to see if the stream is not working when the camera is responding to ping? I'm trying to address a more complicated situation than the standard issue scenario of a device being entirely offline. Typical situation is not what I'm experiencing here. I just installed the Wyze custom integration to see if it had any kind of sanity checks, but it only turns the camera on and off. It doesn't even restart the camera.

itkfilelor commented 3 years ago

Unless they updated it recently it doesn't cover doorbell call events. which is what i am using amcrest2mqtt for. I would happily exchange it =) I am also hoping for them to add the different api endpoints like manual IR on/off and brightness control. and light control ( e.g the floodlight) until then curl commands it is! =)

as far as sanity, you could parse the frigate log for dropped frames. if ffmpeg can connect but isn't getting video it should still chuck an error.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.