0x2142 / frigate-notify

Event notifications for a standalone Frigate NVR instance
https://frigate-notify.0x2142.com/
MIT License
109 stars 9 forks source link

Required validation failed #156

Closed IxcheI closed 1 month ago

IxcheI commented 1 month ago

Hi, I'm trying to set up notifications for my use case and currently can't even get frigate-notify to run in docker.

This is the ever repeating log:

INF Frigate Notify - v0.3.5
INF Starting...
WRN Config file could not be read, attempting to load config from environment
FTL Failed to load config from environment! error="alerts: required validation failed, frigate: required validation failed"

I'm running frigate through docker and WSL (Ubuntu) on a windows machine with Nvidia GPU. Frigate is running without any issues so I'd hope its not my general setup.

Here is my compose file:

services:
  frigate:
    # frigate stuff
    ports:
      - "8971:8971"
      - "5000:5000"
      - "8554:8554"
      - "8555:8555/tcp"
      - "8555:8555/udp"
  frigate-notify:
    image: ghcr.io/0x2142/frigate-notify:latest
    environment:
      TZ: Etc/UTC
    volumes:
      - C:\Users\USER\frigate\frigate_notify\config.yml:/app/config/config.yml
    restart: unless-stopped

And my notify config:

frigate:
  server: localhost:5000
  webapi:
    enabled: true
    interval: 60
alerts:  
  general:
    title: test
    timeformat: 2006-01-02 15:04:05 -0700 MST
    nosnap: allow
    snap_bbox: true
    snap_timestamp: true
    snap_crop: false
    notify_once: true

The mounting works fine, I can see and open the config within docker. From the error I would assume, the issue is with the contents of my config? Is localhost not an acceptable address? I tried all kinds of addresses and ports, nothing worked. I don't know anything about mqtt, so I haven't use that in frigate.

If you need to know anything else, let me know! Thanks for your help, your work is greatly appreciated.

0x2142 commented 1 month ago

Hello there & thanks for using this app!

So the key here is the log that states WRN Config file could not be read. The default location for the config file is /app/config.yml, or it can be overriden by using the FN_CONFIGFILE environment variable as shown here.

In the config shared, it looks like you're mounting the config to /app/config/config.yml - so my best guess is that the app can't find it. I would suggest either updating the volume map to /app/config.yml, or use the env var if you like!

Edit: I see the docs might be a little confusing on the default file location - I'll make a note to update this to clarify it

IxcheI commented 1 month ago

@0x2142 Hi, thanks for the quick answer. The solution was indeed that simple. The documentation installation page has it correct, I just failed to see my mistake. Maybe there could be a dedicated error for not finding the config.

Now im getting: WRN Cannot reach Frigate server at http://localhost:5000 error="Get \"http://localhost:5000/api/stats\": dial tcp [::1]:5000: connect: connection refused" attempt=1 interval=30 max_tries=5

But I'm already happy seeing a different error. When checking the api/stats in browser, it returns json without issue.

This may also be a very beginner level problem but I hope simple questions will also help others in the future. Want me to open a separate issue for this or is it also an easy fix? Thanks again.

0x2142 commented 1 month ago

That should be a simple fix as well 😊

In the current frigate-notify config, it's using server: localhost:5000 - which is telling frigate-notify to check port 5000 on itself, not the Frigate container.

In your docker-compose.yml, you can set a container_name for Frigate, which can then be accessed via DNS by frigate-notify. So update your compose file for the Frigate container to include that, like shown below:

services:
  frigate:
    container_name: frigate
...

Then, in the frigate-notify config - try setting the server value to frigate:5000 instead & try restarting.

Please note that since you're running both apps in the same compose file, you may still see frigate-notify say it can't reach that at first, since it may take Frigate a moment to start up & the API to be accessible. But once Frigate starts & the API is available, then frigate-notify should connect.

IxcheI commented 1 month ago

Perfect! Everything is working now, thanks a lot for the help :D

I noticed that the notifications are only sent after an event has concluded, is it possible to sent one as soon as an object is being detected? My use case is kind of like a doorbell so speed is of the essence. If you think its theoretically possible but not with the current implementation I will also accept that as answer.

I will close the issue with this comment since my problems have been resolved and this is more of a general question.

0x2142 commented 1 month ago

Glad to hear it's working for you!

So currently you're set up to use the Web API to check for events, not MQTT. With the Web API, we have to pull events manually from Frigate - which is done on a scheduled interval. By default, this is every 30 seconds but this can be overridden in the config here. That being said the Web API will always be a bit slow because we can't process the event until Frigate processes & publishes it to the API + the lag between that & when frigate-notify runs the next API query to look for events.

If you want instantaneous, you would need to look at using MQTT instead. The way this works, is that there is a separate message broker that frigate-notify subscribes to. Any time there is an event, Frigate will publish the event info to that message broker immediately - and since we're subscribed to those events, that means frigate-notify gets those events as soon as they're published.

The Web API polling method is here since not everyone wants to use MQTT, since it is an additional service to run. However, there are some limitations & speed of detection-to-notification time is one of them.

Hope that helps!