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

hap-router

v4.1.0

Published

A Middleware HAP Router for bringing HomeKit functionality to your Home Automation.

Downloads

15

Readme

HAP Router

Image

Image

NPM npm Package Quality DeepScan grade GitHub issues GitHub closed issues Libraries.io dependency status for latest release

A Middleware HAP Router for bringing HomeKit functionality to your Home Automation.

HAP Router is a middleware NodeJS server that allows you to take advantage of Apples HomeKit technology, and bring it in to your automation ecosystem.

This is achieved by creating simple, software based accessories, that can be enrolled into HomeKit.

The difference however, compared to most implementations of this kind, is that the events that occur on them are directed (or routed) to a transport of your choice.

These transports can be a UDP broadcast, a message sent to an MQTT broker, sent to Node Red or any other automation platform.

The accessories have also been created for you, and you simply select the type of accessory you wish to create
and set their associated information.

Transports are the medium, in which the event is travelled. By default, the following transports (or routes) are as follows:

  • HTTP
  • UDP Broadcast
  • File
  • MQTT
  • Websocket
  • Console (Mainly for testing)

When I say 'by default' - what I mean here, is that you can develop your own route modules.

The transport/route will receive the following JSON payload.
There are 3 event types: characteristicUpdate, pairStatusUpdate, identifyAccessory

pairStatusUpdate

{
  accessory: {
    AccessoryID: '8D6497BC70A1',
    AccessoryType: 'Fan',
    AccessoryName: 'My Fan',
    AccessorySerialNumber: '2ND2PB12EQO3',
    Bridged: false
  },
  route: {
    Name: 'Output To Console',
    Type: 'Console Output'
  },
  eventType: 'pairStatusUpdate',
  eventData: true
}

identifyAccessory

{
  accessory: {
    AccessoryID: '8D6497BC70A1',
    AccessoryType: 'Fan',
    AccessoryName: 'My Fan',
    AccessorySerialNumber: '2ND2PB12EQO3',
    Bridged: false
  },
  route: {
    Name: 'Output To Console',
    Type: 'Console Output'
  },
  eventType: 'identifyAccessory',
  eventData: true
}

characteristicUpdate

{
  accessory: {
    AccessoryID: '8D6497BC70A1',
    AccessoryType: 'Fan',
    AccessoryName: 'My Fan',
    AccessorySerialNumber: '2ND2PB12EQO3',
    Bridged: false
  },
  route: {
    Name: 'Output To Console',
    Type: 'Console Output'
  },
  eventType: 'characteristicUpdate',
  eventSource: 'iOS_DEVICE',
  eventData: {
    characteristic: 'RotationSpeed',
    value: 62
  }
}

If you're a Home Automation Enthusiast, or just a tinkerer, Hap Router allows you to explore Homekit, and build with it.

Nice! how do I get started

The server is managed by a gorgeous looking Web User Interface (if the above images haven't already suggested so), It is a breeze to use, and at the basic level you:

  • Create a Route (Routes can be used by more than 1 accessory)
  • Create an Accessory
    • Contact Sensor
    • Air Quality Sensor
    • Intruder Alarm
    • Multisensor - Combinations of:
      • Motion
      • Lux
      • Temp
      • Humidity
    • Power Outlet
    • Basic On/Off Switch
    • Fan
    • Lock
    • Light Bulb
    • Smart TV
    • Garage Door Opener
    • Thermostat
    • Smoke Sensor
    • Leak Sensor
    • CCTV Camera
  • Enroll the device in HomeKit.
  • Have Fun.

Devices can be 'published' in 2 ways:

  • Attached to a bridge (HAP Router can also act as a Bridge)
  • Exposed as a seperate device.

If you have Enrolled HAP Router in your HomeKit environment as a bridge, then any accessories attached to this Bridge, will be seen when published. else, you enroll the accessory as a separate entity.

Manipulating accessories using non apple devices.

HAP Router has a web based API, as well as an MQTT client built in.
The web API uses BASIC HTTP Authentication, and the login details are the same as the management UI.

| Method | Address | Description | | ------ | --------------------------------- | ------------------------------------------------------- |
| GET | /api/accessories | Lists all accessories and there current characteristics |
| GET | /api/accessories/{{AccessoryID}} | Same as above but for the identified accessory |
| POST | /api/accessories/{{AccessoryID}} | Sets characteristics for the identified accessory |

To turn the fan accessory on at full speed using the web API, you will:
Send a post request to: http://{{IP ADDRESS}}:7989/api/accessories/8D6497BC70A1
And include the following POST body (with a type of application/json)

{
  'On': true,
  'RotationSpeed': 100
}

If you have enabled the MQTT client in the UI, the same message will be sent.
Just ensure the topic of the message ends with the Accessory ID.
By default the subscribed topic is HAPRouter/IN/+

Command line arguments

| Argument | Description | | --------------------------------- | ------------------------------------------------ | | reset | Completely resets HAP Router to a default state |
| installmodule {{Name}} | Installs the specified route module from NPM |
| passwd {{Username}} {{Password}} | Set the UI and API login information |

Installing and Running

Make sure you have Node >= v14.14.0 installed

Simply install via NPM npm install hap-router
to run the server just call node HAPRouter.js

Credits

HAP Router is based on the awesome HAP-NodeJS library, without it, projects like this one are not possible.

License

MIT License

Copyright (c) 2021 Marcus Davies

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.