blakeblackshear / frigate

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

[Support]: Question about MQTT messages and best practices #2885

Closed Justihar closed 2 years ago

Justihar commented 2 years ago

Describe the problem you are having

I'm pretty new to Frigate so I am trying to understand the behavior of zones, object filtering and how that information comes through in MQTT.

I am running Frigate in a docker container and although I did end up adding the custom component to HA core, I plan on building my automations in AppDaemon using MQTT directly.

I am doing the typical "notification of car entering driveway" type scenario. I don't particularly care to record or take action on vehicles that are passing by on the street but obviously need to start the process of object detection in that area or at least the entrance of the driveway.

What is the recommended way to allow the zone data to be passed through MQTT but ignore recording? It seems like if I use the record/snapshot options with required_zones, I still see MQTT data but the "entered_zones" and "required_zones" data is not passed through.

If I am understanding correctly, I should be able to check for an MQTT event where current_zone=["driveway"] and entered_zones=["driveway_entry", "driveway"] but again, don't want to record a vehicle in the driveway or street.

Is there any documentation that explains some of the expected behaviors of MQTT or perhaps some examples of data to look at for various scenarios?

Any suggestions would be helpful, thank you!

Version

0.10.0-BFECEE9

Frigate config file

front_south:
  ffmpeg:
    inputs:
      - path: REDACTED
        roles:
          - detect
          - rtmp
      - path: REDACTED
        roles:
          - record
  detect:
    width: 640
    height: 480

  best_image_timeout: 5

  motion:
    mask:
      - 467,206,521,328,640,384,640,0,401,0 # FRONT YARD TREE
      - 133,0,138,92,36,118,0,0 # SOUTH NEIGHBOR TREE

  zones:
    entire_frame:
      coordinates: 640,0,640,480,0,480,0,0
      objects:
        - person
        - dog
    driveway_entry:
      coordinates: 473,382,510,313,276,153,192,167
      objects:
        - car
    front_yard:
      coordinates: 539,319,640,401,640,480,0,480,0,225,204,125
      objects:
        - person
        - dog

  record:
    events:
      required_zones:
        - entire_frame
        - driveway_entry
        - front_yard

  snapshots:
    required_zones:
        - entire_frame
        - driveway_entry
        - front_yard

Relevant log output

NA

FFprobe output from your camera

NA

Frigate stats

No response

Operating system

Other Linux

Install method

Docker Compose

Coral version

USB

Network connection

Wired

Camera make and model

Amcrest

Any other information that may be helpful

No response

NickM-27 commented 2 years ago

It seems you understand it well except for that fact that you said using required_zones that the zone data is not passed through. This is not the case, and is exactly how I have my setup working.

One thing to note is that frigate uses zones and masks based on the bottom center of an object's bounding box. So I would double check your zones to make sure it is designed to be triggered when the bottom center of the bounding box is in the zone.

Justihar commented 2 years ago

Let me rephrase, zone data for an ignored zone isn't coming through on MQTT (from what I can tell). So if I tell zone "front_yard" to only identify "person" objects but the vehicle passes through the "driveway_entry" which only watches for car objects but ends up in the "front_yard" zone, I never see "front_yard" show up as an "entered_zones" for car.

Thank you for the note on how the bounding boxes work. I have been looking through the github issues and see that come up quite often and it has helped me in marking zones more adequately.

NickM-27 commented 2 years ago

Okay I see, but why would you want that? If you aren't looking for a car in the front_yard why would you expect the MQTT message to show that a car was in the front_yard?

Justihar commented 2 years ago

My thinking is that I'd want to know because it had to pass through the driveway_entry in order to get in the front_yard. Once that has been established then I don't care to know that it is in the front_yard. Of course I understand that it is the way it is so what would be the best way for me to adapt?

NickM-27 commented 2 years ago

Perhaps I am misunderstanding something. In your case is the "driveway" (where cars go) and the "front yard" the same zone / area?

A picture might be helpful to offer suggestions

Justihar commented 2 years ago

Yes, I had driveway broke into its own zone but I had way too many zones for something that should be pretty simple. So I just made the whole front yard one zone since I only care about people except when a vehicle enters.

Blue zone is "driveway_entry"

image

NickM-27 commented 2 years ago

Okay cool, I have a few ideas of different types.

  1. What were the results when you test as it is now? I believe it should work that when a car comes through and parks in the driveway the event should be created and there will be an MQTT event that shows entered_zones with "driveway_entry" and that would be your trigger to send a notification. I wouldn't think that any cars driving by on the street would enter that zone.
  2. Wouldn't be a clean solution, but you could make it so "front_yard" accepts cars and then add an object mask for car on the bottom-center of the bounding box where they are parked. That way the zone would record them but then they get to their parking place it would stop tracking the car and not be recognized anymore.
  3. I understand it is not as clean, but could also just create the driveway zone inside of the front yard zone so it would just be one more zone than you have right now (and just use it to track cars) which IMO would be the most full-proof way to get what you want working.
blakeblackshear commented 2 years ago

Frigate doesn't have a concept of an "ignored zone" and configuration of required_zones for recordings and snapshots have no effect on the mqtt events topic.

Justihar commented 2 years ago

But the zone -> object options do have an effect on the data being reported over MQTT, correct?

Frigate doesn't have a concept of an "ignored zone" and configuration of required_zones for recordings and snapshots have no effect on the mqtt events topic.

blakeblackshear commented 2 years ago

But the zone -> object options do have an effect on the data being reported over MQTT, correct?

Yes. Only object types listed there can trigger the zone.

Justihar commented 2 years ago

Ok, fair enough, I'll work with that. Thank you @NickM-27 and @blakeblackshear for the help.