diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index 0a9c439f4..760c2234b 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -75,6 +75,7 @@ class Dispatcher: "birdseye_mode": self._on_birdseye_mode_command, "review_alerts": self._on_alerts_command, "review_detections": self._on_detections_command, + "genai": self._on_genai_command, } self._global_settings_handlers: dict[str, Callable] = { "notifications": self._on_global_notification_command, @@ -737,3 +738,28 @@ class Dispatcher: review_settings, ) self.publish(f"{camera_name}/review_detections/state", payload, retain=True) + + def _on_genai_command(self, camera_name: str, payload: str) -> None: + """Callback for GenAI topic.""" + genai_settings = self.config.cameras[camera_name].genai + + if payload == "ON": + if not self.config.cameras[camera_name].genai.enabled_in_config: + logger.error( + "GenAI must be enabled in the config to be turned on via MQTT." + ) + return + + if not genai_settings.enabled: + logger.info(f"Turning on GenAI for {camera_name}") + genai_settings.enabled = True + elif payload == "OFF": + if genai_settings.enabled: + logger.info(f"Turning off GenAI for {camera_name}") + genai_settings.enabled = False + + self.config_updater.publish_update( + CameraConfigUpdateTopic(CameraConfigUpdateEnum.genai, camera_name), + genai_settings, + ) + self.publish(f"{camera_name}/genai/state", payload, retain=True) diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py index e487b30ee..b0f85387e 100644 --- a/frigate/comms/mqtt.py +++ b/frigate/comms/mqtt.py @@ -122,6 +122,11 @@ class MqttClient(Communicator): # type: ignore[misc] "ON" if camera.review.detections.enabled_in_config else "OFF", retain=True, ) + self.publish( + f"{camera_name}/genai/state", + "ON" if camera.genai.enabled_in_config else "OFF", + retain=True, + ) if self.config.notifications.enabled_in_config: self.publish( @@ -215,6 +220,7 @@ class MqttClient(Communicator): # type: ignore[misc] "birdseye_mode", "review_alerts", "review_detections", + "genai", ] for name in self.config.cameras.keys(): diff --git a/frigate/config/camera/updater.py b/frigate/config/camera/updater.py index 756e370db..164899be0 100644 --- a/frigate/config/camera/updater.py +++ b/frigate/config/camera/updater.py @@ -17,6 +17,7 @@ class CameraConfigUpdateEnum(str, Enum): birdseye = "birdseye" detect = "detect" enabled = "enabled" + genai = "genai" motion = "motion" # includes motion and motion masks notifications = "notifications" objects = "objects"