Frigate notification when object is moving from one zone to other zone?

Hi folks,
I just started with Frigate and integrated it into my HA, so far, it works perfectly.
I also use the automation blueprint form Frigate for notifications, which basically also works, but I do get too much notifications.
I have a cam at my driveway, which is divided into 3 zones: street-facing, middle and frontdoor-facing.
I want a notification if an object is moving from the middle into the frontdoor zone, but not vice-versa (i.e. if I’m levaing the house (frontdoor → middle), I don’t need a push message). If someone not only wakling by the street, rather than entering my driveway and coming to my door/house, I want a push.

I’m sure that is possible, but I couldn’t find out how.
I see the MQTT messages from Frigate, but I couldn’t find any docs, explaining the difference between “before” and “after” section in the JSON. I saw some examples in the internet around, one was using after, one was using befor, but no really sense for me.

Can someone point me in the right directen?

Thanks!!

2 Likes

Before is just the message before the current one that has been sent (which is after). It’s also worth noting that the zones listed in entered_zones are chronological

ok, in that case, I would actually look for the after part in the JSON.
What is the difference between current_zones and entered_zones? I assume current is the one, the object is right now (correlating with the after part) and entered_zones is the histroy?

In my case:
In the before part the object would need to entered_zones == street and middle
And in the after part the current_zone == door
?

Sounds right to me

@oggy512 will you lmk if you get this working? i’ve struggled to get this working in an automation myself, and it feels like it should be pretty straightforward to do :man_shrugging:

Think I may finally have a working example of this. I’ve only briefly tested this so far, and my use case isnt exactly like yours b/c i only have 2 zones (near/far), but this tracks a person walking from mudroom_far into mudroom_near and logs the output (as an error so its easy to see it happening real time).

- alias: "Frigate: Track Object in Zones"
  id: "Frigate: Track Object in Zones"
  trigger:
    - platform: mqtt
      topic: frigate/events
      id: frigate-event
      payload: mudroom
      value_template: '{{ value_json["after"]["camera"] }}'
      variables:
        after_zones: "{{ trigger.payload_json['after']['entered_zones'] }}"
        label: "{{ trigger.payload_json['after']['label'] }}"
  condition:
    - "{{ label == 'person' }}"
    - "{{ 'mudroom_far' in after_zones }}"
  action:
    - service: system_log.write
      data_template:
        message: "LOGGING: first zone"
        level: error
    - wait_for_trigger:
        - platform: mqtt
          topic: frigate/events
          value_template: "{{ 'mudroom_near' in wait.trigger.payload_json['after']['current_zones'] }}"
      timeout: "00:00:45"
      continue_on_timeout: false
    - service: system_log.write
      data_template:
        message: "LOGGING: second zone"
        level: error
    - delay: 15

Here’s where I’ve landed on this, it’s been working really well for the past ~6days. This uses go2rtc to record a 10s clip once the object moves into the “far away” zone, then, if that object hits the “near zone”, it sends the clip as a notification via telegram.