Coder Social home page Coder Social logo

frigate_watcher's Introduction

Frigate Watcher

A quick and dirty script to handle No frames have been received, check error logs quick and dirty.

This script checks through the frigate stats if the ffmpeg process is still running. If the consecutive fails hit the treshold has been registered for your camera, this script will reboot frigate. The failure count is recorded at the MQTT topic frigate_watcher/[camrea_name]/failure_count. As soon as the ffmpeg pid of a camera is found in the stats, the counter is set to 0.

After a reboot, ffmpeg processes will spin up to restore the connection with your camera. If, for instance, the camera has been shut down, frigate_watcher will reboot frigate until the power is restored.

This script is not meant to run as a service, it could be a cron job for every x seconds.

frigate_watcher.json

{
    "mqtt": {
        "broker": "", //the address of the mqtt broker
        "port": 1883,
        "username": "", //the username to connect to the broker
        "password": "", //the password to connect to the broker
        "base_topic": "frigate_watcher", //the base topic to report to
        "frigate_base_topic": "frigate" //the base topic of frigate
    },
    "log": {
        "level": "debug", //set the log level
        "copy": { //copy the specified log before restart, it is copied to the folder of the script
            "frigate":true,
            "go2rtc":true,
            "nginx":true
        }
    },
    "frigate_url": "", //the url of frigate
    "failure_count_treshold": 5, //the number of consecutive failures before a reboot is initiated
    "restart": true //define of the reboot should be initiated

Cron

If you want to run this script through cron, use the following configurateion for a job every minute.

* * * * * python3 /path/to/frigate_watcher.py

Home Assistant

Place frigate_watcher.py and frigate_watcher.json in /config/python_scripts/

Sensor

Create a command line sensor that runs every 60 seconds

- platform: command_line
  name: Frigate Command Line
  scan_interval: 60
  command_timeout: 300
  command: python3 /config/python_scripts/frigate_watcher.py

Automation

This automation will notify when a restart is initiated by frigate_watcher. Change the 5 if you have set a different value at failure_count_treshold in frigate_watcher.json

- id: frigate_notifications
  alias: Frigate Notifications
  description: ""
  trigger:
    - platform: mqtt
      topic: frigate_watcher/+/failure_count
      id: frigatewatcher
  action:
    choose:
    - conditions:
      - condition: trigger
        id: frigatewatcher
      sequence:
      - condition: and
        conditions:
        - condition: template
          value_template: >-
            {% if (trigger.payload_json | int) == 5 %} {{ True }}
            {% else %} False
            {% endif %}
      - service: notify.mobile_app_iphone
        data:
          title: "Frigate watcher"
          message: "Frigate will be restared, got {{ trigger.payload_json | string }} failure counts on topic {{ trigger.topic | string }}"

Changelog

2023.5.7.1

  • Added copy log before reboot

2023.5.4.1

  • Initial release

frigate_watcher's People

Contributors

skons avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.