HomeKit debugging/development

Discussions about RaZberry - Z-Wave board for Raspberry computer
S'pht'Kr
Posts: 9
Joined: 20 Mar 2015 22:14

HomeKit debugging/development

Post by S'pht'Kr »

I'm looking to do some debugging and probably contribute some code to the HomeKit module, but I'm just digging in and am confused about a few things:
  • I see the automation/modules/HomeKitGate/index.js, and can understand what's going on there. But I also see modules/modhomekit.so, which is an ELF library, and clearly didn't come from any JavaScript...what is the relationship between these two, and does modhomekit.so do anything at all? Is it a plugin for z-way or the HTTP server you're using? Is the source code for this available? Do I need it?
  • If I edit the HomeKitGate/index.js file, what should I do to have the changes loaded? Will z-way server notice the change, or do I need to restart it or do something else?
FWIW, the problem I'm trying to fix/troubleshoot is with Siri--I'm using HomeKitDemo and MyTouchHome on my iPhone and both can control the 4 switches in my network just fine!...but Siri is totally confused, and seems to work with only one device, and usually it's not the one whose name I ask for--it's like she's conflating all the bridged devices as one, and the one that gets the message is undefined.

What I'd like to add is thermostat support and improved temperature sensor support, and possibly look into RGB support.
gregharewood
Posts: 4
Joined: 04 Sep 2015 11:37

Re: HomeKit debugging/development

Post by gregharewood »

Are you still looking at this? :-)

Turns out all the device mapping code is nicely placed in that index.js, and we can fix a lot of stuff there. I was dealing with a similar problem that dimmers weren't being flagged as lights in HomeKit... bad mapping. So no Siri control of any of my lights, because they're ALL dimmers.

I fixed it. https://github.com/Z-Wave-Me/home-automation/pull/270
Anyone know how to make sure this change gets incorporated? Please??

For you own purposes if the change is useful to you, you can just edit the index.js and restart the server. You'll have to delete and re-add on HomeKit too I think otherwise it won't see the change in device characteristics. The change is to update the switchMultiLevel part to....

Code: Select all

                else if (deviceType == "switchMultilevel") {
                        var serviceUUID = HomeKit.Services.Lightbulb;


                        var service = accessory.addService(serviceUUID, title + " Dimmer");

                        m.level = service.addCharacteristic(HomeKit.Characteristics.PowerState, "bool", {
                                get: function() { return (parseFloat(vDev.get("metrics:level")) || 0.0)>0; },
                                set: function(value) { vDev.performCommand(value ? "on" : "off"); }
                        });

                        m.level = service.addCharacteristic(HomeKit.Characteristics.Brightness, "float", {
                                get: function() { return parseFloat(vDev.get("metrics:level")) || 0.0; },
                                set: function(value) { vDev.performCommand("exact", { level: value }); }
                        });

                }

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: HomeKit debugging/development

Post by pz1 »

gregharewood wrote: Anyone know how to make sure this change gets incorporated? Please??
I guess the developers have already seen it, or will do so within a couple of days max.

The best thing to get this moving is for current HOMEkit users to replace their index.js with yours for a test. Since most of them are not familiar with github, it would be good if you provide a direct link to that index.js
jeff_greenshed
Posts: 5
Joined: 08 Sep 2015 02:32

Re: HomeKit debugging/development

Post by jeff_greenshed »

This really helped me out today.

I ended up basically removing support entirely for `sensorMultilevel` because they cause all kinds of problems for me.

I'm an iOS dev by trade, and after digging through the HomeKit docs, especially the Characteristics list, I'm pretty disappointed. No support for power meters at all in there.

On a related note, has anyone found where the things like `HomeKit.Services.Lightbulb` are defined? I have a motion sensor and I'd like to map it to the `HMCharacteristicTypeMotionDetected` etc. characteristics in HomeKit, but I can't seem to find where these are mapped at all.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: HomeKit debugging/development

Post by pofs »

HomeKit module is not updated to the latest specs yet. They've added a lot of new service types and characteristics which are not currently included into the module.
I'd rather not integrate your pull request now, because new services will make that part of JS completely rewritten, so it will be lost anyway.

Modhomekit.so is actually an implementation of a HomeKit bridge. It handles all the encryption, device announces, request handling, and provides JS objects to v8 engine.
HomeKitGate is a JS wrapper which sets up the HomeKit object and provides it a handler to integrate Automation objectss to the abstract HomeKit implementation.
So these two components work altogether to make things work.

Constants like HomeKit.Service.Lightbulb are defined inside the native module (modhomekit.so), that is why you failed to find them.
jeff_greenshed
Posts: 5
Joined: 08 Sep 2015 02:32

Re: HomeKit debugging/development

Post by jeff_greenshed »

pofs wrote:Modhomekit.so is actually an implementation of a HomeKit bridge.
Is this part open source?
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: HomeKit debugging/development

Post by pofs »

jeff_greenshed wrote:
pofs wrote:Modhomekit.so is actually an implementation of a HomeKit bridge.
Is this part open source?
No, it is not.

All the logic describing mapping between devices and HomeKit accessories/services is described in JS (HomeKitGate/index.js), so you can freely modify and extend it.
Native module only contains protocol low-level details, which don't need to be modified at all.
S'pht'Kr
Posts: 9
Joined: 20 Mar 2015 22:14

Re: HomeKit debugging/development

Post by S'pht'Kr »

Jeff,

I'd kind of moved on to a different approach--I'd discovered Homebridge and since it solved a more general need (and already had a module that worked with my garage door opener) I started writing a ZWay server interface module for that. It's getting a lot closer to being ready to merge, hopefully an initial version in the next few days now. It requires running Homebridge separately from ZWay, so it's a little more involved, but if you have any other of the devices it supports (or can write one) it's probably worth looking into.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: HomeKit debugging/development

Post by pofs »

S'pht'Kr,

the latest HomeKitGate commits (not included in releases yet) already have a lot of new devices supported, including binary and multilevel sensors, and RGBW switches too.
They will be available with the next update, or you may use them right now (but you'll need to define a few extra constants, because it requires an updated binary module with new service and characteristics types).

So instead of writing and supporting a whole new bridge (which is quite slow by the way, encryption is not a strong side of node.js), you'd better make your changes to the bundled HomeKitGate to support new device types, and file a pull request to get them included into the codebase.
S'pht'Kr
Posts: 9
Joined: 20 Mar 2015 22:14

Re: HomeKit debugging/development

Post by S'pht'Kr »

Hmm...well, I'll be interested to see the changes when they make release, but I've already made a good bit of progress on the Homebridge module and I'm already running Homebridge anyway to support my garage door opener and Yamaha AVRs (another module I wrote). Oh, and I'm running it on a Mac Mini, not the RPi, so speed isn't as much of an issue.

That said, I can probably leverage the logic I wrote as an internal ZWay module later if needed, or at least use the expertise to redo it faster. But the lack of documentation or source for modhomekit got in the way of me trying that earlier...at the moment HAP-nodeJS and Homebridge are much easier to write for. Looking forward to the updates though, we'll see!
Post Reply