HomeKit to MQTT bridge π‘π±
Depends on HAP-NodeJS by KhaosT, all credits belong to him.
This project follows the mqtt-smarthome architecture. I'm using this to control a multitude of MQTT-connected "Things" in my home automation through Siri and with HomeKit apps.
Prerequisites:
- Debian, Ubuntu, Raspbian or macOS
- Node.js 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
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]
You have to create a JSON file that defines devices and mappings from MQTT-topics and payloads to HomeKit-characteristics.
See example-homekit2mqtt.json.
Every Accessory is represented like this in the JSON file:
"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)
}
topic
- statusCarbonDioxideDetected
- statusLowBattery (optional)
- identify (optional)
payload
- onCarbonDioxideDetected
- onLowBattery (optional)
- identify (optional)
topic
- statusCarbonMonoxideDetected
- statusLowBattery (optional)
- identify (optional)
payload
- onCarbonMonoxideDetected
- onLowBattery (optional)
- identify (optional)
topic
- statusContactSensorState
- statusLowBattery (optional)
- identify (optional)
payload
- onContactDetected
- onLowBattery (optional)
- identify (optional)
topic
- statusEvent
- identify (optional)
payload
- identify (optional)
topic
- setDoor
- setLock (optional)
- statusDoor (optional)
- statusLock (optional)
- statusObstruction (optional)
- identify (optional)
payload
- doorOpen
- doorClosed
- lockUnsecured (optional)
- lockSecured (optional)
- onObstructionDetected (optional)
- identify (optional)
topic
- statusHumidity
- identify (optional)
payload
- identify (optional)
topic
- statusLeakDetected
- statusLowBattery (optional)
- identify (optional)
payload
- onLeakDetected
- onLowBattery (optional)
- identify (optional)
topic
- setOn
- statusOn (optional)
- setBrightness (optional)
- statusBrightness (optional)
- setHue (optional)
- statusHue (optional)
- setSaturation (optional)
- statusSaturation (optional)
- identify (optional)
payload
- onTrue
- onFalse
- brightnessFactor (default: 1)
- hueFactor (default: 1)
- saturationFactor (default: 1)
- identify (optional)
topic
- statusAmbientLightLevel
- identify (optional)
payload
- identify (optional)
topic
- setLock
- statusLock (optional)
- identify (optional)
payload
- lockUnsecured
- lockSecured
- identify (optional)
topic
- statusMotionDetected
- statusLowBattery (optional)
- identify (optional)
payload
- onMotionDetected
- onLowBattery
- identify (optional)
topic
- statusOccupancyDetected
- statusLowBattery (optional)
- identify (optional)
payload
- onOccupancyDetected
- onLowBattery
- identify (optional)
topic
- statusEvent
- identify (optional)
payload
- identify (optional)
topic
- statusSmokeSensorState
- statusLowBattery (optional)
- identify (optional)
payload
- onSmokeDetected
- onLowBattery (optional)
- identify (optional)
topic
- setMute
- setVolume (optional)
- statusMute (optional)
- statusVolume (optional)
- identify (optional)
payload
- muteTrue
- muteFalse
- volumeFactor (optional)
- identify (optional)
topic
- setOn
- statusOn (optional)
- identify (optional)
payload
- onTrue
- onFalse
- identify (optional)
topic
- statusTemperature
- identify (optional)
payload
- identify (optional)
topic
- setTargetTemperature
- setTargetHeatingCoolingState (optional)
- statusCurrentTemperature
- statusTargetTemperature
- statusCurrentRelativeHumidity (optional)
- setCoolingThresholdTemperature (optional)
- statusCoolingThresholdTemperature (optional)
- setHeatingThresholdTemperature (optional)
- statusHeatingThresholdTemperature (optional)
- identify (optional)
payload
- identify (optional)
config
- TemperatureDisplayUnits
topic
- setTargetPosition
- statusTargetPosition (optional)
- statusCurrentPosition (optional)
- statusPositionState (optional)
- identify (optional)
payload
- targetPositionFactor (default:
1
) - currentPositionFactor (default:
1
) - roundTarget (boolean, optional)
- positionStatusIncreasing (optional)
- positionStatusDecreasing (optional)
- identify (optional)
MIT Β© Sebastian Raff