dlford / frigate-alerts

Get push notifications for Frigate events
MIT License
0 stars 0 forks source link

Frigate Alerts

Get alerts for Frigate events with snapshots and filters.

This project has been split off from the now deprecated dlford/frigate-slack-alerts, in the future I will be adding support for Gotify, and potentially other platforms down the road for push notifications.

Quick Start (for Slack)

  1. Create a slack channel for alerts (the default channel name is frigate)
  2. Go to the Slack API page and create a new app Screenshot: Create a new App button on Slack API page
  3. Choose to create the app from a manifest Screenshot: Create from manifest button on Slack API page
  4. Paste in the following manifest:
    _metadata:
      major_version: 1
      minor_version: 1
    display_information:
      name: frigate-bot
      description: Frigate alerts bot
      background_color: '#232c34'
    features:
      bot_user:
        display_name: FrigateBot
        always_online: true
      app_home:
        home_tab_enabled: false
        messages_tab_enabled: true
        messages_tab_read_only_enabled: true
    oauth_config:
      scopes:
        bot:
          - app_mentions:read
          - channels:history
          - channels:join
          - channels:manage
          - channels:read
          - chat:write.customize
          - chat:write.public
          - chat:write
          - files:read
          - files:write
          - groups:history
          - groups:read
          - groups:write
          - im:history
          - im:read
          - im:write
          - links:read
          - links:write
          - mpim:history
          - mpim:read
          - mpim:write
          - pins:read
          - pins:write
          - reactions:read
          - reactions:write
          - reminders:read
          - reminders:write
          - team:read
          - usergroups:read
          - usergroups:write
          - users:read
          - users:write
          - users.profile:read
    settings:
      event_subscriptions:
        bot_events:
          - app_mention
      interactivity:
        is_enabled: true
      org_deploy_enabled: false
      socket_mode_enabled: true
  5. Click "Install App" from the menu
  6. After insalling the app to your workspace, you should see the "Bot User OAuth Token" on this page, save that for later. Screenshot: Bot User OAuth Token on Slack API page
  7. In slack, click on the menu for your channel, and add the new app to the channel Screenshot: Adding app to Slack channel
  8. Create a password file for Mosquitto MQTT broker (/data/mqtt/password.txt in this example)
    touch /data/mqtt/password.txt
    # User for frigate
    mosquitto_passwd /data/mqtt/password.txt frigate
    # User for alerts
    mosquitto_passwd /data/mqtt/password.txt alerts
  9. Create a config for Mosquitto MQTT broker (/data/mqtt/config/mosquitto.conf in this example)
    allow_anonymous false
    password_file /mosquitto/config/password.txt
    # MQTT
    listener 1883 0.0.0.0
    protocol mqtt
  10. Add an MQTT broker and this project to your docker-compose file
    version: '3.9'
    services:
      mqtt:
        container_name: mqtt
        restart: unless-stopped
        image: eclipse-mosquitto
        volumes:
          - '/data/mqtt/config/mosquitto.conf:/mosquitto/config/mosquitto.conf'
          - '/data/mqtt/password.txt:/mosquitto/config/password.txt'
      alerts:
        container_name: alerts
        restart: unless-stopped
        image: ghcr.io/dlford/frigate-alerts:latest
        environment:
          FSA_MQTT_BROKER: mqtt
          FSA_MQTT_USER: alerts
          FSA_MQTT_PASSWORD: 'ChangeMe123'
          FSA_FRIGATE_INTERNAL_BASEURL: http://frigate:5000
          FSA_FRIGATE_EXTERNAL_BASEURL: 'https://frigate.yourdomain.com'
          FSA_SLACK_TOKEN: 'Your_Slack_OAuth_API_Token'
          # Right click a channel in Slack and choose "View channel details",
          # the ID will be at the bottom of that pane
          FSA_SLACK_CHANNEL_ID: 'Your_Slack_Channel_ID'
      frigate:
        # ... See https://docs.frigate.video/frigate/installation
  11. Add MQTT settings in your Frigate configuration file
    # See https://docs.frigate.video/configuration/
    mqtt:
      enabled: True
      host: mqtt
      port: 1883
      user: frigate
      password: ChangeMe123

Advanced

Environment Variables

The following environment variables can be added to the environment section of docker-compose.yml:

Filters

You may want to have some events recorded but not send alerts, this is possible with event filters. By default, all event alerts are sent to Slack, but if you add a filters file, only events described in the filters will be sent to Slack.

  1. Create a filters.yml file (/data/alerts.filters.yml in this example)
    # Cameras not included in this list will not be alerted
    cameras:
     - name: camera1
       # Zones not included in this list will not be alerted for this camera
       zones:
         - name: zone1
           # Objects not included in this list will not be alerted for this zone
           objects:
             - person
             - dog
  2. Mount the file as a volume to the alerts container
    version: '3.9'
    services:
     mqtt:
       # ...
     alerts:
       # ...
       volumes:
         - '/data/alerts/filters.yml:/app/filters.yml'
       # ...
  3. Tell the app where to find the filters file with the FSA_FILTER_CONFIG_FILE environment variable
    version: '3.9'
    services:
     mqtt:
       # ...
     alerts:
       # ...
       volumes:
         - '/data/alerts/filters.yml:/app/filters.yml'
       environment:
         FSA_FILTER_CONFIG_FILE: /app/filters.yml
       # ...