Frigate - Open the gate if a car is leaving, or open it if the registration plate is recognised when someone arrives

I am using frigate to monitor my cameras. When a car is found at the gate by frigate (drive cam), I send the image to platerocognizer and then process the image to open the gate. If someone is leaving the (gate cam) opens the gate to let them out.

alias: A car is at the gate
description: >-
  If a car has been seen by the drive camera send the image to platerocogniser. 
  If it was the gate camera then someone is leaving, open the gate
triggers:
  - topic: frigate/events
    value_template: "{{ value_json.type }}"
    trigger: mqtt
conditions:
  - condition: template
    alias: A vehicle has been spotted
    value_template: "{{ trigger.payload_json['after']['label'] == 'car' }}"
actions:
  - if:
      - condition: template
        alias: A car is leaving
        value_template: "{{ trigger.payload_json['after']['camera'] == 'gate' }}"
      - alias: The gate is closed
        type: is_not_open
        condition: device
        device_id: ed70874efa61fe384ae0d8c967d6465a
        entity_id: 85439b641892947743db0778dfbc6d16
        domain: binary_sensor
    then:
      - action: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.open_the_gate
    else:
      - alias: A car has arrived
        action: image_processing.scan
        metadata: {}
        data: {}
        target:
          entity_id: image_processing.platerecognizer_drive_mainstream
        enabled: true
mode: single

1 Like