Skip to content

About

Bridge a cloud-locked Xiaomi CW300 camera into UniFi Protect via go2rtc + a minimal ONVIF adapter

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Xiaomi CW300 -> UniFi Protect bridge

Adds a cloud-locked Xiaomi Outdoor Camera CW300 to UniFi Protect as a third-party camera. The CW300 exposes no local RTSP/ONVIF - it only speaks Xiaomi's encrypted miss protocol. This bridge:

  1. Uses go2rtc to pull the camera stream (it fetches the per-connection decryption key from the Xiaomi cloud) and transcodes H.265/Opus to H.264/AAC (Protect dislikes H.265).
  2. Runs onvif_adapter.py, a ~250-line stdlib ONVIF Profile S adapter that answers WS-Discovery + SOAP so Protect can discover and adopt the go2rtc RTSP stream.
CW300 (H.265/Opus)  ->  go2rtc  ->  transcode H.264/AAC  ->  onvif_adapter.py  ->  UniFi Protect

No secrets are committed. Your Xiaomi passToken lives only in go2rtc.yaml (gitignored) and is written there by go2rtc after you log in.

Requirements

  • go2rtc >= 1.9.13 (native Xiaomi support)
  • ffmpeg with a hardware H.264 encoder (Apple Silicon: h264_videotoolbox)
  • Python 3.8+ (stdlib only)
  • The host must be on the same LAN as the camera and stay powered on
  • A Xiaomi account with email + password (Sign-in-with-Apple only accounts must add a password in the Mi Home app first)

Setup

  1. Install go2rtc and ffmpeg.

  2. Copy the config template and start go2rtc:

    cp go2rtc.example.yaml go2rtc.yaml
    ./go2rtc -config go2rtc.yaml
    
  3. Open http://127.0.0.1:1984 > Add > Xiaomi and log in. go2rtc writes the xiaomi: passToken block into go2rtc.yaml and lists your cameras. Fill the cw300: line with your camera's USER_ID, REGION, CAMERA_IP, DID, MODEL (visible in that list or via GET /api/xiaomi?id=USER_ID), then restart go2rtc. Verify:

    ffprobe rtsp://127.0.0.1:8554/cw300_h264   # should show h264 + aac
    
  4. Start the ONVIF adapter (config via env vars, see below):

    CW300_LAN_IP=192.168.0.7 CW300_ONVIF_USER=protect CW300_ONVIF_PASS=protect \
      python3 onvif_adapter.py
    
  5. In UniFi Protect: Settings > Cameras > Discover Third-Party Cameras (ONVIF). Adopt the discovered camera using the ONVIF user/pass above.

Configuration (environment variables)

Variable Default Meaning
CW300_LAN_IP autodetect host IP the Protect console will reach
CW300_ONVIF_PORT 8555 adapter SOAP/HTTP port
CW300_ONVIF_USER / CW300_ONVIF_PASS protect / protect ONVIF credentials (enter the same in Protect)
CW300_RTSP_PORT 8554 go2rtc RTSP port
CW300_RTSP_PATH cw300_h264 go2rtc stream name served to Protect
CW300_SNAP_SRC cw300 go2rtc stream used for snapshots
CW300_GO2RTC_API 127.0.0.1:1984 go2rtc API (local) for snapshots
CW300_NAME / CW300_MODEL Xiaomi CW300 / CW300 display name / model
CW300_WIDTH / CW300_HEIGHT 848 / 480 advertised resolution
CW300_UUID built-in stable ONVIF device UUID

Tests

python3 -m unittest -v

Notes and limitations

  • Not fully local: every stream (re)connection needs Internet to obtain the Xiaomi per-connection key (~3-4 s). The video itself is then LAN-only.
  • Always-on host: the bridge machine is the camera source for Protect.
  • Security: the RTSP stream and the ONVIF adapter are exposed on the LAN (they must be, for Protect to reach them). Keep this on a trusted network; do not expose to the Internet.
  • The adapter does not strictly validate the ONVIF password (Protect still requires a username/password field). Add validation if you need it.

About

Bridge a cloud-locked Xiaomi CW300 camera into UniFi Protect via go2rtc + a minimal ONVIF adapter

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages