My node-red + HomeKit + OpenHAB setup

Did you find any reference for this? I will try your example to turn tv on and off. Would be great if additonal inputs could be selected

Check the issues on the node red plugin GitHub page. I’ve done a quick demo and know that tv on/off as well as input selection (linked services) is working fine. The big unknown right now is volume control…

I’d search for “television”

Thanks, however I couldn’t find the demo code of yours…

Ps.: Television is working flawlessly, however I have added an InputSource linked to the Television but I can’t see it there.

I personally haven’t done any examples.

Check this issue, there are some pasted flows and some text files with flows

Thanks this is the one I have found. See my edited earlier post…

I’m trying to enable / disable HomeKit scenes from OpenHAB, but I couldn’t yet figure out how to do so. Here’s already a partially functional solution that sets a switch if a scene is enabled or disabled, so OH gets to know that the scene is active or not:

What I can’t yet get to work, is how to enable or disable a scene in HomeKit through setting a switch in OH… I tried using a stateless switch but it invariably sends “0” to the HomeKit bridge node in Node-RED.

My take on this is to use a stateless programmable switch. I put up the wiki page about it almost 2 weeks ago.

You get to choose within the switch (button) which scene is triggered by that button press. You would be able to send {"ProgrammableSwitchEvent":0/1/2} into the stateless switch node to trigger that switch button.

I like to do this in OpenHAB with a “dummy switch” that has expire binding set to like 5 seconds. Then make a rule (OH or node red) that changes ON to a number 0/1/2 and send it into your homekit node.

I’m happy to answer any questions, check out that wiki page I linked above and let me know what you think.

That was the Wiki page I stumbled upon when searching for a solution. Sadly I didn’t manage to get it work on my end. I’m using a standard “proxy” On/Off Switch item in OH which I hoped to be able to propagate to HomeKit to enable and disable a given scene.

Meanwhile I’ve seen that the Home app does indeed allow to enable a scene, but not to disable it like a tap on an enabled scene in the Home app does. So I apparently can’t use the “off” state of the switch in OH to deactivate a scene in HomeKit.

I was getting an example ready for you then I stumbled upon your issue as mentioned above - homekit won’t run an automation to “disable a scene”. Best I can tell this is a homekit limitation and scenes can’t be “turned off” from anything but pressing on the scene in the home app… It makes sense though, what would a garage door or thermostat do when it was “turned off”? If the scene is to set the thermostat to 70º, what does turning the scene off set it to?

A (cumbersome) workaround would be to make “on scenes” and “off scenes” in HomeKit. It’ll get messy pretty quickly but it would work.

I’m assuming that you have various “official homekit” devices you are trying to control from OH? Otherwise you could keep the scenes within OH / node red…

Since I was already mostly through the example, I’ll go ahead and share it here:

Note: change the inject nodes for your OH item

40%20AM

This flow gives you 2 “buttons”. I’ve set them to be “arrive home” and “leave home”. As stated above you’ve got the issue where homekit won’t automate scenes turning off.

Now you can link these buttons to set any scene in homekit, I’ve chosen “ON” to be “arrive home” and “OFF” to be “leave home”:

45%20AM

And the copy-paste for you to see my code:

[{"id":"3fdc6bf0.b7263c","type":"homekit-service","z":"c3a5a440.d4673","isParent":true,"bridge":"fc1c5b0d.cd50f8","parentService":"","name":"shutterfreak","serviceName":"StatelessProgrammableSwitch","topic":"","filter":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{}","x":790,"y":360,"wires":[[]]},{"id":"e0102731.e16d5","type":"inject","z":"c3a5a440.d4673","name":"ON from OpenHAB","topic":"","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":340,"wires":[["3350e929.8cfb7e"]]},{"id":"52408ac8.b705bc","type":"inject","z":"c3a5a440.d4673","name":"OFF from OpenHAB","topic":"","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":380,"wires":[["3350e929.8cfb7e"]]},{"id":"3350e929.8cfb7e","type":"change","z":"c3a5a440.d4673","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"{\"ProgrammableSwitchEvent\":0}","tot":"json"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"{\"ProgrammableSwitchEvent\":1}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":360,"wires":[["3fdc6bf0.b7263c"]]},{"id":"fc1c5b0d.cd50f8","type":"homekit-bridge","z":"","bridgeName":"Irrigation","pinCode":"123-45-321","port":"","allowInsecureRequest":false,"manufacturer":"Garage","model":"Pi HAT","serialNo":"3Aplus","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true}]
1 Like

I forgot to mention another issue you may run into with the proxy switch - for a normal switch (not stateless), homekit will ignore repeated commands since it remembers the state.

So you can’t send “on” twice in a row and expect the homekit automation to run for the second “on” command - it will be ignored because the light is already on.

The normal switches work like the OH item changed to on rules…

Stateless switches DO respond to repeated commands.

1 Like

@crxporter or others watching this thread, I have question/problem: it seems that HomeKit gets out of sync with the state of things, which then causes issues when I try and use Siri to update an item. For example, HK will think a switch is On, and it I issue a command “turn switch on”, nothing will happen. I believe this is because HK thinks it doesn’t need to take any action. If I were to say “turn switch off”, followed by “turn switch on”, it works, because the “off” command will cause HK to update on its end. If I recall from when I used the HK binding, HK does poll items, but I’m guessing that Node Red is caching the state (or maybe not?). Has anyone seen this problem before?

HomeKit doesn’t really poll anything. The important thing for this to be working properly is to have an openhab node which will receive the item updates then connect that to your homekit node (you’ll need a couple functions in between)

Generally the openhab node should only need to pass state changes into homekit but if it’s anpolling item, that shouldn’t cause problems.

If this doesn’t make sense- share a screenshot of your node red flow and I’ll try pointing you in the right direction!

I’m using basically the setup/functions that you posted at the start of this thread. They seem to generally work fine, in that I can control w/HK → OH w/o issue. The only issue is when HK seems to not have the proper status (sometimes after a restart, or perhaps they get a wrong status somehow?)

Also, if HK doesn’t poll, how does it get an initial status, or what happens after we restart Node RED? Does NR just push all of the statuses of the Items?

Another question around all of this (and maybe part of the problem) is how Dimmers work. I.e. Dimmers originally send their target status (i.e. if it’s turning off, it sends 0), but then will send updated status as they transition, so it looks something start: 100, then 0, then 50, then 0 (depending on timing). Some of this ends up looking a bit odd in HK, as if you turn off a Dimmer, it go from Off, to On (partially) and then eventually off.

Finally, re: polling. When I was using the OH/Homekit binding, I noticed that when you load the HK app on your phone, it would query OH for that statuses of the items. Is that not the case?

Currently the node red homekit node does not have any persistence through node red restarts. There has been some work to add this but it isn’t ready yet.

Everything will go back to the default state- off for switches and dimmers, unlocked for locks, I think closed for contacts- whatever is the “0” value. It will stay there until a different value is sent to the homekit node.

If you are restarting a lot then you will need to find a way to update the status… you can use an inject node during startup to poll openhab and use that polling to go on to homekit. Essentially you need to think of homekit nodes just showing the most recent value they got - or “0” if they haven’t gotten anything since restart. This can be a pain during setup (have to go back and switch everything on/off once to be correct) but once you’re in the running mode it’ll go for months without being touched…

No. The homekit node does not do any action when you open the app on your phone. There was briefly a PR that had another output on the node for this - but it also caused other issues and was not merged in the main code.

Regarding your dimmers - dimmers are a tough item to get just right… I recommend checking out my dimmer example, really study the functions because they’re very important in keeping the dimmer values straight… what hardware are you using?

Your dimmers might need a trigger node to avoid the repeated commands- how quick is the series of commands while they turn off? Example: if your dimmer takes 2 seconds to send everything, set a trigger node that sends nothing - waits 2.5 seconds - then sends the most recent value. That would give you a little buffer to essentially ignore all of the updates that come through while the light turns off.

If you can’t get it sorted then come back and we can dig into it more…

That may be the ideal solution for now then…I’m restarting often enough right now, so ideally things return to their proper state.

Ya, I started off with your function, except I’m not storing the value as I always want mine to rest to 100% whenever they’re turned on. In terms of hardware, I have some older GE ones as well as some Zwaveproducts ones (same hardware as Homeseer ones). The GE ones are definitely more troublesome as that was before they had proper instant status.

That may be the way to go…I’ll look into using trigger nodes.

@crxporter I wonder if there’s a better/easier way to do something like this:

…I tried to remove as much duplication in the chain as possible (i.e. having a translation method for each pair of OH/HK items), and then used the message topic to filter and allow only needing one HK -> OH node (I use the item name as the topic and then pass that through). I think I’ll need a tweak the delay node a bit, but it works roughly how I need.

Has anyone here used a HomePod in the their NR/HK setup? I’ve been having some hiccups, where if I tell my HomePod a command, it will say it’s successful, but does not perform the action (but sometimes it does). I finally had some time today to dig in deeper and have noticed a few things:

  1. When the HP doesn’t send the action, it looks NodeRED doesn’t even get the command (aka it’s not a fault of the functions/etc). I’m guessing either this is a fault of Apple, or HAP-NodeJS.

  2. Sometimes it seems that the HomeKit statuses don’t sync across all HK instances. I.e. I’ve had cases where if I use Siri on my iPhone, it will perform the action and update there, but then the Home app on my Mac or the HomePod doesn’t reflect the change.

Anyone else experience issues like this and know of a way to debug better?

Interesting. I have 3 homepods, 2 iPhone users, 2 iPad users, 2 watch users, and 2 computers (me and my wife each have each)… as long as there’s a change, the HomePod works every time.

I say “as long as there’s a change” because if homekit thinks the light is off and you say “hey Siri turn off the light” it will respond something like “that’s done” but not actually send a command because homekit thinks it’s already off.

As for syncing between devices, sometimes if changes are made on the phone, the computer doesn’t update right away, I have to quit/reopen home app to update. But generally, everything is in sync.

I do remember some growing pains at the beginning where the changes made on the phone wouldn’t update to other devices, but I think that’s a different issue…

Also - make sure you restart node red before going too much further in your troubleshooting… that nasty bug where “deploy” doesn’t work right hasn’t been fixed quite yet.

On a pi:

sudo systemctl restart nodered.service

Good to know (re: your setup working). I also tried updating node-red and we’ll see what happens.