Xiaomi Door Window sensor 2 (MCCGQ02HL) - sergey-brutsky/mi-home GitHub Wiki
For Xiaomi Gateway 2
This is BLE sensor, Xiaomi Gateway 2 supports only ZigBee devices.
For Xiaomi Gateway 3
usingvargw3=newXiaomiGateway3("<gateway ip>","<gateway token>");{gw3.OnDeviceDiscovered+= x =>{if(xisXiaomiDoorWindowSensor2device&&device.Did=="<specific did here>"){Console.WriteLine(device.ToString());// Contact can be Opened/Closed/Not closed after specific timeout (default 1 min) device.OnContactChange+=(oldContactState)=>Console.WriteLine($"Door/Window contact is {device.Contact}");device.OnBatteryPercentChange+=(oldBatteryValue)=>Console.WriteLine($"Battery is {device.BatteryPercent}");// Light can be discovered or notdevice.OnLightChange+=(oldLightValue)=>Console.WriteLine($"Light is {device.Light}");}};gw3.DiscoverDevices();}