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 🙏

© 2024 – Pkg Stats / Ryan Hefner

homebridge-xiaomi-alarmswitch

v2.1.3

Published

homebridge-xiaomi-alarmswitch

Downloads

23

Readme

homebridge-xiaomi-alarmswitch v2.1

Homebridge dynamic platform plugin for Xiaomi Aqara Switches with morse code functionality

npm npm GitHub last commit

This homebridge plugin exposes Xiaomi Aqara switches setted in config.json as switch accessory to HomeKit with morse code functionality!

What means 'morse code'?

Well, i'm using this switch for activating/deactivating my house alarm. Normally i need to single click the button for activating the alarm and double click for deactivating. But this seems not to be secure. Because of this, i have created this plugin to give these switches a special functionality!.

Plugin in action (Log)

Compatible switches

Token and switch/device ID

In order to work without any problems, this plugin uses the miio module for discovering and storing the gateway information in your persist folder. Because of this, it is not temporarely important to set the ip adress and/or token in the config.json file. But it is recommended if you have multiple gateways to choose a specific gateway!

Installation instructions

After Homebridge has been installed:

sudo npm install -g homebridge-xiaomi-alarmswitch@latest

Basic configuration

To use the plugin, add the following basic configuration to your config.json that configures homebridge in the platforms section:

{
  "platform": "AlarmSwitch",
}

After you've saved your config.json you can go ahead and launch homebridge and observe the logs.

First run

With the above configuration homebridge will print the following logs:

[WARN] No ip address and/or no token could be found in config, looking in storage..
[WARN] No gateway information in storage, requesting...
[INFO] Found new gateway, storing gateway information...
[WARN] Can not find any switches in config! Searching...
[INFO] Connected to Gateway lumi.gateway.v3 [miio:12345678]. Searching devices...
[INFO] Found 1 switch(es)!
[INFO] Please add the Device ID(s) from the switch(es) you want to control in your config.json and restart homebridge!
[INFO] (0) Device ID: 123a45678bc910
**************************************************************

    Example config.json

    {
      "platform":"AlarmSwitch",
      "name":"Alarm",
      "firstRun":false,
      "ip":"192.168.1.1",
      "token":"12345678910abcdefghijklmnop",
      "switches":{
          "123a45678bc910":{
               "type": 1,
               "disable":false,
               "resetTimer":10,
               "morseCode": [2,1,2]
          }
      }
    }

**************************************************************
[INFO] Closing connection...

Now, the plugin have stored all necessary information into your persist folder. To expose your switch, just copy the example config from your output and paste it into your config.json. If you want to enhance multiple switches, try the Advanced config.json below.

Advanced config.json (for multiple switches)

{
 "bridge": {
     ...
 },
 "platforms": [
   {
     "platform":"AlarmSwitch",
     "name":"Alarm Switch",
     "firstRun":false,
     "ip":"192.168.1.1",
     "token":"abcdefghijklmon123456789",
     "switches":{
       "123a45678bc901":{
         "type":1,
         "disable":false,
         "resetTimer":10,
         "morseCode": [1,1,2]
       },
       "124a45678bc902":{
         "type":2,
         "disable":false,
         "resetTimer":15,
         "morseCode": [2,1,1]
       }
     }
   }
 ]
}

See Example Config for more details.

Functionality of the morse code

  • You can give every switch a value for a single click and for a double click
  • The long click acts only for confirmation and checking of the morse code OR turning the switch/alarm on if the morseCode was not given or it was given wrong
  • Example: morseCode = [2,1,2] (see example-config above), this means that after entering the needed clicks in right order (in this example it is double click, single click, double click) and confirming it with a "long click", the switch/alarm will turn off, after entering a "long click" again, the switch/alarm will turn on.
  • Morse code click types: 1 = Single Click ; 2 = Double Click

Types

There are 3 types of accessories which can be assigned to the switches in the config.json.

  • Type 1: Exposes an ALARM accessory to HomeKit
  • Type 2: Exposes an VIRTUAL SWITCH accessory to HomeKit
  • Type 3: Exposes an PROGRAMMABLE SWITCH accessory to HomeKit

Note: All types except type 3 are directly connected with the gateway alarm system. That means, if you "long click" the button you have assigned in the config.json the alarm will trigger on. If you give the morse code setted in config.json in right order and confirm it with a long click the alarm will trigger off.

Type 3 (Programmable switch) uses the morse functionality, too. But it is not connected to the gateway alarm sytem. You can assign the single taps and double taps different automations or scenes in Apple HomeKit. But keep in mind, to activate the event on "single tap" you have to "long lick" the switch and for activating the "double tap" event you have to give the morse code and confirm it with a "long click". The advantage of type 3 is, it's up to you what you want to control with it.

Options

| Attributes | Required | Usage | |------------|----------|-------| | platform | Yes | Must be AlarmSwitch | | name | no | Name for the switch. Will be used as part of the accessory name. | | ip | no | IP adresse from the Gateway (if no setted in config, the plugin will automatically find the ip) | | token | no | Token from the Gateway (if no setted in config, the plugin will automatically find the token) | | firstRun | no | Manually invokes the "First run" function to list all connected devices and an example config in your terminal | | switches.id | Yes | Device ID from the switch(es) that you want to control with this plugin | | switches.type | no | Defines which type of accessory should be exposed to HomeKit (1 = Alarm, 2 = Virtual Switch, 3 = Programmable Switch, default: 1) | | switches.disable | no | If disable = true, the switch will be removed from HomeKit (Default: false) | | switches.resetTimer | no | Timer (in seconds) for resetting the switch if no input is detected (Default: 10) | | switches.morseCode | no | Order of click types (1 = single click, 2 = double click) which is needed to be clicked in right order to deactivate switch/alarm |

See Example Config for more details.

Supported clients

This plugin has been verified to work with the following apps on iOS 11.3.1:

  • Apple Home
  • All 3rd party apps like Elgato Eve etc.

Known issues / TODO

Issues ///

TODO

  • [ ] "Learn Code" Function (partial)
  • [x] Prorammable switch
  • [x] Option to set also the order of clicks
  • [x] Expose automatically all available switches
  • [x] Dynamically remove/add switches (partial)

Contributing

You can contribute to this homebridge plugin in following ways:

Pull requests are accepted.