HowTo: Node Red – Control devices with Apple HomeKit and read sensors

You can curse or idolize Apple devices, but what Apple has done very well is to integrate SmartHome components into their operating systems. For example, iOs comes with the option of controlling HomeKit devices (this is how SmartHome components are referred to in the Apple universe) via iOs.

It is also practical that you can simulate these HomeKit devices with NodeRed (and the matching Node). This allows you to control the actuators of your SmartHome from your iOs device and even display the sensor data (e.g. temperature, humidity) of the SmartHome.

The following article explains how to do this and what you need to bear in mind.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article, you should have prepared the RaspberryPi so that it is accessible via the network and controllable via SSH. NodeRed must also be installed.

The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes

Required tool:
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log into the NodeRed configuration interface

Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Installation of the required node

So that you can simulate Homekit devices, the appropriate node must of course first be installed. To do this, install the node "node-red-contrib-homekit". How to install nodes is described in the article NodeRed – Install new nodes explained.

node-red-contrib-homekit
Installation of the node "node-red-contrib-homekit".

Read motion detector

A small example node code to be informed about the status of a motion detector could look like this. To simulate the motion detector, the "Inject" nodes "true" and "false" are installed, which simulate a motion detector-is-activated signal (true) and a motion detector-is-not-activated signal (false). You can then "connect" a motion detector to these inputs, whose signals are then displayed via HomeKit.

There is also an Inject node with the name "requestOptions". If you click on it, all the properties of this HomeKit device will be displayed in the debug bar.

View of the NodeCode.
[{"id": "9998cf7e.5cf8e","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"a10e8039.50d9c","name":"BewegungsmelderBad","serviceName":"MotionSensor","x":740,"y":820,"wires":[["9dcd9414.118448"]]},{"id":"18fa3044.4d02d","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":550,"y":820,"wires":[["9998cf7e.5cf8e"]]},{"id":"2fea5d63.ae8852","type":"template","z":"5dcffcbc.bae6c4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"MotionDetected":{{payload}}}","output":"str","x":400,"y":820,"wires":[["18fa3044.4d02d"]]},{"id":"c568f55f.d8e828","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":800,"wires":[["2fea5d63.ae8852"]]},{"id":"9dcd9414.118448","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":930,"y":820,"wires":[]},{"id":"46dbd92c.8000e8", "type": "inject", "z": "5dcffcbc.bae6c4", "name":"", "topic":"", "payload": "false", "payloadType": "bool", "repeat":"", "crontab":"", "once":false, "onceDelay":0.1,"x":190,"y":840,"wires":[["2fea5d63.ae8852"]]},{"id":"39aee99f.957496","type":"comment","z":"5dcffcbc.bae6c4","name":"Bewegungsmelder als Event","info":"","x":220,"y":740,"wires":[]},{"id":"769255e1.22b44c","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":550,"y":860,"wires":[["9998cf7e.5cf8e"]]},{"id":"fdd0e0c1.c5117","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":400,"y":860,"wires":[["769255e1.22b44c"]]},{"id":"40c3c829.e4f308","type":"inject","z":"5dcffcbc.bae6c4","name":"requestOptions","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":900,"wires":[["fdd0e0c1.c5117"]]},{"id":"a10e8039.50d9c", "type": "homekit-accessory", "z":"", "accessoryName": "Sensors", "pinCode": "111-11-111", "port": "32304", "manufacturer": "Nerdiy.de", "model": "Default Model", "serialNo": "Default Serial Number", "accessoryType": "10"}]

For this NodeCode to work, you still need to configure the HomeKit accessory and the service. To do this, double-click on the "Motion detector bathroom" node. This opens the following menu.

There you set the "MotionSensor" in the "Service" section and then click on the pen icon in the "Accessory" section.
There you can/must now enter data that is important for the later configuration in iOS. Enter all the data as shown. However, you will of course change the pin code to one that only you personally know. This must also be entered in the format XXX-XX-XXX. The entry for "Port" indicates the port under which the HomeKit device can later be reached. You do not necessarily have to specify this explicitly. NodeRed will then select a random port. However, this has the disadvantage that a HomeKit device once connected to iOS is assigned a different port after a restart of NodeRed and must therefore be reconnected in iOS. You can avoid this by assigning a fixed port. For Type, it is recommended to set "SENSOR", because in this case you are also using a sensor. You can enter all other details as you wish.

Once you have entered all this data, click on "Add" and "Done" to apply this setting. The last section of this article explains how to register the HomeKit devices in iOS.


Setting the heating thermostats

Here is an example node code of how you can forward the information from a heating thermostat to a simulated HomeKit thermostat, for example. There are (in this example) two properties that are displayed on your iOS device. One is the set target temperature and the other is the current actual temperature. Both values can be simulated via the Inject nodes. At this point, you would therefore have to replace the inject nodes with the values of your real heating thermostat.

On the other hand, the values that you send to the simulated HomeKit device via the iOS HomeKit app are output via the debug node. This is where the values to be set could be forwarded to the heating thermostat.

There is also another Inject node with the name "requestOptions". If you click on it, all the properties of this HomeKit device are displayed in the debug bar.

View of the NodeCode.
[{"id":"b3001d65.5105f","type":"comment","z":"5dcffcbc.bae6c4","name":"Heizungsthermostate steuern","info":"","x":220,"y":1300,"wires":[]},{"id":"b12f3ad3.c1ef68","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"39b8cf37.35a27","name":"Heizung","serviceName":"Thermostat","x":740,"y":1480,"wires":[["3cb1fd5c.fd60c2"]]},{"id":"8d9e79f3.0de618","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":590,"y":1480,"wires":[["b12f3ad3.c1ef68"]]},{"id":"7e9e340b.320a5c", "type": "template", "z": "5dcffcbc.bae6c4","name":"Soll-Temp","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"TargetTemperature": {{payload}}}","output":"str","x":420,"y":1460,"wires":[["8d9e79f3.0de618"]]},{"id":"3cb1fd5c.fd60c2","type":"change","z":"5dcffcbc.bae6c4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.TargetTemperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":1480,"wires":[["4ca89ee5.5cd2d"]]},{"id":"4ca89ee5.5cd2d","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1130,"y":1480,"wires":[]},{"id":"129c9403.2c229c","type":"template","z":"5dcffcbc.bae6c4","name":"Ist-Temp","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"CurrentTemperature":{{payload}}}","output":"str","x":420,"y":1500,"wires":[["8d9e79f3.0de618"]]},{"id":"182c1f88.f4e04","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1600,"wires":[["129c9403.2c229c"]]},{"id":"93979569.ae6e68","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1560,"wires":[["129c9403.2c229c"]]},{"id":"f2fdf87d.6e9be8","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1520,"wires":[["129c9403.2c229c"]]},{"id":"ccdae584.bd2dd8","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1440,"wires":[["7e9e340b.320a5c"]]},{"id":"820780bd.32628","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1400,"wires":[["7e9e340b.320a5c"]]},{"id":"fafe7787.64f6c8","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1360,"wires":[["7e9e340b.320a5c"]]},{"id":"78c76a0a.b7b7f4","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":590,"y":1620,"wires":[["b12f3ad3.c1ef68"]]},{"id":"a6b574ca.dc1c98","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":440,"y":1620,"wires":[["78c76a0a.b7b7f4"]]},{"id":"63397e19.508ff", "type": "inject", "z": "5dcffcbc.bae6c4", "name": "requestOptions", "topic":"", "payload": "true", "payloadType": "bool", "repeat":"", "crontab":"", "once":false, "onceDelay":0.1,"x":260,"y":1660,"wires":[["a6b574ca.dc1c98"]]},{"id":"39b8cf37.35a27","type":"homekit-accessory","z":"","accessoryName":"Heizung","pinCode":"111-11-111","port":"32305","manufacturer":"Nerdiy.de","model":"Default Model","serialNo":"Default Serial Number","accessoryType":"9"}]

As with the motion detector, you also need to configure the HomeKit accessory and the service for this NodeCode. To do this, double-click on the "Heating" node. This will open the following menu again.

There you set the service to Thermostat. Then click on the pencil icon again in the "Accessory" section.
The setting process is the same as for the motion detector example. The only difference now is that you select a different port number than in the motion detector configuration (ideally simply the next port after the port set for the motion detector) and of course set the type to "THERMOSTAT".


Read out temperature and humidity sensors

This NodeCode example shows how to simulate a humidity and temperature sensor with the HomeKit node. The HomeKit node uses the data from "openweathermap" as its "data source". This means that the current temperatures of the location set in the openweathermap node are displayed.

As with all other examples, there is also an Inject node with the name "requestOptions". If you click on it, all the properties of this HomeKit device are displayed in the debug bar.

View of the NodeCode.
[{"id":"cc6c7b40.da9078","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"bd29e027.b0d63","name":"Temperatur","serviceName":"TemperatureSensor","x":1130,"y":1100,"wires":[["7a89e1f4.1dc75"]]},{"id":"3b22973d.547ac8","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"2dc17d94.90bc32","name":"Luftfeuchtigkeit","serviceName":"HumiditySensor","x":1140,"y":1180,"wires":[["195b33c9.57261c"]]},{"id":"7a89e1f4.1dc75","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1290,"y":1100,"wires":[]},{"id":"1c8b89c4.9270b6","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":970,"y":1120,"wires":[["cc6c7b40.da9078"]]},{"id":"a3736df8.87e9c","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":970,"y":1160,"wires":[["3b22973d.547ac8"]]},{"id":"400e1113.e2f29","type":"template","z":"5dcffcbc.bae6c4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"CurrentRelativeHumidity":"{{payload}}"}","output":"str","x":820,"y":1160,"wires":[["a3736df8.87e9c"]]},{"id":"bf9000c2.be6a8","type":"template","z":"5dcffcbc.bae6c4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"CurrentTemperature":"{{payload}}"}","output":"str","x":820,"y":1120,"wires":[["1c8b89c4.9270b6"]]},{"id":"195b33c9.57261c","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1290,"y":1180,"wires":[]},{"id":"a64825b.273ccd8","type":"change","z":"5dcffcbc.bae6c4","name":"convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.temp-273.15","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1120,"wires":[["bf9000c2.be6a8"]]},{"id":"fcbc03d9.26567","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":410,"y":1140,"wires":[["a64825b.273ccd8","553238c1.76cb68"]]},{"id":"9dbc96a3.21dcf8","type":"inject","z":"5dcffcbc.bae6c4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1080,"wires":[["2d6b39b3.dc72f6"]]},{"id":"553238c1.76cb68","type":"change","z":"5dcffcbc.bae6c4","name":"convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.main.humidity","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1160,"wires":[["400e1113.e2f29"]]},{"id":"2d6b39b3.dc72f6","type":"openweathermap","z":"5dcffcbc.bae6c4","name":"","wtype":"current","lon":"","lat":"","city":"Bochum","country":"Germany","language":"de","x":400,"y":1080,"wires":[["fcbc03d9.26567"]]},{"id":"66e6d0.bca8793","type":"comment","z":"5dcffcbc.bae6c4","name":"Klimasensoren auslesen","info":"","x":210,"y":1000,"wires":[]},{"id":"648f2c18.d730f4","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":970,"y":1200,"wires":[["3b22973d.547ac8"]]},{"id":"f5f3fc95.8afe2","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":820,"y":1200,"wires":[["648f2c18.d730f4"]]},{"id":"4a9292b6.a69abc","type":"inject","z":"5dcffcbc.bae6c4","name":"requestOptions","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":640,"y":1200,"wires":[["f5f3fc95.8afe2"]]},{"id":"31aa55d1.30fa6a","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":970,"y":1080,"wires":[["cc6c7b40.da9078"]]},{"id":"d0d837e2.311f88","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":820,"y":1080,"wires":[["31aa55d1.30fa6a"]]},{"id":"c13c8c2f.1991c", "type": "inject", "z": "5dcffcbc.bae6c4", "name": "requestOptions", "topic":"", "payload": "true", "payloadType": "bool", "repeat":"", "crontab":"", "once":false, "onceDelay":0.1,"x":640,"y":1080,"wires":[["d0d837e2.311f88"]]},{"id":"bd29e027.b0d63","type":"homekit-accessory","z":"","accessoryName":"Temperatur","pinCode":"111-11-111","port":"32300","manufacturer":"Nerdiy.de", "model": "Default Model", "serialNo": "Default Serial Number", "accessoryType": "10"},{"id": "2dc17d94.90bc32", "type": "homekit-accessory", "z":"", "accessoryName": "Humidity", "pinCode": "111-11-111", "port": "32301", "manufacturer": "Nerdiy.de", "model": "Default Model", "serialNo": "Default Serial Number", "accessoryType": "10"}]

As with the previous examples, you also need to configure the HomeKit accessory and the service for this NodeCode. To do this, double-click on the "Humidity" or "Temperature" node. This will open the following menu again.

To do this, select the "HumiditySensor" under "Service" and then click on the pencil icon in the "Accessory" section.
The setting procedure is the same as in the other examples. The port number must again be increased by one and set and the type is again set to "SENSOR".
The same applies to "Temperature". The service is now set to "TemperatureSensor". Then click on the pencil icon again in the "Accessory" section.
...and set the properties again as in the previous examples. The type must be set to "SENSOR" again. The distinction between humidity and temperature sensor is made via the previously defined service.

Control (Tasmota) lamps

Here is an example of how you can link a lamp with the Tasmota firmware to the HomeKit node so that all changes from all sources are always transferred to all input options. This makes it possible to set the color, brightness or general on/off setting in iOS or in the dashboard or via another way and at the same time the current status is also transmitted to all setting options.

In order for this NodeCode to work for you, you also need the Sonoff node and must configure it accordingly (to match your Sonoff device).

View of the NodeCode.
[{"id":"b200ae52.6003d","type":"comment","z":"5dcffcbc.bae6c4","name":"Tasmota RGB-LED-Steuerung","info":"","x":220,"y":80,"wires":[]},{"id":"a42e8481.c58778","type":"ui_switch","z":"5dcffcbc.bae6c4","name":"","label":"MiniLichterkette","group":"ca676059.8e72e","order":12,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":820,"y":220,"wires":[["fd8991ee.f7fd1"]]},{"id":"73405495.f1e9cc","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"753c6646.f99048","name":"MiniLichterkette","serviceName":"Lightbulb","x":200,"y":160,"wires":[["94a1b366.5c039","9b6599ac.52e878"]]},{"id":"94a1b366.5c039","type":"change","z":"5dcffcbc.bae6c4","name":"convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.On","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":160,"wires":[["fd8991ee.f7fd1"]]},{"id":"9e961d23.1c88b","type":"ui_colour_picker","z":"5dcffcbc.bae6c4","name":"","label":"MiniLichterkette","group":"ca676059.8e72e","format":"hsl","outformat":"object","showSwatch":true,"showPicker":true,"showValue":true,"showHue":true,"showAlpha":true,"showLightness":true,"dynOutput":"false","order":25,"width":0,"height":0,"passthru":false,"topic":"","x":200,"y":520,"wires":[["be8d6249.9bab5"]]},{"id":"6c5cc00.0eed54","type":"ui_slider","z":"5dcffcbc.bae6c4","name":"","label":"MiniLichterkette","group":"ca676059.8e72e","order":0,"width":0,"height":0,"passthru":false,"topic":"","min":0,"max":"100","step":1,"x":200,"y":380,"wires":[["2dabaae2.c1e016"]]},{"id":"20784c5.660aab4","type":"template","z":"5dcffcbc.bae6c4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"Brightness":"{{payload.l}}","Hue":"{{payload.h}}", "Saturation":"{{payload.s}}", "On": true}","output":"str","x":580,"y":520,"wires":[["e8458a57.465e58"]]},{"id":"e8458a57.465e58","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":730,"y":520,"wires":[["73405495.f1e9cc"]]},{"id":"3bd94571.32107a","type":"mqtt out","z":"5dcffcbc.bae6c4","name":"Set Hue","topic":"cmnd/MiniLichterkette/HsbColor1","qos":"","retain":"","broker":"aa8ea139.37c07","x":800,"y":280,"wires":[]},{"id":"c8c9c8e5.fccc08","type":"mqtt out","z":"5dcffcbc.bae6c4","name":"Set Saturation","topic":"cmnd/MiniLichterkette/HsbColor2","qos":"","retain":"","broker":"aa8ea139.37c07","x":820,"y":400,"wires":[]},{"id":"be920697.1bc058","type":"mqtt out","z":"5dcffcbc.bae6c4","name":"Set Brightness","topic":"cmnd/MiniLichterkette/HsbColor3","qos":"","retain":"","broker":"aa8ea139.37c07","x":820,"y":340,"wires":[]},{"id":"9b6599ac.52e878","type":"function","z":"5dcffcbc.bae6c4","name":"Split Color Values","func":"if (msg.payload.Hue!==undefined)
{
    msg.payload=msg.payload.Hue;
    return [ msg, null, null ];
}
if (msg.payload.Brightness!==undefined)
{
    msg.payload=msg.payload.Brightness;
    return [null,  msg, null ];
}
if (msg.payload.Saturation!==undefined)
{
    msg.payload=msg.payload.Saturation;
    return [ null, null, msg ];
}","outputs":3,"noerr":0,"x":470,"y":220,"wires":[["3bd94571.32107a"],["be920697.1bc058"],["c8c9c8e5.fccc08"]]},{"id":"15bdce9b.ac1781","type":"mqtt in","z":"5dcffcbc.bae6c4","name":"dimmerState","topic":"stat/MiniLichterkette/RESULT","qos":"2","broker":"aa8ea139.37c07","x":190,"y":440,"wires":[["441ae395.5fbfcc"]]},{"id":"441ae395.5fbfcc","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":350,"y":440,"wires":[["5918dc5d.eee394"]]},{"id":"5918dc5d.eee394","type":"change","z":"5dcffcbc.bae6c4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Dimmer","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":440,"wires":[["6c5cc00.0eed54"]]},{"id":"96cbb503.343228","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":530,"y":380,"wires":[["73405495.f1e9cc"]]},{"id":"2dabaae2.c1e016","type":"template","z":"5dcffcbc.bae6c4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"Brightness":"{{payload}}"}","output":"str","x":380,"y":380,"wires":[["96cbb503.343228"]]},{"id":"be8d6249.9bab5","type":"function","z":"5dcffcbc.bae6c4","name":"map","func":"msg.payload.l=msg.payload.l*100;
msg.payload.s=msg.payload.s*100;

return msg;","outputs":1,"noerr":0,"x":430,"y":520,"wires":[["20784c5.660aab4"]]},{"id":"bf36bff2.3d98f","type":"mqtt in","z":"5dcffcbc.bae6c4","name":"colorState","topic":"stat/MiniLichterkette/RESULT","qos":"2","broker":"aa8ea139.37c07","x":180,"y":580,"wires":[["d85429c0.4501c8","852254eb.6c9668"]]},{"id":"852254eb.6c9668","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":330,"y":580,"wires":[["be6203d4.c9e66"]]},{"id":"4a52a0ca.93eac","type":"function","z":"5dcffcbc.bae6c4","name":"convert Color","func":"//var input=msg.payload.HSBColor;
let values=msg.payload.HSBColor.split(",");
msg.payload.h=values[0];
msg.payload.s=values[1]/100;
msg.payload.l=values[2]/100;

return msg;","outputs":1,"noerr":0,"x":610,"y":580,"wires":[["9e961d23.1c88b"]]},{"id":"be6203d4.c9e66","type":"switch","z":"5dcffcbc.bae6c4","name":"","property":"payload.HSBColor","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":580,"wires":[["db3e37fb.97a5f8","4a52a0ca.93eac"]]},{"id":"fd8991ee.f7fd1","type":"Sonoff device","z":"5dcffcbc.bae6c4","mode":"0","broker":"665cb0c4.3e438","device":"MiniLichterkette","name":"","onValue":"ON","offValue":"OFF","cmdPrefix":"cmnd","statPrefix":"stat","telePrefix":"tele","x":810,"y":160,"wires":[["a42e8481.c58778"]]},{"id":"b3771bf1.2acd78","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":550,"y":120,"wires":[["73405495.f1e9cc"]]},{"id":"5dbdb6ee.9ac9f8","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":400,"y":120,"wires":[["b3771bf1.2acd78"]]},{"id":"97278e2f.5d65a","type":"inject","z":"5dcffcbc.bae6c4","name":"requestOptions","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":120,"wires":[["5dbdb6ee.9ac9f8"]]},{"id":"d85429c0.4501c8","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":350,"y":640,"wires":[]},{"id":"db3e37fb.97a5f8","type":"debug","z":"5dcffcbc.bae6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":590,"y":640,"wires":[]},{"id":"ca676059.8e72e","type":"ui_group","z":"","name":"Mini-Lichterkette","tab":"d651a8eb.fefb38","disp":true,"width":"6","collapse":false},{"id":"753c6646.f99048","type":"homekit-accessory","z":"","accessoryName":"Lampen","pinCode":"111-11-111","port":"32302","manufacturer":"Nerdiy.de","model":"Default Model","serialNo":"Default Serial Number","accessoryType":"5"},{"id":"aa8ea139.37c07","type":"mqtt-broker","z":"","name":"Server-Mqtt","broker":"server.fritz.box","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"665cb0c4.3e438","type":"mqtt-broker","z":"","name":"","broker":"server.fritz.box","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"d651a8eb.fefb38","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

As with the previous examples, you also need to configure the HomeKit accessory and the service for this NodeCode. To do this, double-click on the node (in this case) "Mini light chain". This opens the following menu again.

Once there, first set the service to "Lightbulb" and then click on the pen icon in the "Accessory" section.
The settings here are the same as in the previous examples. Only the type is set to "LIGHTBULB" and of course the port number must be adjusted again.

Control sockets

This example shows you how you can simulate a SmartHome socket with the HomeKit node. A SonoffS26 socket is used here which (like the lamp in the previous example) is "equipped" with the Tasmota firmware. How to program such a socket with the Tasmota firmware and control it via Node-Red is described in the article Tasmota – Flash Sonoff S26 socket with Tasmota firmware described.

As with all other examples, there is also an Inject node with the name "requestOptions". If you click on it, all the properties of this HomeKit device are displayed in the debug bar.

View of the NodeCode.
[{"id":"d6d0d8e6.785448","type":"comment","z":"5dcffcbc.bae6c4","name":"Steckdose","info":"","x":180,"y":1800,"wires":[]},{"id":"bad38f27.a93b4","type":"ui_switch","z":"5dcffcbc.bae6c4","name":"","label":"Steckdose","group":"16663fb4.9e351", "order":20, "width":0, "height":0, "passthru":false, "decouple": "true", "topic":"", "style":"", "onvalue": "true", "onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":670,"y":1920,"wires":[["f1118c1c.95804"]]},{"id":"f1118c1c.95804","type":"Sonoff device","z":"5dcffcbc.bae6c4","mode":"0","broker":"1fafbb1c.a2df75","device":"SonoffS26","name":"","onValue":"ON","offValue":"OFF","cmdPrefix":"cmnd","statPrefix":"stat","telePrefix":"tele","x":660,"y":1860,"wires":[["bad38f27.a93b4"]]},{"id":"a4cdda.44b67228","type":"homekit-service","z":"5dcffcbc.bae6c4","accessory":"b7e7d023.40f38","name":"Steckdose","serviceName":"Outlet","x":250,"y":1860,"wires":[["307b902a.ca26b"]]},{"id":"307b902a.ca26b","type":"change","z":"5dcffcbc.bae6c4","name":"convert","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.On","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1860,"wires":[["f1118c1c.95804"]]},{"id":"fb3c28d1.cb8da8","type":"json","z":"5dcffcbc.bae6c4","name":"","property":"payload","action":"","pretty":false,"x":570,"y":1980,"wires":[["a4cdda.44b67228"]]},{"id":"811d7998.a861e8","type":"template","z":"5dcffcbc.bae6c4","name":"options","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{"foo":"bar"}","output":"str","x":420,"y":1980,"wires":[["fb3c28d1.cb8da8"]]},{"id":"6bdad444.d1270c","type":"inject","z":"5dcffcbc.bae6c4","name":"requestOptions","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":1980,"wires":[["811d7998.a861e8"]]},{"id":"16663fb4.9e351","type":"ui_group","z":"","name":"Licht","tab":"e5c99d4.147226","order":2,"disp":true,"width":"6","collapse":false},{"id":"1fafbb1c.a2df75", "type": "mqtt-broker", "z":"", "name": "Server-Mqtt", "broker": "server.fritz.box", "port": "1883", "clientid":"", "usetls":false, "compatmode":true, "keepalive": "60", "cleansession":true, "birthTopic":"", "birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b7e7d023.40f38","type":"homekit-accessory","z":"","accessoryName":"Steckdosen","pinCode":"111-11-111","port":"32303","manufacturer":"Nerdiy.de","model":"Default Model","serialNo":"Default Serial Number","accessoryType":"7"},{"id":"e5c99d4.147226","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]

Here too (surprise 🙂 ) you need to configure the HomeKit accessory and the service, as in the previous examples. To do this, double-click on the "Socket" node. This will open the following menu again.

There you first set the service to "Outlet" and then click on the pencil icon in the "Accessory" section.
The settings here are the same as in the previous examples. Only the type is set to "OUTLET" and of course the port number must be adjusted again.

Find out the setting options and properties of the devices

Some examples have an Inject node with the name "requestOptions". You can use this to display the available properties of the respective HomeKit node. You can then use these properties to set the simulated HomeKit device. For example, the HomeKit node that controls the "mini fairy lights" has the option of setting the ColorTermperature. If you set the property, the corresponding value is displayed in HomeKit.

Overview of the properties of the HomeKit nodes used in these examples.

Setup on the iPhone

Once you have created your desired HomeKit devices in NodeRed, it is now time to register them on the iOS device. In this section you will be guided (somewhat) step by step through the registration process. As this sometimes involves a lot of pictures, the following steps are summarized as slide shows.

To do this, open the "Home" app on your iOS device (in this case an iPhone).
In the "factory settings", no HomeKit devices are registered here yet. This is why you will see the "Add Accessory" button at the bottom. Clicking on it will take you to the menu where you can add new HomeKit devices.

Air humidity

To start the registration of a humidity sensor, click on "Add Accessory" as indicated in the previous step.

This slideshow requires JavaScript.

Heating thermostats

To start the registration of the heating thermostat, click on "Add Accessory" - as in the previous step - and then on "Don't Have a Code or Can't Scan".

This slideshow requires JavaScript.

(Tasmota) lamp

To start the registration of the lamp, click on "Add Accessory" - as in the previous step - and then on "Don't Have a Code or Can't Scan".

This slideshow requires JavaScript.

(Tasmota) socket

To start the registration of the socket, click on "Add Accessory" - as in the previous step - and then on "Don't Have a Code or Can't Scan".

This slideshow requires JavaScript.

Temperature sensor

To start the registration of the temperature sensor, click on "Add Accessory" - as in the previous step - and then on "Don't Have a Code or Can't Scan".

This slideshow requires JavaScript.

Motion detector

To start the registration of the motion detector, click on "Add Accessory" - as in the previous step - and then on "Don't Have a Code or Can't Scan".

This slideshow requires JavaScript.


You may have already noticed: With this iOs Node you have all kinds of possibilities. Just try it out a bit. If you have any questions, please leave them in the comments.

Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

4 comments

  1. Hi Nerdy,

    cool site and cool projects! I have already implemented a few things in my smart home (KNX, bridge to HomeKit, Node Red etc.) and still have a lot planned. Been trying to use the HomeKit Bridge from Node Red for a while. I also get the nodes set up and configured so that I can then set up a device in the HomeKit app as a test. Unfortunately, the whole thing is not stable, the connection breaks regularly and Node Red also restarts itself regularly, ie something in the Homekit bridge node causes the crash. Do you also have this problem or do you have an idea what could be the reason?

    Greetings Turner

    1. hey gymnast,
      thanks 🙂
      Unfortunately I don't know exactly what could be the reason. However, in the past I had the problem that my NodeRed installation kept restarting for some reason. To make debugging a little easier, I created a flow that saves the last journal of the NodeRed process after restarting NodeRed. So you can see quite well at which point NodeRed crashed and fix the error. 🙂
      You can find information about this here: https://nerdiy.de/howto-nodered-automatisches-speichern-des-nodered-journals-nach-dem-start-von-nodered-zu-debugging-zwecken/

      Best regards
      Fabian

  2. Hello Fab,

    really cool site. I'm currently working on the flow for the heating thermostats, the import also worked wonderfully. I'm kind of stuck right now and have a few questions:

    1. Can I use any heating thermostat or does it have to be an Apple Homkit capable since I am simulating a Homekit?

    2. how does Node red "know" that I have a thermostat, doesn't it have to be transferred to the WLAN somehow?

    3. Depending on the thermostat, do I need the appropriate bridge, or can this be done without the appropriate bridge?

    Thank you in advance for your replies, as I said, I don't know what to do next.

    Maybe you can also email me detailed instructions on how to proceed with the new thermostat from start to finish.

    I'd be happy to hear from you.

    LG 🙂

    1. Hi Daniel,
      1. In principle, this can be any heating thermostat, yes. Of course, it must be supported by NodeRed or be able to be controlled in some other way. 🙂
      2. Depending on what kind of thermostat you have, it is either integrated via DECT (with the Fritzbox), zigbee or another standard. Sometimes you also need a suitable gateway.
      3. If you already have a FritzBox, I recommend one of the radiator thermostats that is compatible with the FritzBox. Information (including how to integrate it) can be found here, for example: https://nerdiy.de/howto-nodered-fritzbox-heizkoerperthermostat-aus-nodered-steuern/

      I hope this will help you. Otherwise please let me know. 🙂
      Best regards
      Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.