Skip to content

Automation

Zubir Jamal edited this page Jan 24, 2025 · 3 revisions

For real-time response to detections, always use the event trigger. The integration fires the frigate_gemini_analysis_complete event that you should use in your automations.

Available Event Data

The frigate_gemini_analysis_complete event provides these fields:

  • camera: Camera name
  • event_id: Frigate event ID
  • label: Detected object type (e.g., person, car)
  • confidence: Confidence as percentage string (e.g., "82.4%")
  • confidence_raw: Raw confidence value (0.0 to 1.0)
  • analysis: The full Gemini analysis text
  • detection_time: Event detection time in ISO format

You can use any of these fields in your automation's message template.

TTS Service Options

Common TTS services you can use:

  • tts.google_translate_say: Free Google Translate TTS
  • tts.cloud_say: Cloud TTS providers
  • tts.amazon_polly_say: Amazon Polly TTS

Replace tts.cloud_say in the examples with your preferred TTS service.

Event Details

The event contains all necessary data for automations:

event_type: frigate_gemini_analysis_complete
data:
  camera: "front_door"        # Camera name
  label: "person"            # Detected object type
  event_id: "1234567890"     # Frigate event ID
  analysis: "Full analysis text..."  # Complete Gemini analysis
  confidence: 0.965          # Confidence score (0-1)

Example Automations

  1. Real-time Person Detection Alert
automation:
  alias: "Alert on Person Detection"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  condition:
    - condition: template
      value_template: >
        {{ trigger.event.data.label == 'person' and 
           trigger.event.data.confidence > 0.90 }}
    # Optionally use sensor attributes in conditions
    - condition: template
      value_template: >
        {% set last_alert = states('input_datetime.last_person_alert') %}
        {% set minutes_since = ((now() - last_alert) | as_timestamp / 60) | int %}
        {{ minutes_since > 5 }}
  action:
    - service: notify.mobile_app
      data:
        title: "Person Detected"
        message: "{{ trigger.event.data.analysis }}"
    # Update last alert time
    - service: input_datetime.set_datetime
      target:
        entity_id: input_datetime.last_person_alert
      data:
        timestamp: "{{ now().timestamp() | int }}"
  1. Event Logging with Sensor Reference
automation:
  alias: "Log High Confidence Detections"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  condition:
    - condition: template
      value_template: "{{ trigger.event.data.confidence > 0.95 }}"
  action:
    - service: local_file.write
      data:
        path: "/config/frigate_analysis.log"
        append: true
        content: |
          Camera: {{ trigger.event.data.camera }}
          Time: {{ now().strftime('%Y-%m-%d %H:%M:%S') }}
          Event: {{ trigger.event.data.event_id }}
          Analysis: {{ trigger.event.data.analysis }}
          Current Sensor State: {{ states('sensor.frigem_' + trigger.event.data.camera) }}
          ---
  1. Night Time Security
automation:
  alias: "Night Time Detection"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  condition:
    - condition: time
      after: '22:00:00'
      before: '06:00:00'
    - condition: template
      value_template: "{{ trigger.event.data.confidence > 0.85 }}"
  action:
    - service: light.turn_on
      target:
        entity_id: light.outdoor_lights
    - service: notify.mobile_app
      data:
        title: "Night Time Activity"
        message: "{{ trigger.event.data.analysis }}"
        data:
          push:
            sound: 
              name: default
              critical: 1
              volume: 1.0

These automations demonstrate:

  • Using events for real-time triggers
  • Combining event data with sensor attributes in conditions
  • Integration with other Home Assistant services
  • Proper timing and state tracking
  • Advanced notification options

Text-to-Speech Announcements

The integration fires a frigate_gemini_analysis_complete event that you can use with TTS services to announce detections. Here are some examples:

Basic Announcement

automation:
  alias: "Announce Gemini Analysis"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  action:
    - service: tts.cloud_say  # Replace with your TTS service (e.g., tts.google_translate_say)
      data:
        entity_id: media_player.living_room_speaker  # Replace with your media player
        message: "{{ trigger.event.data.analysis }}"

Smart Announcement with Confidence Check

automation:
  alias: "Smart Detection Announcement"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  condition:
    - condition: template
      value_template: "{{ trigger.event.data.confidence_raw > 0.8 }}"  # 80% confidence threshold
    - condition: time
      after: "08:00:00"
      before: "22:00:00"
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.living_room_speaker
        message: >-
          {{ trigger.event.data.camera | replace("_", " ") }} camera: 
          {{ trigger.event.data.analysis }}

Person-Only Announcements

automation:
  alias: "Announce Person Detection"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
    event_data:
      label: person
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.living_room_speaker
        message: >-
          Person detected at {{ trigger.event.data.camera | replace("_", " ") }} camera. 
          {{ trigger.event.data.analysis }}

Custom Message Format

automation:
  alias: "Detailed Detection Announcement"
  trigger:
    platform: event
    event_type: frigate_gemini_analysis_complete
  variables:
    confidence_pct: "{{ (trigger.event.data.confidence_raw * 100) | round(1) }}"
  condition:
    - condition: template
      value_template: "{{ trigger.event.data.confidence_raw > 0.6 }}"
  action:
    - service: tts.cloud_say
      data:
        entity_id: media_player.living_room_speaker
        message: >-
          {% set camera = trigger.event.data.camera | replace("_", " ") %}
          {% if confidence_pct > 90 %}
            High confidence detection at {{ camera }} camera: 
          {% else %}
            Possible detection at {{ camera }} camera: 
          {% endif %}
          {{ trigger.event.data.analysis }}

Clone this wiki locally