blakeblackshear / frigate

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

Toggle 'detect' status via HTTP API #8877

Open jangrewe opened 11 months ago

jangrewe commented 11 months ago

First off, THANK YOU for creating Frigate! I've been using Shinobi/Zoneminder/etc. for many years, but they've all been a very painful experience (coming from a professional Sysadmin, that means something). I got Frigate up & running in a Docker container with TensorRT and all the bells & whistles in less than half an hour, and i never want to switch back to anything else. ♥️

Now regarding the actual feature request:

Describe what you are trying to accomplish and why in non technical terms I want to be able to toggle the 'detect' status via the HTTP API, so that I can easily switch it on and off via my home automation. Otherwise it would record me all the time i'm moving through my flat, instead of just when i'm not at home.

I see that this is possible via the Websocket, but: that's a bit more complicated to use than a simple HTTP call.

Describe the solution you'd like A new HTTP API endpoint like POST /api/<camera_name>/detect, similar to the Websocket, e.g. with

{"payload": "OFF"}

Describe alternatives you've considered A very complicated cURL command to emulate a Websocket client. Not fun, and also not very reusable.

Additional context

NickM-27 commented 11 months ago

what home automation platform are you using? these should support mqtt which can be used for this, otherwise I believe that websocket should suffice.

jangrewe commented 11 months ago

Ironically ESPHome without Home Assistant. I can send simple HTTP requests from my MCUs, but implementing Websockets there would be at least a major PITA, if possible at all. Also no MQTT implemented.

I'm not great at Python and/or knowing the internals of Frigate, but when looking at frigate/http.py it doesn't look too complicated to add another endpoint to accomplish this? 😉

NickM-27 commented 11 months ago

I'm not great at Python and/or knowing the internals of Frigate, but when looking at frigate/http.py it doesn't look too complicated to add another endpoint to accomplish this? 😉

it is likely much more complicated than you may think given that there is a lot of logic to determine when a setting can be enabled / disabled and we must set it so that the change is seen across the many different processes that frigate is using.

Certainly doable but would require a considerable overhaul to ensure it is not a major amount of effort to maintain. we can see what @blakeblackshear thinks

blakeblackshear commented 11 months ago

What if we just leveraged the new inter_process bus and only published a message in the http api?

NickM-27 commented 11 months ago

that could be done, only concern is we wouldn't be able to send an error back to the user if it failed like in the case of recordings being disabled in config or others

kabadisha commented 10 months ago

I'd like to add my support for this feature. I have a bash script that runs on my router that detects if my phone is connected. If it is, I would like to disable detection so that I'm not recording myself all day.

Eierkopp commented 9 months ago

...so that I'm not recording myself all day.

Same here. I'm using Python aiohttp for that purpose.

    async def disable_detection(self, cam):
        async with aiohttp.ClientSession(auth=AUTH) as session:
            async with session.ws_connect(f"https://{FRIGATE_HOST}:{FRIGATE_PORT}/ws") as ws:
                await ws.send_json({"topic": f"{cam}/detect/set", "payload": "OFF", "retain": True})
MaBeniu commented 9 months ago

After getting sorted main config paramos now started to think of such feature as well. Some configurations control from HA would be perfect. Especially detection of objects. While family is at home it doesn't make sense to track people on weekends during day time. While at night it still might be relevant for case if intruders get there. So such change based on time would be easy to define in HA on top of it to combine with families presence at home. Shortly I see lots of value with this. 🙂 Changing tracked objects list from HA could be other alternative as a workaround, just a thought.

NickM-27 commented 9 months ago

Some configurations control from HA would be perfect

there is already a lot of control over the config and interactions with frigate in HA via the HA integration

MaBeniu commented 9 months ago

Accept my apology 🙏 Indeed found those, tons of options. Brilliant

kabadisha commented 8 months ago

I ended up working around this limitation by spending all weekend fiddling with HomeAssistant integration with Frigate and my Router. I now have an automation set up to disable detection when my router can see my phone has connected.

While I now have a more configurable, powerful automation handling this, I still think this Frigate feature request is sensible:

As such, my vote for this feature stands.

NickM-27 commented 8 months ago

To be clear, nothing about home assistant is required. Mqtt is supported by node red and other tools.

The recent changes in architecture will make this easy to implement

github-actions[bot] commented 7 months 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.