Skip to content

Repository files navigation

Xiaomi DeviceConnector

ThingsPanel DeviceConnector for Xiaomi cloud and Xiaomi LAN access. This is the new connector runtime implementation. This is the standalone repository for the Xiaomi connector.

Publish identity

  • connectorKey: xiaomi
  • Standalone repo: github.com/thingspanel/thingspanel-device-connector-xiaomi
  • Suggested visibility: public

Scope

  • xiaomi_cloud: Xiaomi OAuth + MIoT cloud HTTP API
  • xiaomi_lan: LAN IP + token mode
  • Device discovery through account/device listing
  • Internal MQTT downlink bridge for ThingsPanel command delivery

xiaomi-plug is the old direct plugin example and should stay deprecated/private. New Xiaomi publishing should center on this connector.

Runtime configuration

Required baseline variables:

  • CONNECTOR_SERVICE_IDENTIFIER=xiaomi
  • CONNECTOR_INSTANCE_ID=<connector-instance-id>
  • THINGSPANEL_BACKEND_URL=http://127.0.0.1:4000
  • XIAOMI_ACCESS_MODE=xiaomi_cloud or xiaomi_lan

MQTT bridge:

  • TP_MQTT_BROKER=tcp://127.0.0.1:1883
  • XIAOMI_TP_DEVICE_ID=<thingspanel-device-id>
  • XIAOMI_MQTT_USERNAME=<thingspanel-device-number>
  • XIAOMI_MQTT_PASSWORD=<optional>

Cloud mode inputs:

  • XIAOMI_CLOUD_SERVER=cn
  • XIAOMI_OAUTH_JSON=<oauth-json> or XIAOMI_OAUTH_FILE=/path/to/oauth.json

LAN mode inputs:

  • XIAOMI_LAN_TOKEN=<device-token>

Local helpers

Generate Xiaomi OAuth material:

cd examples/device-connectors/xiaomi-service
go run ./cmd/oauth-login -cloud-server cn -out /tmp/xiaomi-oauth.json

List discoverable devices:

go run ./cmd/list-devices

Run the connector:

go run .
curl http://127.0.0.1:9001/health

Standard commands

  • {"method":"switch","params":"on"}
  • {"method":"switch","params":"off"}
  • {"method":"brightness","params":35}
  • {"method":"query","params":"state"}

Local publish helper:

go run ./cmd/publish-command -service xiaomi -method query -params '"state"'

Verification and deploy

go test ./...

Live integration test is env-gated:

LIVE_XIAOMI_TEST=1 go test ./...

Deploy helper in this monorepo:

cd encore-api
go run ./cmd/deploy-xiaomi-service

About

ThingsPanel Xiaomi DeviceConnector

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages