Open nfrntrd opened 3 years ago
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 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.
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/
frigate/
frigate/
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/
/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/
/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/
/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: @.***>
+1
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?
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
OK, thx!
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
+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.
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
Great idea - can you upload your black.mp4 file and I will give it a try?
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.)
Brilliant chatziko. With my 4 cameras the "black" yml version runs @ 1.8% while running during the day
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
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:
#!/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()
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
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:
See the pictures to better unsderstand what I mean:
Frigate's birdseye Frigate's Camera Frigate Card in Home Assistant
Does anybody have the same problems?
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 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 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 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:
camera.intermittent == true
:
This would accomplish the same while being integrated with the existing enhancement request.
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).
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.
+1 for this.
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.
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: @.***>
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.
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.
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 ;-)
@lolrc If you take the time to read this entire thread you will see that there are a couple workarounds to achieve this.
@tbrausch sure, that's why the issue is still opened :-)
i've seen at least one awful workaround, here is mine I'd replace the ffmpeg binary by a script that does the filtering by reading from a retained mqtt topic and decide whether return false or let frigate connect to the camera :-)
that's just yet another awful workaround because we can't be arsed to code it properly in python ;-)
I'm playing with go2rtc, thinking of using in front of frigate, when using frigate-dev you have 2 connections to the camera when watching a stream (one from ffmpeg, one from go2rtc)
I'm playing with go2rtc, thinking of using in front of frigate, when using frigate-dev you have 2 connections to the camera when watching a stream (one from ffmpeg, one from go2rtc)
The docs cover how to have ffmpeg connect to the go2rtc stream, no need to have go2rtc separate.
Great idea @tbrausch and @chatziko at least until we get a Frigate option to disable cameras.
@samgundel -
Are you running the script as a service to make it start again after reboot or how have you solved this?
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:
Hi @citgot, yes, I am using systemd to start the service after reboot as soon as there is network connection.
Hi, would really like to get this feature out of the box. In my case, I want to completely disable the stream from the cameras when I'm on location, because the internet there sucks... Even a 2-3 mbps stream is causing problems, I need a simple and reliable automation to turn off the cameras when I show up on site. This is exactly what I have now implemented for Synology Surveillance Stantion. I would really like to get this in frigate as well.
In case anyone is wondering, I have so far solved the issue of disabling the camera from Home Assistance by creating this command_line switch:
frigate_srv01_reolinkcam_02:
unique_id: 85349ace-4a18-49c6-a71d-b7f1b823beb3
friendly_name: Frigate ReolinkCam 02 Switch
command_timeout: 20
command_on: >-
ssh -i /config/.ssh/id_ecdsa
-o 'StrictHostKeyChecking=no'
ha@srv01.home.intra
"yq -i '.cameras.reolinkcam_02.enabled = True' /opt/docker-compose/frigate/config/config.yml &&
docker compose -f /opt/docker-compose/frigate/docker-compose.yaml restart"
command_off: >-
ssh -i /config/.ssh/id_ecdsa
-o 'StrictHostKeyChecking=no'
ha@srv01.home.intra
"yq -i '.cameras.reolinkcam_02.enabled = False' /opt/docker-compose/frigate/config/config.yml &&
docker compose -f /opt/docker-compose/frigate/docker-compose.yaml restart"
command_state: >-
curl -s -X GET http://srv01.home.intra:5000/api/config | jq '.cameras.reolinkcam_02.enabled'
value_template: >-
{{ value == "true" }}
Frigate is running in the docker on a separate server.
The yq utility is very handy for editing the config.
It is enough to change the enabled: True
to enabled: False
for needed camera and restart the container.
Thus, in HA I have only one switch to turn off and on the camera, which I can use in automations.
However, this is not the most convenient option, because during the restart of the container, the other cameras are also unavailable. And, more unfortunate, go2rtc too, through which I work in general all the threads...
+1 on this.
I have a cam in the garage which is 99% idle. But would be great to start listening to the stream and start detect if the garage door is open, so HA could send a trigger on MQTT.
I was confused at first since there is so much wrong/invalid info about disabling your cameras in frigate but using mqtt is exactly what I was looking for and if you have setup hardware acceleration correctly cpu usage is below 2% per 4k stream.
You simply have to disable motion detection using mqtt which is easily done in homeassistant using:
automation:
- alias: "enable/disable frigate motion detection if home"
trigger:
platform: state
entity_id: binary_sensor.at_home
action:
- service: mqtt.publish
data:
topic: frigate/<camera_name>/detect/set
payload_template: "{{ 'OFF' if trigger.to_state.state == 'on' else 'ON' }}"
retain: true
where binary_sensor.at_home is taken from my smartphone being connected to wifi:
binary_sensor:
- platform: template
sensors:
at_home:
friendly_name: "At home"
value_template: "{{ states('sensor.<phone_name>_wifi_connection') | regex_search('<wifi_ssid>') }}"
device_class: connectivity
replace any <placeholder>
if you have setup hardware acceleration correctly cpu usage is below 2% per 4k stream
The problem is not the CPU load, the problem is the communication channels and the traffic from the camera. The cameras are not always local.
the problem is the communication channels and the traffic from the camera.
Exactly. Wifi cameras are also a problem. They're uselessly clogging the network when everyone is at home and needs bandwidth, but they're perfectly fine when everyone is out and you actually need them.
I've created a draft pull request for adding an MQTT topic to enable/disable the FFMPEG process:
https://github.com/blakeblackshear/frigate/pull/6744
It's not well tested, at all. I also don't know the architecture of Frigate well enough to know if my approach 'fits' ... But I figured I'd put up what I have in case any one else wants to give it a go
Would it be elegant to solve this 'issue' with an optional fallback path in the config (if cameras' fps is zero) to an dummy vid (streamed by a local rtsp server - like rtsp-relay)?
+1 for this feature. Is this currently under consideration?
I have a use case that is similar to what others have mentioned, but slightly different. I have an indoor ptz cam but when someone is home it gets put into "privacy" mode where it physically moves the head so it can't capture an image, and shuts off its stream. I like that it isn't possible for it to be recording (no stream) and I can see that it isn't capturing activity (physical orientation).
I get a stream error log every 10s. Not a huge deal, but it stinks when I am trying to troublehsoot an issue. Would be nice to add a step to my HA automation that enables the cameras privacy mode to also tell Frigate to stop trying to connect to the stream. I hope this or something that will achieve a similar result can be added in the future!
@djdubd My use case is nearly identical. I solved it by having a Home Assistant automation fire when Zone.Home detects 0. The automation runs a 'shell_command' that I added to HomeAssistant which fires a python script that takes in a list of what cameras are enabled/disabled. The python script modifies the Frigate config.yaml. Then in the same automation I use MQTT to issue a restart to Frigate. Frigate reboots with the new config.yml. Would be great if Frigate would just add the ability to toggle camera states over MQTT.
Need this aswell a camera of mine is combiner with a night-light. So it turns on only during night. I need to be able to toggle off this camera.
go2rtc has a rest api that allows cameras(streams) to be added & deleted. Would this be simpler to do using that? If clear documentation cold be provided - maybe that would meet everyone's ask?
the change needs to be made in frigate because frigate still expects the stream to exist and not everyone uses go2rtc for every stream.
This has been long in the wants for lots of people. Would it be too much dev/design work to simply enable/disable cameras either on a schedule or on demand (or both)? All of the workarounds (the most effective being the automation that swaps out config files) have the disadvantage of also eliminating the disabled cameras from the UI (event watching, etc.).
Can someone in the dev arena actually give some feedback as to the progress of this? Some of us are regular donors and would like some feedback on the feasibility of this long standing and basic request.
Some of us are regular donors and would like some feedback on the feasibility of this long standing and basic request.
This is not a basic request.
it is a difficult challenge to implement this feature given the many edge cases of different user configurations, some of the reasons were outlined in https://github.com/blakeblackshear/frigate/pull/6744#issuecomment-1634654897 and the subsequent conversation.
There are other changes we have planned that will make implementing this easier, but those changes need to come first
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.