MQTT API & Homebridge / HomeKit

In case anyone wants to add a SL3P to Homebridge and thus HomeKit via IP (MQTT) instead of BLE, here is a ready made config that works for me:

  1. Connect the Smart Lock to your MQTT Server (seep API instructions)
  2. Go to Homebridge Admin > Plugins, search for and install the Homebridge Mqttthing plugin
  3. Go to Homebridge Admin > Configuration and add the Smart Lock as new accessory:

This configuration is for a Smart Lock with handle on the outside and a door sensor:

  "accessories": [
        {
            "accessory": "mqttthing",
            "type": "custom",
            "name": "Eingang",
            "url": "mqtt://YOUR_MQTT_SERVER",
            "username": "nuki",
            "password": "YOUR_MQTT_PASSWORD",
            "mqttOptions": {
                "keepalive": 60
            },
            "mqttPubOptions": {
                "qos": 2
            },
            "services": [
                {
                    "type": "lockMechanism",
                    "name": "Nuki Smart Lock",
                    "topics": {
                        "getOnline": "nuki/YOUR_NUKI_ID/connected",
                        "setLockTargetState": {
                            "topic": "nuki/YOUR_NUKI_ID/lockAction",
                            "apply": "if (message == 'S') { return 2 } else { return 1 }"
                        },
                        "getLockTargetState": {
                            "topic": "nuki/YOUR_NUKI_ID/state",
                            "apply": "if (message == 1 || message == 4) { return 'S'} else if (message == 0 || message == 255) { return '?'} else if (message == 254) { return 'J' } else { return 'U' }"
                        },
                        "getLockCurrentState": {
                            "topic": "nuki/YOUR_NUKI_ID/state",
                            "apply": "if (message == 1 || message == 2) { return 'S'} else if (message == 0 || message == 255) { return '?'} else if (message == 254) { return 'J' } else { return 'U' }"
                        },
                        "getBatteryLevel": "nuki/NUKI_ID/batteryChargeState",
                        "getChargingState": {
                            "topic": "nuki/YOUR_NUKI_ID/batteryCharging",
                            "apply": "if (message == 'true') { return 'CHARGING' } else { return 'NOT_CHARGING' }"
                        },
                        "getStatusLowBattery": "nuki/YOUR_NUKI_ID/batteryCritical"
                    }
                },
                {
                    "type": "contactSensor",
                    "name": "Nuki Doorsensor",
                    "topics": {
                        "getContactSensorState": {
                            "topic": "nuki/YOUR_NUKI_ID/doorsensorState",
                            "apply": "if (message == 3) { return true } else { return false }"
                        },
                        "getStatusActive": {
                            "topic": "nuki/YOUR_NUKI_ID/doorsensorState",
                            "apply": "if (message < 16) { return true } else { return false }"
                        },
                        "getStatusTampered": {
                            "topic": "nuki/YOUR_NUKI_ID/doorsensorState",
                            "apply": "if (message == 240) { return true } else { return false }"
                        },
                        "getStatusLowBattery": "nuki/YOUR_NUKI_ID/doorsensorBatteryCritical"
                    }
                }
            ]
        }
    ],

If you have a knob at the outside it should be sufficient to change this:

                       "setLockTargetState": {
                            "topic": "nuki/YOUR_NUKI_ID/lockAction",
                            "apply": "if (message == 'S') { return 2 } else { return 1 }"
                        },

to this:

                       "setLockTargetState": {
                            "topic": "nuki/YOUR_NUKI_ID/lockAction",
                            "apply": "if (message == 'S') { return 2 } else { return 3 }"
                        },

The configs work, but are not fully tested.

Just to let you know that your example has the wrong value:

In the lower code blocks regarding door knobs (replace … by …) is “(message == ‘Secured’)”. It should be “(message == ‘S’)” instead

Skjall

Thank you. Is fixed now.

Thanks for posting the example, is my first time using MQTT, works fine for me in homebridge.
Having only one problem, that the config for the chargingState is creating warnings:

Warning: chargingState received [false] which is not in configured values {“NOT_CHARGING”:0,“CHARGING”:1,“NOT_CHARGEABLE”:2}

Have changed the config to match the warning, wondering as the state is a binary tag, how this should work?

Thanks dueso

Charging state was previously untested. I tested it now and fixed the config in the original posting.

The Smart Lock supports only the two states “charging” and “not charging”. “Not chargeable” is not supported.