-
-
Notifications
You must be signed in to change notification settings - Fork 35
Xiaomi Door Window sensor 2 (MCCGQ02HL)
Sergey edited this page Jan 10, 2025
·
3 revisions
using var gw3 = new XiaomiGateway3("<gateway ip>", "<gateway token>");
{
gw3.OnDeviceDiscovered += x =>
{
if(x is XiaomiDoorWindowSensor2 device && 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 not
device.OnLightChange += (oldLightValue) => Console.WriteLine($"Light is {device.Light}");
}
};
gw3.DiscoverDevices();
}