<commit_before># homekit2mqtt 

[![License][mit-badge]][mit-url]
[![NPM version](https://badge.fury.io/js/homekit2mqtt.svg)](http://badge.fury.io/js/homekit2mqtt)
[![Dependency Status](https://img.shields.io/gemnasium/hobbyquaker/homekit2mqtt.svg?maxAge=2592000)](https://gemnasium.com/github.com/hobbyquaker/homekit2mqtt)


HomeKit to MQTT bridge 🏡📱

> Depends on [HAP-NodeJS](https://github.com/KhaosT/HAP-NodeJS) by [KhaosT](https://github.com/KhaosT), all credits belong to him.

This project follows the [mqtt-smarthome architecture](https://github.com/mqtt-smarthome).
I'm using this to control a multitude of MQTT-connected "Things" in my home automation through Siri and with HomeKit apps.

## Installation

**Prerequisites:** 

 * Debian, Ubuntu, Raspbian or macOS
 * [Node.js](https://nodejs.org) 5.10 or higher
 * If you're running on Linux, you'll need to make sure you have the libavahi-compat-libdnssd-dev package installed:
   `sudo apt-get install libavahi-compat-libdnssd-dev`


`sudo npm install -g homekit2mqtt --unsafe-perm`   
`homekit2mqtt -v debug`  

## Command Line Options

<pre>
Usage: homekit2mqtt [options]

Options:
  -v, --verbosity   possible values: "error", "warn", "info", "debug"
                                                               [default: "info"]
  -m, --mapfile     JSON file containing HomeKit Services to MQTT mapping
                    definitions. See Readme.                           [default:
           "/usr/local/lib/node_modules/homekit2mqtt/example-homekit2mqtt.json"]
  -n, --name        instance name. used as mqtt client id and as prefix for
                    connected topic                         [default: "homekit"]
  -u, --url         mqtt broker url. See
                    https://github.com/mqttjs/MQTT.js#connect-using-a-url
                                                   [default: "mqtt://127.0.0.1"]
  -s, --storagedir  directory to store homekit data
  -h, --help        Show help                                          [boolean]
  --version         Show version number                                [boolean]
  -c, --pincode                                          [default: "031-45-154"]
  -a, --username                                  [default: "CC:22:3D:E3:CE:F6"]
  -b, --bridgename                                      [default: "MQTT Bridge"]
  -p, --port                                                    [default: 51826]
                                            
                                                                 
</pre>

## Configuration

You have to create a JSON file that defines devices and mappings from MQTT-topics and payloads to HomeKit-characteristics.

See [example-homekit2mqtt.json](example-homekit2mqtt.json).


Every Accessory is represented like this in the JSON file:

```javascript
  "TemperatureSensor": {                                    // Unique Name - used to generate the accessory UUID
    "service": "TemperatureSensor",                         // HomeKit Service Type (see below)
    "name": "TemperatureSensor",                            // Display Name
    "topic": {                                              
        // ... MQTT Topic Configuration ...
    },
    "payload": {
        // ... MQTT Payload Configuration ...
    },
    "manufacturer": "Generic",                              // Additional Accessory Infos (optional)
    "model": "TemperatureSensor"                            // Additional Accessory Infos (optional)
  }
```


### Supported Service Types

#### CarbonDioxideSensor

topic

* statusCarbonDioxideDetected
* statusLowBattery (optional)
* identify (optional)

payload

* onCarbonDioxideDetected
* onLowBattery (optional)
* identify (optional)

#### CarbonDioxideSensor

topic

* statusCarbonMonoxideDetected
* statusLowBattery (optional)
* identify (optional)

payload

* onCarbonMonoxideDetected
* onLowBattery (optional)
* identify (optional)


#### ContactSensor<commit_msg>fix CarbonMonoxideSensor<commit_after># homekit2mqtt 

[![License][mit-badge]][mit-url]
[![NPM version](https://badge.fury.io/js/homekit2mqtt.svg)](http://badge.fury.io/js/homekit2mqtt)
[![Dependency Status](https://img.shields.io/gemnasium/hobbyquaker/homekit2mqtt.svg?maxAge=2592000)](https://gemnasium.com/github.com/hobbyquaker/homekit2mqtt)


HomeKit to MQTT bridge 🏡📱

> Depends on [HAP-NodeJS](https://github.com/KhaosT/HAP-NodeJS) by [KhaosT](https://github.com/KhaosT), all credits belong to him.

This project follows the [mqtt-smarthome architecture](https://github.com/mqtt-smarthome).
I'm using this to control a multitude of MQTT-connected "Things" in my home automation through Siri and with HomeKit apps.

## Installation

**Prerequisites:** 

 * Debian, Ubuntu, Raspbian or macOS
 * [Node.js](https://nodejs.org) 5.10 or higher
 * If you're running on Linux, you'll need to make sure you have the libavahi-compat-libdnssd-dev package installed:
   `sudo apt-get install libavahi-compat-libdnssd-dev`


`sudo npm install -g homekit2mqtt --unsafe-perm`   
`homekit2mqtt -v debug`  

## Command Line Options

<pre>
Usage: homekit2mqtt [options]

Options:
  -v, --verbosity   possible values: "error", "warn", "info", "debug"
                                                               [default: "info"]
  -m, --mapfile     JSON file containing HomeKit Services to MQTT mapping
                    definitions. See Readme.                           [default:
           "/usr/local/lib/node_modules/homekit2mqtt/example-homekit2mqtt.json"]
  -n, --name        instance name. used as mqtt client id and as prefix for
                    connected topic                         [default: "homekit"]
  -u, --url         mqtt broker url. See
                    https://github.com/mqttjs/MQTT.js#connect-using-a-url
                                                   [default: "mqtt://127.0.0.1"]
  -s, --storagedir  directory to store homekit data
  -h, --help        Show help                                          [boolean]
  --version         Show version number                                [boolean]
  -c, --pincode                                          [default: "031-45-154"]
  -a, --username                                  [default: "CC:22:3D:E3:CE:F6"]
  -b, --bridgename                                      [default: "MQTT Bridge"]
  -p, --port                                                    [default: 51826]
                                            
                                                                 
</pre>

## Configuration

You have to create a JSON file that defines devices and mappings from MQTT-topics and payloads to HomeKit-characteristics.

See [example-homekit2mqtt.json](example-homekit2mqtt.json).


Every Accessory is represented like this in the JSON file:

```javascript
  "TemperatureSensor": {                                    // Unique Name - used to generate the accessory UUID
    "service": "TemperatureSensor",                         // HomeKit Service Type (see below)
    "name": "TemperatureSensor",                            // Display Name
    "topic": {                                              
        // ... MQTT Topic Configuration ...
    },
    "payload": {
        // ... MQTT Payload Configuration ...
    },
    "manufacturer": "Generic",                              // Additional Accessory Infos (optional)
    "model": "TemperatureSensor"                            // Additional Accessory Infos (optional)
  }
```


### Supported Service Types

#### CarbonDioxideSensor

topic

* statusCarbonDioxideDetected
* statusLowBattery (optional)
* identify (optional)

payload

* onCarbonDioxideDetected
* onLowBattery (optional)
* identify (optional)

#### CarbonMonoxideSensor

topic

* statusCarbonMonoxideDetected
* statusLowBattery (optional)
* identify (optional)

payload

* onCarbonMonoxideDetected
* onLowBattery (optional)
* identify (optional)


#### ContactSensor
{'fraction_non_alphanumeric': 0.109375, 'fraction_numerical': 0.011592741935483871, 'mean_word_length': 1.8045936395759716, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2689041', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2200, 'n_words': 568}