Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcus-j-davies/hap-router
A Middleware HAP Router for bringing HomeKit functionality to your Home Automation.
https://github.com/marcus-j-davies/hap-router
accessory apple automation device hap hap-nodejs home homekit ios smart virtual
Last synced: about 1 month ago
JSON representation
A Middleware HAP Router for bringing HomeKit functionality to your Home Automation.
- Host: GitHub
- URL: https://github.com/marcus-j-davies/hap-router
- Owner: marcus-j-davies
- License: mit
- Created: 2021-04-08T15:58:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-19T09:19:57.000Z (almost 2 years ago)
- Last Synced: 2024-05-01T17:18:32.229Z (7 months ago)
- Topics: accessory, apple, automation, device, hap, hap-nodejs, home, homekit, ios, smart, virtual
- Language: JavaScript
- Homepage:
- Size: 6.94 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# HAP Router
![Image](./Logo.png)![Image](./Screenshot.png)
![NPM](https://img.shields.io/npm/l/hap-router)
![npm](https://img.shields.io/npm/v/hap-router)
[![Package Quality](https://packagequality.com/shield/hap-router.svg)](https://packagequality.com/#?package=hap-router)
[![DeepScan grade](https://deepscan.io/api/teams/17652/projects/21016/branches/591318/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=17652&pid=21016&bid=591318)
![GitHub issues](https://img.shields.io/github/issues-raw/marcus-j-davies/hap-router)
![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/marcus-j-davies/hap-router)
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/hap-router)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](./RouteModule.md) route modules.
The transport/route will receive the following JSON payload.
There are 3 event types: **characteristicUpdate**, **pairStatusUpdate**, **identifyAccessory****pairStatusUpdate**
```javascript
{
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**
```javascript
{
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**
```javascript
{
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**)```javascript
{
'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 installedSimply 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](https://github.com/homebridge/HAP-NodeJS)
library, without it, projects like this one are not possible.## License
MIT LicenseCopyright (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.