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

You can curse or deify about Apple devices, but what Apple has solved very well is the integration of SmartHome components in their operating systems. So iOs brings directly brings with HomeKit devices (as the SmartHome components in the Apple universe are called) a easy way to control devices via iOs.

In addition, it is practical that you can use NodeRed (and the matching node) to simulate these HomeKit devices. So you can control the actuators of your SmartHome from your iOs device and even show you the sensor data (for example, temperature, humidity) of the SmartHome.

How to do that and what you have to pay attention to is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/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 shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
Before you start with this article, you should have prepared the RaspberryPi so far that it can be reached via the network and controlled by SSH. In addition, NodeRed must be installed.

The following three articles describe what to do to prepare the RaspberryPi:
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The First Configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes

Required tools:
-no-

Required material:

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


Log in to the NodeRed configuration interface

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

View of the login screen. Here you have to enter the login details that you entered during the configuration of the login. Information about this can be found in the article NodeRed - User Login Setup.

Installation of the required node

So that your home kit can simulate devices must of course first be installed the appropriate node. Install the node “node-red-contrib-homekit”. How to install your Nodes is explained in the article NodeRed – Install New Nodes.

node-red-contrib-homekit
Installation of the node “node-red-contrib-homekit”.

Read out motion detector

A small sample Node code to get the status of a motion detector might look like this. To simulate the motion detector, the “Inject” nodes “true” and “false” are built in, which simulate a motion detector is on (true) signal and a motion detector is off (false) signal. You can then “connect” a motion detector to these inputs, whose signals are then displayed via HomeKit.

There is also an inject node named “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":"Sensoren","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 have to configure the HomeKit-accessory and the service. Click twice on the node “BewegungsmelderBad”. This will open the following menu.

In the “Service” section, you set the “MotionSensor” and then click on the pencil icon in the “Accessory” section.
There you can/must enter now data, which are important for the later configuration in iOS. Enter all data as shown. Of course, you change the pin code to one that only you know personally. This must also be entered in the format XXX-XX-XXX. The specification in “Port” indicates under which port the HomeKit device can be reached later. You do not necessarily have to specify this explicitly. Then NodeRed selects a random port. However, this has the disadvantage that a once connected to iOS HomeKit device after a restart of NodeRed gets assigned a different port and thus must be reconnected in iOS. By assigning a fixed port you avoid this. For type it is recommended to set “SENSOR”, because in this case you also use a sensor. All other information can be entered at your discretion.

If you have entered all these data you click on “Add” and on “Done” to take over this setting. The last section of this article explains how to setup your HomeKit devices into iOS.


Set heating thermostats

Here’s an example Node code, such as how to pass information from a Heater Thermostat to a simulated HomeKit thermostat. There are (in this example) two properties that are displayed on your iOS device. Once the set target temperature and the current actual temperature. Both values can be simulated via the injection nodes. At this point, you would have to replace the Inject nodes with the values of your real heating thermostat.

On the other hand, the values that you send via the iOS HomeKit app to the simulated HomeKit device are output via the debug node. At this point, the forwarding of the values to be set to the heating thermostat could happen.

In addition, there is also an injection 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":"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 have to configure the HomeKit accessory and the service with this NodeCode. Click twice on the node “Heating”. This will open the following menu again.

There you put the service on thermostat. Then you click on the pen icon again in the category “Accessory”.
The setting is again the same as for the motion detector example. The only difference is that you choose a different port number than for the motion detector configuration (best just the next port after the port set at the motion detector) and of course set the type to “THERMOSTAT”.


Read 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 of “openweathermap” as “data source”. That means, the current temperatures of the location set in the openweathermap node are displayed.

As with all other examples, there is also an injection 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":"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":"Luftfeuchtigkeit","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 Service for this NodeCode. Click twice on the node “Luftfeuchtigkeit” or “Temperatur”. This will open the following menu again.

Select under “Service” the “HumiditySensor” and then click in the category “Accessory” on the pencil icon.
The setting is again as in the other examples. The port number must be increased by one and and the type needs to be set to “SENSOR” again.
The same applies to the “temperature”. There, the service is now set to “TemperatureSensor”. Then you click on the pen icon again in the category “Accessory”.
… 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 happens over the previously defined service.

(Tasmota) lamps control

Here’s an example of how you can associate a Tasmota firmware lamp with the HomeKit node so that any changes from any source 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 another way and at the same time the current status is also transferred to all setting options.

In order for this NodeCode to work for you, you also need the Sonoff Node and you have to configure it accordingly (according to 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)\n{\n    msg.payload=msg.payload.Hue;\n    return [ msg, null, null ];\n}\nif (msg.payload.Brightness!==undefined)\n{\n    msg.payload=msg.payload.Brightness;\n    return [null,  msg, null ];\n}\nif (msg.payload.Saturation!==undefined)\n{\n    msg.payload=msg.payload.Saturation;\n    return [ null, null, msg ];\n}","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;\nmsg.payload.s=msg.payload.s*100;\n\nreturn 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;\nlet values=msg.payload.HSBColor.split(\",\");\nmsg.payload.h=values[0];\nmsg.payload.s=values[1]/100;\nmsg.payload.l=values[2]/100;\n\nreturn 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 Service for this NodeCode. Click twice on the node (in this case) “MiniLichterkette”. This will open the following menu again.

Once again, you set the service to “Lightbulb” and then click on the pencil icon in the “Accessory” section.
The settings here are again to handle as in the previous examples. Only the type you put on “LIGHTBULB” and of course the port number must be adjusted again.

Control sockets

This example shows you how to simulate a SmartHome outlet using the HomeKit node. Here is a SonoffS26 socket used which (as well as the lamp in the previous example) is “stocked” 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 – Flashing Sonoff S26 with Tasmota Firmware.

As with all other examples, there is also an injection 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":"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}]

Again, you have to (surprise :)) – as in the previous examples – configure the Home Kit Accessory and the service. Click twice on the node “socket”. This will open the following menu again.

Once again, you set the service to “Outlet” and then click on the pencil icon in the “Accessory” section.
The settings here are again to handle as in the previous examples. Only the type you set to “OUTLET” and of course, the port number must be adjusted again.

Find out settings options and properties of the devices

Some examples have an inject node named requestOptions. About this you have the opportunity to display the available properties of each HomeKit node. You can then use these properties to set the simulated HomeKit device. For example, with the HomeKit node, which controls the “miniLichterkette”, there is the possibility to set the ColorTermperature. If you set the property, the corresponding value will be displayed in HomeKit.

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

Setup on the iPhone

If you have created your desired HomeKit devices in NodeRed, it is now necessary to log them on the iOS device. In this section, you will (reasonably) be guided through the registration process step by step. Since this sometimes includes a lot of pictures, the following steps are summarized as slide shows.

Open on your iOS device (in this case an iPhone), the app “Home”.
In the “factory state”, no HomeKit devices are registered here yet. That’s why the “Add Accesory” button in the lower area is the only button here. Clicking on it will take you to the menu where you can add new HomeKit devices.

Humidity

To start logging in an air humidity sensor, click on “Add Accessory” as indicated in the previous step.

This slideshow requires JavaScript.

Heating thermostats

In order to start the registration of the heating thermostat you click – as in the previous step – on “Add Accessory” and then on “Do not Have a Code or Can not Scan”.

This slideshow requires JavaScript.

(Tasmota-) Lamp

To start the setup of the lamp click – as in the previous step – on “Add Accessory” and then on “Do not Have a Code or Can not Scan”.

This slideshow requires JavaScript.

(Tasmota-) outlet

To start the registration of the socket click – as in the previous step – on “Add Accessory” and then on “Do not Have a Code or Can not Scan”.

This slideshow requires JavaScript.

Temperature sensor

To start the registration of the temperature sensor click – as in the previous step – on “Add Accessory” and then on “Do not Have a Code or Can not Scan”.

This slideshow requires JavaScript.

Motion detector

To start logging in the motion detector, click on “Add Accessory” and then “Do not Have a Code or Can not Scan” as in the previous step.

This slideshow requires JavaScript.


You may already have noticed: With this iOs node you have all kinds of possibilities. Just try something around. If you have questions you can leave them in the comments.

I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. 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 appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *