npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

homebridge-xiaomi-gateway

v1.2.3

Published

XiaomiGateway plugins for HomeBridge(https://github.com/nfarina/homebridge).

Downloads

104

Readme

!!!WORK IN PROGRESS DO NOT USE IT YET TESTCOPY!!!

homebridge-xiaomi-gateway

New built-in/user-uploaded melodies playing functionality available

Installation npm version

npm install -g homebridge-xiaomi-gateway

or

git clone https://github.com/theo-69/homebridge-xiaomi-gateway.git
cd homebridge-xiaomi-gateway
npm link

homebridge plugin for Aqara Xiaomi Gateway plugin.

This repository contains the Aqara plugin for homebridge. Aqara Xiaomi Gateway is a ZigBee gateway with a lot of sensors.

Supported Devices

  1. Gateway
  2. ContactSensor
  3. MotionSensor
  4. Button
  5. TemperatureAndHumiditySensor
  6. SingleSwitch
  7. DuplexSwitch
  8. SingleSwitchLN
  9. DuplexSwitchLN
  10. SingleButton86
  11. DuplexButton86
  12. PlugBase
  13. PlugBase86
  14. MagicSquare
  15. SmokeDetector
  16. NatgasDetector
  17. ElectricCurtain
  18. ContactSensor2
  19. MotionSensor2
  20. Button2
  21. TemperatureAndHumiditySensor2
  22. WaterDetector

Pre-Requirements

  1. Make sure you have V2 of the gateway. V1 has limited space so can't support this feature.
  2. Update gateway firmware to 1.4.1_150.0143 or later.

Installation

  1. Install HomeBridge, please follow it's README.
    If you are using Raspberry Pi, please read Running-HomeBridge-on-a-Raspberry-Pi.
  2. Make sure you can see HomeBridge in your iOS devices, if not, please go back to step 1.
  3. Download homebridge-mi-aqara to your local folder.

Configuration

  1. Open Aqara gateway's settings, enable local network protocol.
    Please follow the steps in this thread: http://bbs.xiaomi.cn/t-13198850. It's in Chinese so you might need a translator to read it.
  2. To control the devices, put gateway's MAC address (lower case without colon) and password (keep original and case sensitive) to ~/.homebridge/config.json.
{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b"
        }
    }]
}

If you have more than one gateways, fill them in right order, like below.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        }
    }]
}

If you want to specify the default name of the device, add a mapping table to your config.json like this.
For more information about default name, Please refer to file sampleConfig.json.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        },
        "melodies":
        [
          { 
            "id": 10001,
            "volume": 5,
            "name": "Button to play melody 1"
          },
          { 
            "id":10002,
            "volume":3,
            "name":"Button to play melody 2",
            "gateway":"f0b223a3484"
          }
        ],
        "defaultValue": {
            "158d0001000001": {
                "ContactSensor_ContactSensor": {
                    "name": "entrance door"
                }
            },
            "158d0001000002": {
                "MotionSensor2_MotionSensor": {
                    "name": "study room motion sensor"
                },
                "MotionSensor2_LightSensor": {
                    "name": "study room light sensor"
                }
            },
            "158d0001000004": {
                "TemperatureAndHumiditySensor_TemperatureSensor": {
                    "name": "living room temperature"
                },
                "TemperatureAndHumiditySensor_HumiditySensor": {
                    "name": "living room humidity"
                }
            }
        }
    }]
}

If you like to use Light Bulb type for Light Switch to make grandma Siri happy, like snOOrz, you can set the following in the config.
Currently only supported: SingleSwitch, DuplexSwitch, SingleSwitchLN, DuplexSwitchLN.
If you changed serviceType config, Please clear register accessories.

New melodies section allows to create virtual buttons for playing system/user-recorded melodies: Volume can be specified by 'volume' parameter, and 'id' is identifier of the internal or user-uploaded melody. 'id' can be: 8,1013,20,21,22,23,24,25,26,27,28,29 - for gateway's default melodies 10000 - stops any playing melodies 10001 and above - user-uploaded melodies Optionally, if you have several gateways you can specify 'gateway' parameter for each melody.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        },
        "defaultValue": {
            "158d0001000007": {
                "SingleSwitch_Switch": {
                    "name": "living room light",
                    "serviceType": "Lightbulb"
                }
            },
            "158d0001000008": {
                "Global": {
                    "serviceType": "Lightbulb"
                },
                "DuplexSwitch_Switch_Left": {
                    "name": "master bedroom room light"
                },
                "DuplexSwitch_Switch_Right": {
                    "name": "study room light"
                }
            },
            "158d10010000001": {
                "DuplexSwitch_Switch_Left": {
                    "name": "master bedroom room light",
                    "serviceType": "Lightbulb"
                },
                "DuplexSwitch_Switch_Right": {
                    "name": "study room light"
                }
            }
        }
    }]
}

If you want to disable accessories, you can add disable attribute to config.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        },
        "defaultValue": {
            "158d0001000007": {
                "SingleSwitch_Switch": {
                    "name": "living room light",
                    "serviceType": "Lightbulb"
                }
            },
            "158d0001000008": {
                "DuplexSwitch_Switch_Left": {
                    "name": "master bedroom room light",
                    "serviceType": "Lightbulb",
                    "disable": false
                },
                "DuplexSwitch_Switch_Right": {
                    "name": "study room light",
                    "serviceType": "Lightbulb",
                    "disable": true
                }
            },
            "158d0001000004": {
                "TemperatureAndHumiditySensor_TemperatureSensor": {
                    "name": "living room temperature"
                },
                "TemperatureAndHumiditySensor_HumiditySensor": {
                    "name": "living room humidity",
                    "disable": true
                }
            },
            "158d0001000012": {
                "Global": {
                    "disable": true
                }
            },
            "158d0001000015": {
                "Global": {
                    "disable": true
                },
                "MagicSquare_StatelessProgrammableSwitch_Flip90": {
                    "name": "study room magic square flip90",
                    "disable": false
                }
            }
        }
    }]
}

If you want to accessory value exact, you can set syncValue is true.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        },
        "defaultValue": {
            "158d0001000007": {
                "SingleSwitch_Switch": {
                    "name": "living room light",
                    "serviceType": "Lightbulb",
                    "syncValue": true
                }
            }
        }
    }]
}

when syncValue is true, accessory will synchronization value when homebridge call the get function. At the same time, it's going to waste more time.
when syncValue is false, accessory will use the device last reported value. It's going to respond quickly.
If you don't like "No Response", you can set disableNoResponse is true.
When the device is no pesponse and disableNoResponse is true, the accessory value will auto jump back to before the control.

{
    "platforms": [{
        "platform": "XiaomiGatewayPlatform",
        "gateways": {
            "6409802da3b3": "02i44k56zrgg578b",
            "f0b4299a5b2b": "2F92E7DA90C66B86",
            "f0b4299a77dd": "syu3oasva3uqd5qd"
        },
        "defaultValue": {
            "Global": {
                "disableNoResponse": true
            }
            "158d0001000007": {
                "SingleSwitch_Switch": {
                    "name": "living room light",
                    "serviceType": "Lightbulb",
                    "syncValue": true
                }
            }
        }
    }]
}

Some explanation

Button/Button2 StatelessProgrammableSwitch support SinglePress, DoublePress, LongPress.
SingleButton86/DuplexButton86(Left, Right, Both) StatelessProgrammableSwitch only support SinglePress.
MagicSquare(Flip90, Flip180, Move, TapTwice, ShakeAir, Rotate) StatelessProgrammableSwitch only support SinglePress.

Run it

homebridge -D

Clear register accessories

cd ~/.homebridge/accessories/
mv cachedAccessories cachedAccessories_`date '+%Y%m%d_%H%M%S'`.bak
echo [] > cachedAccessories

Version Logs

New built-in/user-uploaded melodies playing functionality available*