My node-red + HomeKit + OpenHAB setup

Could you please talk more about stability?

  • how about remote controlling? does it always reports the status smoothly when using 4g?
  • does it often reports “updating” or “unresponsive” even when LAN control?

Thanks!

this is really cool! Thanks for sharing. Now I will have almost every oh item available in HomeKit as well!

Stability is fantastic. It’s been more stable than most of my native HomeKit items actually - I have an ecobee, chamberlain garage door hub, and a few iHome plugs. Each of those native items has been “updating” or “no response” 2 or 3 times over the last few months. The node-red setup has not had any problems.

These problems are not happening. Any time I have a connection to HomeKit I am able to control all of my items as expected. I think once or twice our power went out and the Apple TVs didn’t reconnect properly so I had to go home to restart them but that was a HomeKit issue and not an issue with this setup (ALL of my devices including native HomeKit were offline).

The “updating” is only ever for 1-2 seconds while it updates. “no response” doesn’t happen.

I’m trying to think of any other issues I’ve had but after the original setup there really have been no problems. One thing I’ll probably add is a little delay buffer between my HomeKit dimmers and OpenHAB - when I slide the little slider HomeKit will send 3-4 updates depending how “slowly” I’m sliding it. I think it will smooth out my system if I put a half-second delay on those and only send the last one so that my light (Insteon) only gets one update…

Thank you for the details, really awesome job!
May I also ask you how many devices(including none-homekit wifi devices) in your local network? Which router are you using?

I am having very deep troubles about “updating” and become “unresponsive”, when I in LAN, everything working very well, no delay at all! Then I disconnect the wifi and go to 4g, the remote homekit is also working very well, however if I stay 4g and wait around 20-30 minutes then reopen the home app, everything becomes “updating”, and need to wait 2-3min(during the wait time all devices report “updating” and finally report “unresponsive”), then after 2-3 minutes, I reopen the home app, everything back to normal(I can watch real time streaming without any issue).

In this case, if I leave wifi and wait long enough(20-30min), the problem happen. But if I wait within 20min(say 17min, then I reopen the home app in 4g remote mode), everything still working smoothly. no “updating” at all…
So I am facing this problem like half year and still don’t have any clue of how this strange thing happen.

I am guessing it’s the router’s problem, I am running openwrt router with dnsmasq, somehow it may cause this strange problem, something related to dnsmasq(still guessing). No idea at all!

Do you have any idea of what cause this problem? Thanks!

I can think of 20 wireless devices connected in my house. Of those, 2 are actual “genuine HomeKit” devices, 2 are HomePods, 7 are phone/watch/tablet/computer, 1 is a sprinkler controller, and the others are various ESP8266 or Raspberry Pi devices. Router is a TP-Link C5400 running default firmware. I’ve been thinking of switching to openwrt - but you’re making me reconsider that a bit…

I’ve made it a point to keep things off wifi as much as possible. We have 6 or 7 things connected with ethernet - including my OpenHAB pi. I use Insteon light switches so there’s no wifi involved there.

When I open up the home app and scroll through my rooms there’s maybe a 1-2 second time where everything says “updating” then boom - all of the accurate states of everything.

Are all of your homekit devices openhab devices? Or do you have some native ones? Do any update more reliably than others? I find there are times when my garage doors (native homekit) is a little behind my node-red devices but not by much. For some reason my ecobee thermostat (native homekit) is the most spotty, it will drop out for 5-10 minutes at times and the only way to kick it back is restart the home app on my phone.

Try setting up a “dummy device” in node-red and adding it to your homekit then watch if it goes offline with the others. This could help pinpoint where the issues are coming from.

The only other problems I’ve had is in spotty signal areas but that’s to be expected right? Nobody expects these things to work in the middle of nowhere when cell service is lackluster at best.

Here are some of the other threads and comments that helped me get everything put together.

For anyone wanting colored homekit lights - start here. My brightness function was based on this post.

For a thermostat, see this post (copy and paste the line of code into your node-red)

For those with oscillating / multi-speed fans see this post for an example of sending speed and oscillation commands to HomeKit:

If anyone has interesting in building out a relay-based sprinkler flow, let me know. I think it would be fun to help put that code together!

Thanks everyone who’s posted things that I’ve copied and modified. There’s so much potential here. For my house we use HomeKit for everything - to the point my 4 year old controls our window, music, lights, and more with our HomePod. I need to not teach her about the sprinkler option - she’d be all over that one to go jump on the trampoline with sprinklers on!

NOTE
Many of these examples use an older version of the node-red homekit plugin which does NOT add as a bridge. Each item adds individually. I just thought it would be cool to put together a nice starting point for people wanting to do homekit+node-red.

One more question.
Do you have a ‘real server’ for your server or you run OH + Node-RED on RPi?

It all runs together on a Pi 3 B+. My MQTT broker is on that same Pi.

I considered splitting it up when I added my node red stuff - but monitoring the ram and cpu everything runs very comfortably. 3-4 weeks uptime shows 85-90% memory usage and low cpu usage (always under 5% when I run “uptime”)

Thanks, same setup, so I’ll install it on that as well :slight_smile: Now I’m just playing on it in a VM.

Just checked again. I’ve got 14% free ram and my 15-minute cpu load is 1%.

I keep a pi running at work so I can try stuff before putting it in my house. Have to keep my family happy!

So I have started implementing my HomeKit with Node-RED.
I have a few questions, maybe you know the answer to some of them.

  • I wanted to implement my Air Quality Sensor. I always get this response, I don’t know where should I specify setValue (tried outside payload, in payload…)
"TypeError: Cannot read property 'setValue' of undefined"
  • I went for a different approach for dimmers, because I have a lamp for example which has ColorTemp as well. So I read all values in, HomeKit accepts multiple jsons with only one value in it. For example: Lamp_Power sends ON for the HomeKit item, Lamp_Bright sends the Brightness… Now I want to do this for setting the values through HomeKit. I wanted to check if the output has the attribute and if yes, just pass back to the power or brightness item.
msg.payload.hasOwnProperty("Brightness")

It should work, because HomeKit puts just one value to the output, however Node-RED ignores that check and passes all values to the OH item. Why? Node-RED doesn’t have this hasOwnProperty function?

I’m really new to Node-RED and Javascript as well… Some items can be easily implementable (like TempSensor, MotionSensor, LightSwitch) but some of them is harder…

Thanks!

Hi i am also using node red + OH + homekit

but i am using homekit binding from OH, items are defined on OH
and rules will set Home items ,just on and will bring them back to off

i find homekit to be unstalbe so i dont like the cntorl from there , i just use it for siri and nothing else
or maybe backup when cloud is down

Are you doing this as an “air quality” sensor or as an “air purifier” type? What is the “setValue”? Is this from OpenHAB? Best recommendation I can say is watch what’s coming from OpenHAB into Node-red with a “debug” node then see below for formatting on how to write your function to change the openhab information on to homekit.

Air purifier nodes can take input/output of the following types (found by sending a nonsense JSON input and watching debug):

  • Name, Active, CurrentAirPurifierState, TargetAirPurifierState, LockPhysicalControls, Name, SwingMode, RotationSpeed

Air quality sensors can take these:

  • Name, AirQuality, StatusActive, StatusFault, StatusTampered, StatusLowBattery, Name, OzoneDensity, NitrogenDioxideDensity, SulphurDioxideDensity, PM2.5Density, PM10Density, VOCDensity, CarbonMonoxideLevel, CarbonDioxideLevel

The input/output for the HomeKit node would look like:

{"Active":true}
{"TargetAirPurifierState":1} //0 means off, 1 means idle, 2 means purifying air
{"CurrentAirPurifierState":} //0 means off, 1 means idle, 2 means purifying air
{"OzoneDensity":240}//range is 0 to 1000

Note for things with Target and Current state options you need to send both to/from homekit if you want homekit to show properly.

A great resource for seeing what can go in and out of HomeKit is the “HomeKit Accessory Protocol” document available through Apple developer program (free, have to register). If you’d like some help getting this hit me up with a private message I might be able to help. :wink:

The whole purpose of the functions is to change openhab terminology and format to homekit terminology and format.

I think that statement might help you figure out your next question as well:

“hasOwnProperty” is from openhab, right? You’ll need to “translate” that in node-red before sending it to homekit. Then if you get a brightness 45 from OH you send to homekit:

{"Brightness":45}

You can definitely do this but to watch for the output from HomeKit into the node-red system (msg.payload), you’ll be looking for:

msg.payload.Brightness != undefined

That would mean HomeKit is sending a brightness number and you can take it and send it back to OpenHAB to do with as you please.

It took me 2 or 3 days fiddling with my functions, watching input/output between openhab and homekit and node-red before I got comfortable with everything. I think that homekit protocol document would be helpful for you to find which items take which inputs.

Hopefully something here sends you in the right direction to make some progress. You can also export your flows and paste them here - then I (or someone else) could see and comment on which adjustments could be made.

I’m doing with Air Quality Sensor type. Injecting something only returns values like this:

Try one of these: Name, AirQuality, StatusActive, StatusFault, StatusTampered, StatusLowBattery, Name, OzoneDensity, NitrogenDioxideDensity, SulphurDioxideDensity, PM2.5Density, PM10Density, VOCDensity, CarbonMonoxideLevel, CarbonDioxideLevel

The data is from openHab, it is just a plain number. If I setup a node, after transforming for HomeKit, I can see something like this:

payload : {
                PM2.5Density : "4"
}

Well. I just tried to make a dummy Air Quality sensor on my node-red test system and I get the same error:

"TypeError: Cannot read property 'setValue' of undefined"

…I’m restarting node-red…standby…

I have added items which is almost the same as Air Quality Sensor, like Humidity sensor, it works as it should. Only this one has this problem! Maybe a bug?

Thanks for your help!

I think it might have something to do with the “.” in the “PM2.5” - I’m trying with PM10Density

The PM10Density shows this coming out of HomeKit:

image
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