ESP32 Cam / ESP Home / Frigate

I have been going back and forth on a few topics trying to find the right settings to enable an ESP32 cam to stream to Frigate so I thought I would summarise my findings here. It’s a very basic camera but I wanted to play around before my proper security cameras arrive from Amazon. To my surprise the detection even on a low res video is quite good for alerts - will think of where I could use this project as I initially thought it to be a throw away…

My setup involves a HAOS on a Proxmox VM and a Frigate Docker image running on a Proxmox LXC container. I then have the Frigate NVR Proxy add on within HA. I’m passing through a Google Coral to enable object detection through to the Frigate container - yes I know, I finally found stock in Berrybase in Germany…

On the ESP32 cam module I’m running ESP Home firmware:

esphome:
  name: esp32-camera

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ESP32 Camera Fallback AP"
    password: !secret esphome_password

captive_portal:

# Example configuration entry
esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32

  # Image settings
  name: ESP32 Camera
  icon: mdi:camera
  idle_framerate: 1 fps
  max_framerate: 15 fps
  resolution: 800x600
  jpeg_quality: 20
  vertical_flip: true

#Stream
esp32_camera_web_server:
- port: 8080
  mode: stream

# Flashlight
output:
  - platform: ledc
    pin: GPIO4
    id: gpio_4
    channel: 2
light:
  - platform: binary
    output: gpio_4
    name: ESP32 Camera Light
switch:
  - platform: restart
    name: "ESP32 Camera Restart"

sensor:
  - platform: uptime
    name: "ESP32 Camera Uptime Sensor"
    
  - platform: wifi_signal
    name: "ESP32 Camera WiFi Signal"
    update_interval: 60s

It is using two components from ESP Home:

Here are my settings within my Frigate config:

cameras:
  esp32_camera:
    snapshots:
      enabled: true
    ffmpeg:
      inputs:
        - path: http://192.168.20.125:8080
          roles:
            - detect
            - record
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -c:v mjpeg
      output_args:
        record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
        rtmp: -c:v libx264 -an -f flv
    rtmp:
      enabled: false
    detect:
      width: 800
      height: 600
      fps: 3
    record:
      enabled: true
      retain_days: 0
      events:
        retain:
          default: 5

The camera can do higher quality but it just bogs down and usually crashes. It’s a balancing act!

I hope this helps someone else out there. I’m grateful to all those people have contributed to the community!

14 Likes

Have you updated your configuration since frigate now uses go2rtc? I am making progress there, but it is not yet stable. Maybe your tweaks translate?

That is not a ‘must’ …benefit (for me) with go2rtc is that I can have multiple end-use from the cam without issues over rtsp direct to cam.
What is not stable?

Yeah, that is why i use go2rtc, too. The streaming to frigate is unstable, including to go2rtc. I am not yet familiar enoigh with the frigate setup to know how your settings are modified for the new use of go2rtc. i was hoping to learn from seeing if you did that. No worries if you have kept this configuration. It is possible that my esp32 cam connection is the caise of the instabiloty. i need to do more debugging.

I’ve not made any configuration changes to my setup despite upgrading Frigate a few times. Still works well and I receive notifications based on people walking through the detection zone.

Hi

I am trying your setup. I am running frigate in docker on a Synology nas. I have them same esp32 cam set up as you in Home Assistant.

My frigate config is

cameras:

  kamera2:
    snapshots:
      enabled: true
    ffmpeg:
      inputs:
        - path: http://10.17.17.239:8080
          roles:
            - detect
            - record
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -c:v mjpeg
      output_args:
        record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
        rtmp: -c:v libx264 -an -f flv
    rtmp:
      enabled: false
    detect:
      width: 800
      height: 600
      fps: 3
    record:
      enabled: true
      retain_days: 0
      events:
        retain:
          default: 5



but I can´t start my frigate.
I get this error

 s6-rc: info: service nginx successfully started

s6-rc: info: service legacy-services: starting

2023-09-01 19:52:18.448480633  [INFO] Starting NGINX...

2023-09-01 19:52:18.455846616  [INFO] Preparing go2rtc config...

2023-09-01 19:52:18.471353122  [INFO] Starting Frigate...

s6-rc: info: service legacy-services successfully started

2023-09-01 19:52:18.949695731  [INFO] Starting go2rtc...

2023-09-01 19:52:19.115608882  19:52:19.115 INF go2rtc version 1.6.2 linux/amd64

2023-09-01 19:52:19.116123538  19:52:19.116 INF [api] listen addr=0.0.0.0:1984

2023-09-01 19:52:19.116999360  19:52:19.116 INF [rtsp] listen addr=0.0.0.0:8554

2023-09-01 19:52:19.117785654  19:52:19.117 INF [webrtc] listen addr=0.0.0.0:8555/tcp

2023-09-01 19:52:19.119127189  19:52:19.119 INF [srtp] listen addr=0.0.0.0:8443

2023-09-01 19:52:21.662604842  [2023-09-01 19:52:21] frigate.app                    INFO    : Starting Frigate (0.13.0-6801981)

2023-09-01 19:52:21.681524375  *************************************************************

2023-09-01 19:52:21.681930439  *************************************************************

2023-09-01 19:52:21.681989564  ***    Your config file is not valid!                     ***

2023-09-01 19:52:21.682028118  ***    Please check the docs at                           ***

2023-09-01 19:52:21.682075603  ***    https://docs.frigate.video/configuration/index     ***

2023-09-01 19:52:21.682132156  *************************************************************

2023-09-01 19:52:21.682167289  *************************************************************

2023-09-01 19:52:21.682221732  ***    Config Validation Errors                           ***

2023-09-01 19:52:21.682258899  *************************************************************

2023-09-01 19:52:21.682521767  1 validation error for FrigateConfig

2023-09-01 19:52:21.682525004  cameras -> kamera2 -> record -> retain_days

2023-09-01 19:52:21.683121311    extra fields not permitted (type=value_error.extra)

2023-09-01 19:52:21.684749068  Traceback (most recent call last):

2023-09-01 19:52:21.684756489    File "/opt/frigate/frigate/app.py", line 564, in start

2023-09-01 19:52:21.684773147      self.init_config()

2023-09-01 19:52:21.684776741    File "/opt/frigate/frigate/app.py", line 108, in init_config

2023-09-01 19:52:21.684779123      user_config = FrigateConfig.parse_file(config_file)

2023-09-01 19:52:21.684781398    File "/opt/frigate/frigate/config.py", line 1228, in parse_file

2023-09-01 19:52:21.684799586      return cls.parse_obj(config)

2023-09-01 19:52:21.684801779    File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj

2023-09-01 19:52:21.684804429    File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__

2023-09-01 19:52:21.684806468  pydantic.error_wrappers.ValidationError: 1 validation error for FrigateConfig

2023-09-01 19:52:21.684808421  cameras -> kamera2 -> record -> retain_days

2023-09-01 19:52:21.684810243    extra fields not permitted (type=value_error.extra)

2023-09-01 19:52:21.685778234  

2023-09-01 19:52:21.685859242  *************************************************************

2023-09-01 19:52:21.686061661  ***    End Config Validation Errors                       ***

2023-09-01 19:52:21.686112366  *************************************************************

2023-09-01 19:52:22.429902233  2023/09/01 19:52:22 [error] 137#137: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET /api/stats HTTP/1.1", upstream: "http://127.0.0.1:5001/stats", host: "10.17.17.17:5010"

2023-09-01 19:52:22.430014375  172.17.0.1 - - [01/Sep/2023:19:52:22 +0000] "GET /api/stats HTTP/1.1" 502 157 "-" "HomeAssistant/2023.8.3 aiohttp/3.8.5 Python/3.11" "-"

2023-09-01 19:52:23.116812927  [INFO] Service Frigate exited with code 1 (by signal 0)

s6-rc: info: service legacy-services: stopping

s6-rc: info: service legacy-services successfully stopped

s6-rc: info: service nginx: stopping

s6-rc: info: service go2rtc-healthcheck: stopping

2023-09-01 19:52:23.135128685  [INFO] The go2rtc-healthcheck service exited with code 256 (by signal 15)

s6-rc: info: service go2rtc-healthcheck successfully stopped

2023-09-01 19:52:23.150057718  [INFO] Service NGINX exited with code 0 (by signal 0)

s6-rc: info: service nginx successfully stopped

s6-rc: info: service nginx-log: stopping

s6-rc: info: service frigate: stopping

s6-rc: info: service frigate successfully stopped

s6-rc: info: service go2rtc: stopping

s6-rc: info: service frigate-log: stopping

s6-rc: info: service nginx-log successfully stopped

2023-09-01 19:52:23.160304947  exit with signal: terminated

s6-rc: info: service frigate-log successfully stopped

2023-09-01 19:52:23.167952631  [INFO] The go2rtc service exited with code 0 (by signal 0)

s6-rc: info: service go2rtc successfully stopped

s6-rc: info: service go2rtc-log: stopping

s6-rc: info: service go2rtc-log successfully stopped

s6-rc: info: service log-prepare: stopping

s6-rc: info: service s6rc-fdholder: stopping

s6-rc: info: service s6rc-fdholder successfully stopped

s6-rc: info: service log-prepare successfully stopped

s6-rc: info: service legacy-cont-init: stopping

s6-rc: info: service legacy-cont-init successfully stopped

s6-rc: info: service fix-attrs: stopping

s6-rc: info: service fix-attrs successfully stopped

s6-rc: info: service s6rc-oneshot-runner: stopping

s6-rc: info: service s6rc-oneshot-runner successfully stopped

If I have this setup, the picture comes and goes.
When it is a picture (just a few frames /secund), it is very delay.

  kamera2:
    snapshots:
      enabled: true
    ffmpeg:
      inputs:
        - path: http://10.17.17.239:8080
          roles:
            - detect
            - record
      input_args: -avoid_negative_ts make_zero -fflags nobuffer -flags low_delay -strict experimental -fflags +genpts+discardcorrupt -use_wallclock_as_timestamps 1 -c:v mjpeg
      output_args:
        record: -f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 -strftime 1 -c:v libx264 -an
        rtmp: -c:v libx264 -an -f flv
    rtmp:
      enabled: false
    detect:
      width: 800
      height: 600
      fps: 3
#    record:
#      enabled: true
#      retain_days: 0
#      events:
#        retain:
#          default: 5

On the overview frigate cameras
No frame have been received, check error log

log

2023-09-01 19:58:18.405724558  [INFO] Preparing Frigate...
2023-09-01 19:58:18.444797210  [INFO] Starting Frigate...
2023-09-01 19:58:21.640960775  [2023-09-01 19:58:21] frigate.app                    INFO    : Starting Frigate (0.13.0-6801981)
2023-09-01 19:58:21.703655335  [2023-09-01 19:58:21] peewee_migrate.logs            INFO    : Starting migrations
2023-09-01 19:58:21.713839747  [2023-09-01 19:58:21] peewee_migrate.logs            INFO    : There is nothing to migrate
2023-09-01 19:58:21.911033476  [2023-09-01 19:58:21] frigate.app                    INFO    : Recording process started: 223
2023-09-01 19:58:21.916387783  [2023-09-01 19:58:21] frigate.app                    INFO    : go2rtc process pid: 100
2023-09-01 19:58:21.967923079  [2023-09-01 19:58:21] frigate.app                    INFO    : Output process started: 234
2023-09-01 19:58:21.989446898  [2023-09-01 19:58:21] detector.cpu                   INFO    : Starting detection process: 233
2023-09-01 19:58:21.990147173  [2023-09-01 19:58:21] frigate.detectors              WARNING : CPU detectors are not recommended and should only be used for testing or for trial purposes.
2023-09-01 19:58:21.997940084  [2023-09-01 19:58:21] frigate.app                    INFO    : Camera processor started for hallen: 238
2023-09-01 19:58:22.009930684  [2023-09-01 19:58:22] frigate.app                    INFO    : Camera processor started for kamera2: 240
2023-09-01 19:58:22.024535026  [2023-09-01 19:58:22] frigate.app                    INFO    : Capture process started for hallen: 242
2023-09-01 19:58:22.032814735  [2023-09-01 19:58:22] frigate.app                    INFO    : Capture process started for kamera2: 243

Hi @Andreas11

It looks like the configuration has changed: Configuration File | Frigate - namely where the retain is referenced and named.

record:
  # Optional: Enable recording (default: shown below)
  # WARNING: If recording is disabled in the config, turning it on via
  #          the UI or MQTT later will have no effect.
  enabled: False
  # Optional: Number of minutes to wait between cleanup runs (default: shown below)
  # This can be used to reduce the frequency of deleting recording segments from disk if you want to minimize i/o
  expire_interval: 60
  # Optional: Retention settings for recording
  retain:
    # Optional: Number of days to retain recordings regardless of events (default: shown below)
    # NOTE: This should be set to 0 and retention should be defined in events section below
    #       if you only want to retain recordings of events.
    days: 0
    # Optional: Mode for retention. Available options are: all, motion, and active_objects
    #   all - save all recording segments regardless of activity
    #   motion - save all recordings segments with any detected motion
    #   active_objects - save all recording segments with active/moving objects
    # NOTE: this mode only applies when the days setting above is greater than 0
    mode: all
  # Optional: Event recording settings

Hope that helps a little in getting it to work.

@BlackCatPeanut this is awesome! I’ve been looking at M5Stack devices including their cams. Which ESP Camera are you using for this setup?

@sdpopplewell - this looks to be the same one - I bought them off Aliexpress if I remember correctly: ESP32-CAM Video Streaming and Face Recognition with Arduino IDE | Random Nerd Tutorials