Skip to content

Aqara Door Window sensor (MCCGQ11LM)

Sergey edited this page Jul 17, 2024 · 2 revisions

For Xiaomi Gateway 2

using var gw2 = new XiaomiGateway2();
{
    gw2.OnAqaraOpenCloseSensor  = (_, x) =>
    {
        Console.WriteLine(x.ToString());

        if(x.Sid == "<specific sid here>")
        {
            x.OnOpen  = (_, __) => Console.WriteLine("Door/Window is open");
            x.OnClose  = (_, __) => Console.WriteLine("Door/Window is close");
        }
    };
}   

For Xiaomi Gateway 3

using var gw3 = new XiaomiGateway3("<gateway ip>", "<gateway token>");
{
    gw3.OnDeviceDiscovered  = x =>
    {
        if(x is AqaraDoorWindowSensor device && device.Did == "<specific did here>")
        {
            Console.WriteLine(device.ToString());

            device.OnContactChanged  = () => Console.WriteLine($"Door/Window is {device.Contact}");
            device.OnBatteryPercentChange  = (oldBatteryValue) => Console.WriteLine($"Battery is {device.BatteryPercent}");
            device.OnChipTemperatureChange  = (oldChipTemperatureValue) => Console.WriteLine($"Chip Temperature is {device.ChipTemperature}");
            device.OnVoltageChange  = (oldVoltageValue) => Console.WriteLine($"Voltage is {device.Voltage}");
            device.OnLinkQualityChange  = (oldLinkQualityValue) => Console.WriteLine($"Linq quality is {device.LinqQuality}");
        }
    };

    gw3.DiscoverDevices();
}