My node-red + HomeKit + OpenHAB setup

The PM10Density shows this coming out of HomeKit:


Input is:

msg.payload={"PM10Density":4}

Thanks that seems to work for me as well!

Thanks for your help!
And for the second problem! I have found my error.

if(msg.payload.hasOwnProperty("On")) {
    if(msg.payload.On === true) {
        msg.payload = "ON";
    }
    else {
        msg.payload = "OFF";
    }
    return msg;
}

I check it like that to see if that parameter should be updated…

I’ve been searching on github and found an example where the ā€œold versionā€ of node-red homekit changed all the ā€œ.ā€ (dots), for example PM2.5Density, to ā€œ_ā€ (underscore).

I don’t know how to do pull requests github but I’ve figured out how to fix the issue.

This is the repo we are using:

We need to change line 188 of homekit.js from:

      var key = info.characteristic.displayName.replace(/ /g, '');

to:

      var key = info.characteristic.displayName.replace(/ /g, '').replace(/\./g, '_')

and line 200 from:

      var cKey = characteristic.displayName.replace(/ /g, '');

to:

      var cKey = characteristic.displayName.replace(/ /g, '').replace(/\./g, '_')

Then you’d be able to send the following into homekit in node red:

{"PM2_5Density":6}

So if you know how to make a pull request / build github code / install it in node-red… That would be a solution. Because yes I’ve confirmed the issue is indeed with the ā€œ.ā€

1 Like

Ha! I got it!

I went to this file on my pi: (sudo nano)

~/.node-red/node_modules/node-red-contrib-homekit-bridged/homekit.js

And changed lines 188 and 200 as I described above then restarted node-red. Now I can send PM2_5Density into and out from HomeKit in node-red.

Thanks!! Will try that now!

Thanks it is working now!

Another thing which I might not understand:
If I don’t specify at the brightness item that it should be ItemCommand, it won’t do anything if I change the brightness through HomeKit. If I specify it as a command, if I change the brightness, it will start a loop, because the HomeKit node always sends out the item update, even if it is not triggered through HomeKit.
Did you have a problem like this before?

Yes I tried to explain that up above. Read back through the part about

if (msg.hap.context!==undefined)

Thanks and sorry! That what I was looking for!

1 Like

Thank you! I have almost finished my setup with Node-RED (I don’t have that much stuff yet and implementing not dimmable switches are easy) just some final touches and tests needed. If anyone interested I have implemented the following not so ā€˜trivial’ things:

  • Air Quality Sensor
  • Air Purifier (with switchable Auto/Manual mode)
  • Lamp with ColorTemp and Brightness
  • Lamp with Color and Brightness
  • MotionSensor
  • HumiditySensor
  • TemperatureSensor
  • SecuritySystem
  • ContactSensor

Once you understand how HomeKit works it is not so bad to implement these things. The only key on for example Air Purifier, that it has two states, current state and target state. And after you set the target state you should send a current state to that device 1-2s later to not just show ā€˜Turning on/off…’

There is a pretty good documentation on Apple’s site which can help which commands are accepted at a device type (and which one is required and optional) and also get some info how you should send the commands.

I have also tried implementing ā€˜Speaker’ device into HomeKit, but it said that this device is not supported yet. I’m on iOS12. Would be great to control volume from HomeKit. Maybe @crxporter do you know why this happens?

Later I would like to implement camera streams and a few other things. It seems better than the builtin HomeKit…

I am pretty sure there are other apps that support these devices through HomeKit. I think elgato eve is a popular one.

I use AirPlay for my music so I’ve never been concerned with volume control but I believe it’s possible along with some basic media control if I remember right from my pre openhab days when I used homebridge.

Yes please! That would be helpful to see those devices especially for the SecuritySystem with code setup(a keypad pin code to set the state for the SecuritySystem)

btw, @rkrisi, @crxporter, one more question for you guys:
Did you guys somehow knows how to push an in app notification when the air quality gets worse?(eg. PM2.5 sensor), I believe homekit natively doesn’t support this function(only support notification for the motion, contact sensors I think?), so how do you guys deal with this?

I currently have to create a virtual ā€œcontactā€ sensor inside node-red, so that when PM2.5 gets high->trigger the virtual contact sensor to ON state->then push the in app notification… but this workflow looks stupid and needs one virtual contact per air quality sensor(I have many of them), plus notification text is saying ā€œcontact being turned ONā€, not ā€œPM2.5 poorā€, which makes other people a bit confused when receiving such in app push text.

The SecuritySystem is not fully complete yet (not tested) but I havent found an option to set PIN code for the SecuritySystem. For the air quality sensor… I’m sending the PM2.5 value to the sensor and I calculate an AirQuality value (you can see the accepted values for this in the Apple
docs, somewhere around a 0-7 scale) and send that also to the Sensor item. Today I was able to see that if the AirQuality value is greater than 3, it will trigger that sensor (like the motion sensor when detects motion). However you can’t set an automation or notification to that sensor. Weird…

This is a limitation of the HomeKit app. It only will notify for doors, windows, contact sensors, smoke/carbon monoxide sensors, motion, locks, and security systems.

The option might be available in the elgato eve app - it has several options that apple’s app doesn’t have. The ones I remember looking at are it can run an automation based on when an outlet is ā€œin useā€ and have conditions on whether that will run. I ultimately decided it wasn’t useful to have that (all much easier to do in openhab) so I didn’t pursue further options in that.

Security system has been on my list of things to play with for a while… Generally the HomeKit security system is just there to turn on/off an actual security system. I’ve looked a little at building a security system programmatically through node red and/or openhab. Maybe I’ll fiddle with that next week… if I get it I’ll come back here to add to my tutorials.

If I understood correctly - homekit doesn’t actually use codes for this. It just assumes authentication is complete if your phone (or watch) is unlocked. Similar to a garage door or door lock.

So if you’re connecting to an openhab security system for example, you’d put the pin code into node red then use homekit ā€œdisarm security systemā€ as the trigger to send that code on to node red.

Again I haven’t actually done this except for looking for like 5 minutes at to see if it works… perhaps these comments will lead you in the right direction.

Yes that’s what I thought of as well. My original implementation for openHab is the same, it won’t ask for the PIN code, you can just toggle the Arm/Disarm…
So for now, almost everything works, except I can’t control my Air Purifier and RGBW led color channels from HomeKit. These are under implementation :slight_smile: Anyway it works really good, Node-RED uses minimal resources and the HomeKit connection is stable

Hi, how to add a rtsp camera stream into node red homekit? Thanks~

As I understand this setup doesn’t work for cameras…

Here’s some information - feel free to look through it, I’d be interested if you get this working…
https://github.com/oliverrahner/node-red-contrib-homekit-bridged/issues/16

I have read this topic with great interest.
I would like to use node-red + homekit for the first time
Installed on Raspberry + Openhab + Node-red, everything is ok

I installed node-red-contrib-homekit-bridged via Manage Palette, but I see a red triangle.
The service homekit-service and homekit-bridge are not green.


Who can help me ?

I’ve never seen this error but it seems like you might already have homekit installed in node red. It’s available from various developers - take a look at your ā€œinstalled nodesā€ in the manage pallete screen to see if HomeKit is in there.

Also check your available nodes in case homekit is there and ready to use.

I had to reinstall everything, now it works
Openhab 2.4.0M5 + Node-red + node-red-contrib-homekit-bridged + Bindings Openwebnet
Node-Red … one word … fantastic !!!

Some questions :

  • How do I update my homekit after a change in the flow?
  • How do I create a button node (open Gate or garage pulse gate ON, after OFF)?
  • How to change name and pin code homekit?