blakeblackshear / frigate

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

Dynamic zones based on time / camera preset #3621

Open smol84 opened 1 year ago

smol84 commented 1 year ago

I live on a busy road with parking on the street. I want to be able to set my object detection and recording based on time of day.

THe reason is that I want to track people late at night to capture anyone tampering with my car, house etc. But during the day, I am less bothered, it's a fairly busy street and setting object detection when I don't need it ends up with my HDD maxing out when recording these events.

Is there a way to enable a zone to have object detection at a specific time of day?

A solution I have considered is having a cron job that replaced the config.yml file every morning and night. E.g. I have 3x config files - config_day.yml, config_night.yml and config.yml At the day time the config_day.yml is copied to replace the normal config.yml file. At night the inverse would happen.

However, this would mean having to restart frigate each time, which is rather inelegant. Is there a better way?

NickM-27 commented 1 year ago

Toggling detection, recording, and snapshots is already supported with the MQTT API.

Do people frequently walk into your driveway, by your car, etc? I believe a zone should be enough for this unless the zone is not setup properly and catching people walking by when you don't want it to

smol84 commented 1 year ago

So I have a small courtyeard, approx 2m from door to the footpath. It is very busy so I get hundreds of motion triggers a day.

Setting a zone would be the correct way to only record in my courtyard for example, removing the zone at night would then allow me to monitor the rest of the street and my car.

In the MQTT API I can only see topics to turn record on/off (which is not what I want). I can't see anything that the turns the zone on/off https://docs.frigate.video/integrations/mqtt/ Am I missing something?

NickM-27 commented 1 year ago

I see, that's not currently supported with frigate today

smol84 commented 1 year ago

Would a cron job to rotate the config.yml files be the best solution in this scenario? Can a cron then trigger a restart of frigate?

Or is there a more elegant option?

NickM-27 commented 1 year ago

As far as currently available, yeah that's probably the best solution. and yes just need the cron job to do something like docker restart frigate

smol84 commented 1 year ago

Posting my current working solution in case others want to replicate

use command crontab -e to edit your cron table, add the following commands: 0 6 * * * /home/scripts/frigate_day.sh 2 2 * * * /home/scripts/frigate_night.sh

This will run scripts at 6am and 10pm each day

Script frigate_day.sh: #! /bin/sh cp -f /home/frigate/config_day.yml /home/frigate/config.yml docker restart frigate

Script frigate_night.sh: #! /bin/sh cp -f /home/frigate/config_night.yml /home/frigate/config.yml docker restart frigate

For this to work you need 3 config.yml files:

  1. config.yml - the file in use by frigate at all times
  2. config_night.yml - the file containing the settings you want at night
  3. config_day.yml - the file containing the settings you want at the day time

The cron job will then execute at the set times every day, copying the files to use and restarting frigate.

Mincka commented 1 year ago

Also interested by this but more generic: be able to enable / disable any masks using API / MQTT.

In my case, I would like to enable a mask when the laundry is hung in the garden because it will trigger a lot of false positive detections. So the idea would be to use a boolean in HA to enable / disable the mask. It would require to be able to set ID to masks in Frigate + enable / disable state, so lot of work. :-/

In the meantime, I will try the scripting method with bash scripts in HA. :) Thank you for sharing @smol84 !

gtxaspec commented 1 year ago

Adding a time-based zone feature to Frigate NVR is a brilliant idea. It's a simple tweak, but it can make the system a lot smarter and user-friendly.

Users will love having more control, and it could even make the system more efficient for big setups. We all stand to benefit from this feature, so let's hope the team can make it happen soon!

nwish commented 10 months ago

I just popped in here to express interest in dynamic zones as well. My use case is that I have a PTZ camera that tours every so often and I’d want to be able to set “views” of zones and masks for each camera position.

For example, Position 1 views the front door while position 2 views the patio slider. I do trigger these views based on door sensor activity as well. If I can disable Frigate view 1 and enable 2 as the camera moves to position 2, that would be pretty neat.

nlejeune commented 9 months ago

I'm also very interrested to be able to enable object detection and recording based on a schedule. The ultimate goal would be :

Zone 1 : Detect Always : person Detect only during night : car Zone 2 : Detect only during night : person

(I simplify, it would be based on schedule :D and I don't use HASS)

edouardaihua commented 3 months ago

Interested as well, using a PTZ cam as a baby camera, recording bed at night and playground during the day. I'd like to set a zone to detect when baby get ouf of bed.

robby-d commented 3 months ago

Interested as well. Similar to a previous poster, I am doing some PTZ autotracking and it would be good to dynamically apply zones and object masks based on the PTZ camera's position. Most simply, this would mean disabling object masks and zones if the PTZ camera was on anything but the default (parked) preset position. Preset position could be read through the Frigate PTZ service or the HA ONVIF service.

tamueller commented 2 months ago

I'd like to have this feature as well - especially since both of my PTZ positions have things that get a 85% false positive for person, and if I mask both false positives I loose a lot of visibility for persons in the respective other PTZ position. Since this is a bit of an advanced feature, I would be totally fine if it does not have a working UI and does not work directly with the mask editor in the debug view - just setting a mask via MQTT would be enough.

MrDrew514 commented 1 month ago

Toggling specific zones just like detect/record would be an amazing feature, it would open so many options for automations via Home Assistant. We would really appreciate if you could take this feature into consideration.

FoxxMD commented 1 month ago

Adding another use-case for dynamic zones and/or object masks: I have interior cameras that I track cats (so they need to have detect/record on) but I don't particularly care or want to track/record people when I am at home. It would be useful to be able to disable an object mask for a person, or enable a zone for a person, through the API so that I can toggle these when I leave the house (away mode, essentially).

That way if I'm away frigate will detect and record any people who not supposed to be on those cameras. But if I am at home it ignores people while still recording the other things (cats) I care about.

NickM-27 commented 1 month ago

That's a very roundabout way of doing that. You'd be better of just having specific objects labels be toggle able