frigate icon indicating copy to clipboard operation
frigate copied to clipboard

Enhancement Request: Ability to dynamically disable/enable individual cameras

Open nfrntrd opened this issue 3 years ago • 63 comments

Describe what you are trying to accomplish and why in non technical terms I want to be able to dynamically enable/disable cameras defined in the config.yml so that I can ensure no data is flowing from camera to the frigate container when not in use. Right now when the switch to stop recording is turned off, the camera/ffmpeg/rtsp process still keeps gathering video data and continues to drop files into /tmp/cache. (Assume snapshot and detect is also off) I want to be able to ensure no data is flowing between camera and frigate container when I don't need the camera to capture anything. The use case here is I don't want cameras doing anything when I'm home in the house. My cameras are wireless enabled and use power/wireless bandwidth. It becomes quite a bandwidth hog having multiple in the house to simply throw all that data away. The switch to turn them on then becomes important to turn on the camera with recordings when I'm away from the house (triggered by HA via security alarm.)

Describe the solution you'd like I would like another frigate HA switch service call to be available per camera that will completely disable/enable the camera and stop/start the ffmpeg process when not needed in the container.

Describe alternatives you've considered From another NVR type of solution (Zoneminder) I've used, the idea of starting/stopping ffmpeg is a part of the profile and callable to disable said cameras. (That's my alternative) :) From a frigate standpoint already tried stopping recording switch to learn what I summarized above.

Additional context None.

nfrntrd avatar Oct 05 '21 14:10 nfrntrd

I would also really like to find a way to enable/disable particular cameras in frigate. I am trying to keep my CPU usage to a minimum and would like to enable/disable certain cameras based on time of day, presence detection, alarm activated, etc. Is it possible in a future release to stop the ffmpeg process for a camera if the detect, snapshot, and record switches are all turned off?

tbrausch avatar Apr 19 '22 15:04 tbrausch

@tbrausch I have a PR up to add the ability to selectively toggle motion detection which will help with this. Completely disabling ffmpeg for a camera selectively would be much more complicated but I don't think impossible.

NickM-27 avatar Apr 19 '22 15:04 NickM-27

I would also really like to find a way to enable/disable particular cameras in frigate. I am trying to keep my CPU usage to a minimum and would like to enable/disable certain cameras based on time of day, presence detection, alarm activated, etc. Is it possible in a future release to stop the ffmpeg process for a camera if the detect, snapshot, and record switches are all turned off?

You could use MQTT, as shown here: https://docs.frigate.video/integrations/mqtt

frigate/<camera_name>/detect/set# Topic to turn detection for a camera on and off. Expected values are ON and OFF.

frigate/<camera_name>/detect/state# Topic with current state of detection for a camera. Published values are ON and OFF.

frigate/<camera_name>/recordings/set# Topic to turn recordings for a camera on and off. Expected values are ON and OFF.

crashnbernstein avatar Apr 19 '22 17:04 crashnbernstein

Yes, I can turn off objrect detection, but the ffmpeg process for motion detection still runs, and this is what utilizes a bit of CPU resources, especially with 6 cameras at one time.

On Tue, Apr 19, 2022 at 1:59 PM crashnbernstein @.***> wrote:

I would also really like to find a way to enable/disable particular cameras in frigate. I am trying to keep my CPU usage to a minimum and would like to enable/disable certain cameras based on time of day, presence detection, alarm activated, etc. Is it possible in a future release to stop the ffmpeg process for a camera if the detect, snapshot, and record switches are all turned off?

You could use MQTT, as shown here: https://docs.frigate.video/integrations/mqtt

frigate/<camera_name>/detect/set# https://docs.frigate.video/integrations/mqtt#frigatecamera_namedetectset Topic to turn detection for a camera on and off. Expected values are ON and OFF.

frigate/<camera_name>/detect/state# https://docs.frigate.video/integrations/mqtt#frigatecamera_namedetectstate Topic with current state of detection for a camera. Published values are ON and OFF.

frigate/<camera_name>/recordings/set# https://docs.frigate.video/integrations/mqtt#frigatecamera_namerecordingsset Topic to turn recordings for a camera on and off. Expected values are ON and OFF.

— Reply to this email directly, view it on GitHub https://github.com/blakeblackshear/frigate/issues/1911#issuecomment-1102933281, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZQ3VHUJ4KWD46LUFLTO53VF3YBHANCNFSM5FL4U7WA . You are receiving this because you were mentioned.Message ID: @.***>

tbrausch avatar Apr 19 '22 18:04 tbrausch

+1

MickazNL avatar Jun 12 '22 10:06 MickazNL

I see that the new 11.0 beta has included switches to enable/disable motion detection on a per camera basis. When detection, motion, and recording are turned off for a particular camera is the ffmpeg process for that camera terminated?

tbrausch avatar Jun 12 '22 16:06 tbrausch

I see that the new 11.0 beta has included switches to enable/disable motion detection on a per camera basis. When detection, motion, and recording are turned off for a particular camera is the ffmpeg process for that camera terminated?

No, video will still be decoded and it will still be viewable in frigate / HA. This will come as a separate action in a future release

NickM-27 avatar Jun 12 '22 16:06 NickM-27

OK, thx!

tbrausch avatar Jun 12 '22 16:06 tbrausch

In case anyone is interested, thought I would share a simple workaround that I am currently using to get around this issue. Just to reiterate, I am running HA on a Celeron processor with 4 cameras and object detection at 1920x1080, 3FPS (my cameras do not support substreams). This takes a significant amount of CPU resources, so sometimes I want to disable 2 of the cameras while other times I want all 4 cameras active (when I am away, for example).

Workaround: I created 2 shell commands which simply copy two different frigate configuration files to the default file frigate.yaml. I then have two scripts called frigate2 and frigate4 that call the appropriate shell command and then restart frigate. Not elegant, but works perfectly.

frigate4:
  alias: Restart Frigate with 4 Active Cameras
  sequence:  
  - service: shell_command.frigate4
  - service: hassio.addon_restart
    data:
      addon: "ccab4aaf_frigate-beta"
shell_command:
  frigate2: cp /config/frigate-2.yaml /config/frigate.yaml
  frigate4: cp /config/frigate-4.yaml /config/frigate.yaml

tbrausch avatar Jun 15 '22 12:06 tbrausch

+1, the abilitity to enable/disable cameras is hugely useful (it is very common for several cameras to be used only at night or when away).

Even better: ideally, frigate could automatically switch off its input sources when not used. Each camera can have multiple inputs for different roles (record, detect, rtmp). When each role is inactive, the corresponding input is not needed, so it should be switched off to save bandwidth/cpu. If no role is active, then the camera should not consume any resources at all.

chatziko avatar Jul 12 '22 16:07 chatziko

Building on the workaround of @tbrausch for disabling cameras, instead of completely removing a camera from the confg, it's possible to give it a "dummy" input like the one below. black.mp4 is a dummy mp4 containing a few minutes of a black 2x2 frame at 1 fps.

With this config, ffmpeg takes ~1% CPU on my rpi4, and of course consumes no bandwidth. The advantage is that the camera is still visible in the UI, we can browse events/recordings, etc.

cameras:
  my_camera:
    ffmpeg:
      inputs:
        - input_args: "-re -stream_loop -1 -fflags +genpts"
          path: "/config/black.mp4"
          roles:
          - rtmp
          - record
          - detect
    detect:
      width: 2
      height: 2
      fps: 1
      enabled: False
    record:
      enabled: False

chatziko avatar Jul 13 '22 08:07 chatziko

Great idea - can you upload your black.mp4 file and I will give it a try?

tbrausch avatar Jul 13 '22 08:07 tbrausch

Sure: https://user-images.githubusercontent.com/362089/178692766-3a394ad7-e027-48cb-b2c3-1c6d7be2370e.mp4

(It was created with ffmpeg -stream_loop -1 -i black.png black.mp4 where black.png is 2x2 black image. I tried directly using black.png as an input but frigate didn't like it.)

chatziko avatar Jul 13 '22 08:07 chatziko

Brilliant chatziko. With my 4 cameras the "black" yml version runs @ 1.8% while running during the day

sshort1955 avatar Jul 28 '22 16:07 sshort1955

Nice! You can also try this version, I remember I made some change that made it faster to decode (although 1.8% seems already pretty optimal)

https://user-images.githubusercontent.com/362089/181588415-04444470-551a-45da-b048-da82614a2acb.mp4

chatziko avatar Jul 28 '22 16:07 chatziko

I really liked the idea of replacing the config and getting rid of the cameras. Nevertheless I am running Home Assistant on VirtualBox VDI and Frigate via docker-compose on the host.

What I end up doing was the following:

  • listening via mqtt on my host for a message to swap the files
  • swap the files via home assistant automation
  • restart frigate via mqtt

On Host

#!/usr/bin/python3
import paho.mqtt.client as mqtt
import shutil

HOST = "192.168.X.X"
USER = "frigate_swapper"
PASSWORD = "ABC"

CLIENT = "FrigateSwapper"
PORT = 1883
TOPIC = "frigate/swapper/config"
TARGET_CONFIG = "config.yaml"

config = {
    "2" : "two-cameras.yaml",
    "4" : "all-cameras.yaml"
}

def on_message(client, userdata, message):
    payload = str(message.payload.decode("utf-8"))
    print("Payload %s received" % payload)
    if payload in config:
        shutil.copyfile(config[payload], TARGET_CONFIG)
    else:
        print("config %s not found for frigate" % payload)

client = mqtt.Client(CLIENT)
client.on_message=on_message

print("connecting to Home Assistant MQTT Broker")
client.username_pw_set(USER, PASSWORD)
client.connect(HOST, PORT)
client.on_message=on_message

print("subscribing to topic %s" % TOPIC)
client.subscribe(TOPIC)
client.loop_forever()

On Home Assistant

alias: Frigate - Enable Only Day Cameras
trigger:
  - platform: time
    at: "07:00:00"
condition: []
action:
  - service: mqtt.publish
    data:
      topic: frigate/swapper/config
      payload: "2"
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: mqtt.publish
    data:
      topic: frigate/restart
mode: single

samgundel avatar Aug 19 '22 20:08 samgundel

Hello together, first: thank you @tbrausch and @chatziko - great idea! I'm also replacing the frigate config.yaml to get rid of the indoor cameras when I'm at home and I'm using the black.mp4 from @chatziko. I do this via a home assistant presence automation because I don't want my indoor cams on when I'm at home.

It works like a charm....but I still have some little problems:

  • Frigate's birdseye almost always shows just a white picture when cameras are "deactivated"
  • Frigate's Camera view shows the "deactivated" cameras as black squares (1:1 and not an 16:9)
  • the Frigate Card (https://github.com/dermotduffy/frigate-hass-card) doesn't work anymore with "deactivated" cameras

See the pictures to better unsderstand what I mean:

Frigate's birdseye fg-be Frigate's Camera fg-square Frigate Card in Home Assistant fg-cust-card

Does anybody have the same problems?

vakilando avatar Sep 19 '22 10:09 vakilando

Frigate's Camera view shows the "deactivated" cameras as black squares (1:1 and not an 16:9)

The filler video will be to be cropped to fit the same aspect ratio as your actual camera

NickM-27 avatar Sep 19 '22 11:09 NickM-27

@NickM-27 FYI the "Describe the solution you'd like" in this issue is really quite different from #4897. I think it's worth mentioning that the issue you just closed as a duplicate is specifically about turning on/off camera logs by plugging/unplugging them. Not through external software such as HA as discussed in this issue.

Redsandro avatar Jan 05 '23 02:01 Redsandro

@Redsandro I can see that it is different and I should've given more info on the reason for closing, I am sorry about that.

The use case of the feature falls under the same category, being that there's some cameras that aren't always in use and they should be turned off and not trying to connect. This solution here is preferable because it not only would alleviate the log spam but it would actually stop doing the work of trying to connect to the camera.

NickM-27 avatar Jan 05 '23 02:01 NickM-27

@NickM-27 gotcha, thanks.

Generally speaking this issue seems to be about a "software camera off" option. For the folks using frigate stand-alone it would be nice to have such a toggle feature in the frigate GUI as well, next to the suggested Home Assistant binding.

Speaking specifically to what #4897 was trying to accomplish (with proposed intermittent: True), in the context of this existing issue it'd be for "software camera off and on" to follow the hardware state of the camera as detected by stream up or down:

  • When camera.intermittent == true:
    • on ffmpeg error (hardware camera gone):
      • turn software camera off
    • on ping detect camera stream up:
      • turn software camera on, start ffmpeg processes again

This would accomplish the same while being integrated with the existing enhancement request.

Redsandro avatar Jan 05 '23 10:01 Redsandro

I vote for camera/ffmpeg on/off control as well, not only in the GUI but also as an MQTT state switch (like detection). I had to resort to the dual YAML file swap method as suggested by @tbrausch. I have no need for the cameras during the times that I am mowing, shoveling snow, splitting wood, etc., but the CPU works harder while I create all that motion, even with detection turned off (using MQTT switch from HA).

sshort1955 avatar Jan 05 '23 13:01 sshort1955

I'm also in favor of a solution like this.

In my case, I have a lot of cameras running though frigate, but I live in a country where the grid is not very reliable. I have a backup battery system, but when the batteries are running low I want to disable the cameras using a Sonoff of similar to save battery power. BUT: I don't want to create a ton of logs and unnecessary CPU wastage with Frigate trying to access the cameras over and over again.

I might try to stop/suspend Frigate altogether when this happens (likely a better solution), but a soft-switch to turn a camera on/off would enable me to focus on some cameras while leaving others running.

ebendl avatar Jan 10 '23 20:01 ebendl

+1 for this.

0x414c49 avatar Jan 12 '23 20:01 0x414c49

This is also something that I need.

I need only indoor cameras to be turned off and not recording during the daytime and turned on and recording only at night or when no one is home.

I've been researching ways to implement this. One way would be to use a ha controlled PoE switch to disable specific ports. Another would be to use smart plugs to cut power to specific cameras.

Frigate should be able to handle the camera disconnections gracefully.

chanon avatar Jan 16 '23 16:01 chanon

For that you can simply disable recording, motion detection and snapshots so frigate won’t record but the camera is still there.

On Mon, Jan 16, 2023, at 5:19 PM, Chanon Sajjamanochai wrote:

This is also something that I need.

I need indoor cameras to be turned off and not recording during the daytime and turned on and recording only at night or when no one is home.

I've been researching ways to implement this. One way would be to use ha controlled PoE switch to disable specific ports. Another would be to use a smart plug to cut power to specific cameras.

Frigate should be able to handle the camera's disconnection gracefully.

— Reply to this email directly, view it on GitHub https://github.com/blakeblackshear/frigate/issues/1911#issuecomment-1384279368, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTT3LQVEJNAWSKIJN5Y22DWSVYIFANCNFSM5FL4U7WA. You are receiving this because you commented.Message ID: @.***>

0x414c49 avatar Jan 16 '23 20:01 0x414c49

Would also love this feature. I have an indoor Amcrest camera that has a privacy mode that I activate via home assistant when I am home. Right now, the Frigate log gets spammed because the camera turns off the rtsp feed in privacy mode, so Frigate can't access it. Would love to be able to disable the camera or something via mqtt so the log doesn't freak out.

jonlarson13 avatar Feb 20 '23 00:02 jonlarson13

I would like this feature. My use case is to capture the stream from a Ring 2 Doorbell but only when the Doorbell detects motion. Then when motion is detected, enable the Frigate stream connection for recording, events for a while until Frigate determines there is no motion or interesting objects. Currently, Frigate is attempting to stream the camera constantly even if all detect/recording features are disabled, which quickly depletes the Ring 2 Doorbell battery. I use Home Assistant with the Frigate addon, Frigate NVR Proxy addon, and the Ring-MQTT with Video Streaming addon, which Frigate gets the doorbell camera feed from. I think in my case the Ring-MQTT with Video Stream is the bad-actor that keeps the camera stream alive because it has a consumer (Frigate) constantly attached to it, even when Frigate may not be consuming the stream. To solve this problem, I think Frigate should have an externally controllable method to detach and reattach from/to the stream.

bmarr avatar Mar 25 '23 20:03 bmarr

looks like disabling detect/motion/recording/snapshots still leaves a ffmpeg process fetching from camera => both frigate and camera cpu/gpu are used for nothing => energy consumed for nothing ! bad bad bad ;-)

lolorc avatar Mar 26 '23 23:03 lolorc

@lolrc If you take the time to read this entire thread you will see that there are a couple workarounds to achieve this.

tbrausch avatar Mar 26 '23 23:03 tbrausch