diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index b7bdb86fa..010154bef 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -185,6 +185,13 @@ class Dispatcher: ptz_autotracker_settings = self.config.cameras[camera_name].onvif.autotracking if payload == "ON": + if not self.config.cameras[ + camera_name + ].onvif.autotracking.enabled_in_config: + logger.error( + "Autotracking must be enabled in the config to be turned on via MQTT." + ) + return if not self.ptz_metrics[camera_name]["ptz_autotracker_enabled"].value: logger.info(f"Turning on ptz autotracker for {camera_name}") self.ptz_metrics[camera_name]["ptz_autotracker_enabled"].value = True diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py index b1b52ad90..6182c89e3 100644 --- a/frigate/comms/mqtt.py +++ b/frigate/comms/mqtt.py @@ -71,7 +71,7 @@ class MqttClient(Communicator): # type: ignore[misc] ) self.publish( f"{camera_name}/ptz_autotracker/state", - "ON" if camera.onvif.autotracking.enabled else "OFF", + "ON" if camera.onvif.autotracking.enabled_in_config else "OFF", retain=True, ) self.publish( diff --git a/frigate/config.py b/frigate/config.py index 777cdc152..a7ceaeecb 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -184,6 +184,9 @@ class PtzAutotrackConfig(FrigateBaseModel): default=[], title="Internal value used for PTZ movements based on the speed of your camera's motor.", ) + enabled_in_config: Optional[bool] = Field( + title="Keep track of original state of autotracking." + ) @validator("movement_weights", pre=True) def validate_weights(cls, v): @@ -1191,6 +1194,9 @@ class FrigateConfig(FrigateBaseModel): # set config pre-value camera_config.record.enabled_in_config = camera_config.record.enabled camera_config.audio.enabled_in_config = camera_config.audio.enabled + camera_config.onvif.autotracking.enabled_in_config = ( + camera_config.onvif.autotracking.enabled + ) # Add default filters object_keys = camera_config.objects.track diff --git a/frigate/ptz/autotrack.py b/frigate/ptz/autotrack.py index a7352a8f5..4bca8be47 100644 --- a/frigate/ptz/autotrack.py +++ b/frigate/ptz/autotrack.py @@ -208,7 +208,10 @@ class PtzAutoTracker: continue self.autotracker_init[camera] = False - if camera_config.onvif.autotracking.enabled: + if ( + camera_config.onvif.autotracking.enabled + and camera_config.onvif.autotracking.enabled_in_config + ): self._autotracker_setup(camera_config, camera) def _autotracker_setup(self, camera_config, camera):