Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

С# API for Xiaomi Mi Home devices

License

NotificationsYou must be signed in to change notification settings

sergey-brutsky/mi-home

Repository files navigation

Build projectTestsNugetNugetLicense

This library provides simple and flexible C# API for Xiaomi smart devices.

Currently supportsonlyGateway version 2 (DGNWG02LM),Gateway version 3 (ZNDMWG03LM),Air Humidifier (zhimi.humidifier.v1),Mi Robot vacuum (rockrobo.vacuum.v1) and several sensors. See table below.

xiaomi-gateway-2

Supported gateway devices/sensors

DeviceGateway 2 supportGateway 3 support
Aqara Vibration Sensor

DJT11LM
yesyes
Xiaomi Door/Window Sensor

MCCGQ01LM
yesyes
Xiaomi Door/Window Sensor 2

MCCGQ02HL
noyes
Aqara Door/Window Sensor

MCCGQ11LM
yesyes
Xiaomi TH Sensor

WSDCGQ01LM
yesyes
Xiaomi TH Sensor 2

LYWSD03MMC
noyes
Aqara TH Sensor

WSDCGQ11LM
yesyes
Aqara Water Leak Sensor

SJCGQ11LM
yesyes
Xiaomi Motion Sensor

RTCGQ01LM
yesyes
Xiaomi Motion Sensor 2

RTCGQ02LM
noyes
Aqara Relay T1 EU (with N)

SSM-U01
noyes
Aqara Relay CN

LLKZMK11LM
noyes
Aqara Opple Switch (2 buttons)

WXCJKG11LM
noyes
Aqara Opple Switch (4 buttons)

WXCJKG12LM
noyes
Honeywell Smoke Sensor

JTYJ-GD-01LM/BW
yesyes
Honeywell Smoke Alarm

JTYJ-GD-03MI
noyes
Xiaomi Wireless Button

WXKG01LM
yesyes
Xiaomi Plug CN

ZNCZ02LM
yesyes
Aqara Double Wall Switch (no N)

QBKG03LM
yesno
Aqara Double Wall Button CN

WXKG02LM
yesno
Aqara Cube EU

MFKZQ01LM
yesno

via nuget package manager

Install-Package MiHomeLib

or

dotnet add package MiHomeLib

or install viaGitHub packages

Before using this library you should setupdevelopment mode on your gateway,instructions how to do this.
This mode allows to work with the gateway via UDP multicast protocol.

Warning 1:If you bought a newer revision of Mi Home Gateway (labels in a circle)

It could be possible that ports on your gateway required for UDP multicast traffic areclosed.
Before using this libraryports must be opened.Check this instruction.

Warning 2: Mi Home Gateway uses udp multicast for messages handling, so your appmust be hosted in the same LAN as your gateway.If it is not youhave to use multicast routers likeudproxy origmpproxy orvpn bridging.

Warning 3: If your app is running on windows machine, make sure that you disabled virtual network adapters like VirtualBox, Hyper-V, Npcap, pcap etc.Because these adapters may prevent proper work of multicast traffic between your machine and gateway

Before using this library:

  1. Open telnet on your gateway
  2. Expose MQTT broker to the world
  3. Extract token to work with your gateway

The easisest way is to setup/configurethis HA integration (it does all aforementioned things automatically).

The way of warrior:

  1. Enable telnet on your gateway
  2. Download thisopenmiio_agent and upload it to your gateway (for example to /data/openmiio_agent) via telnet
  3. Login to your gateway via telnettelnet <gateway ip> 23 (login: admin, pwd: empty)
  4. Kill embedded mosquitto mqtt broker and run openmiio_agent (it will expose mqtt port 1883 to the world)kill -9 <pid of mosquitto> && /data/openmiio_agent mqtt &
  5. Check that mosquitto is binded to0.0.0.0 1883netstat -ntlp | grep mosquitto
  6. Extract token instructions

Get all devices in the network from theXiaomi Gateway 2

publicstaticvoidMain(string[]args){// gateway password is optional, needed only to send commands to your devices// gateway sid is optional, use only when you have 2 gateways in your LAN// using var gw2 = new XiaomiGateway2("gateway password", "gateway sid");usingvargw2=newXiaomiGateway2();gw2.OnAnyDevice+=(_,device)=>{Console.WriteLine($"{device.Sid},{device.GetType()},{device}");// all discovered devices};Console.ReadLine();}

Get all devices in the network from theXiaomi Gateway 3

publicstaticvoidMain(string[]args){usingvargw3=newXiaomiGateway3("<gateway ip>","<gateway token>");gw3.OnDeviceDiscovered+= gw3SubDevice=>{Console.WriteLine(gw3SubDevice.ToString());// all discovered devices};gw3.DiscoverDevices();Console.ReadLine();}

Check detailed documentation on how to work with different devices in theproject's WIKI

Your pull requests are welcome to replenish the database of supported devices


[8]ページ先頭

©2009-2025 Movatter.jp