New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple devices #146
Comments
If you have a map of light bulb accessories, you have to convert it to a slice of generic accessories like this. var lights map[string]*accessory.Lightbulb
var accessories []*accessory.Accessory
for (string, light) := range lights {
accessories = append(accessories, light.Accessory)
} Then you can create an ip transport with the
I would create a function which takes the telnet address and returns a light bulb accessory. There you have all the information you need to implement the two-way communication between telnet and HomeKit. |
Will give it a try! Thanks for help and thanks for such a great implementation (and sorry for my questions - this is one of my early attempts writing in golang...) |
Seems I panicked prematurely (and deleted my previous comment) :-) My issue is that I am passing too many devices to the transport - is there any limitation? - I was trying to send about 150 devices to the transport (all the relays on the control unit) what seems too many. I went down to 4 and it works fine (almost). The only issue I have is that I am able to control only one of the created lightbulbs (which is the very first one I turn on after starting the program)... If I check the phone app, I see the devices having the correct SN (which is the telnet address) but any ON / OFF call is reusing the address of the first device I turned on.... I am setting the on / off action in the same loop where I am creating the accessory object:
...and where I am filling in the accessory info (which is correct for each object)
The ON/ OFF action is the one from the example and it expects
The problem is that if I toggle the device (for example) 0x01020027, all the other ON / OFF actions will be using the same device SN instead of SN of the accessory I am trying to control:
creating the accessory:
(sorry for the formatting of the debug prints and my terrible way of coding - I didn't care about the logs so far and all the pointers and types are still very confusing for me). |
The HomeKit Accessory Protocol (HAP) specification sets a limit of 150 accessories per bridge. |
Thanks for confirming - I thought that I might be too demanding by not filtering out what I really need and passing all the relays to the protocol :-) |
Devices (accessories) in HomeKit are identified by an ID. hc assigns the ID incrementally in the order you add them in the |
@bjanders That's a good point. Pull requests are always welcome. 😉 |
I did a quick hack for my own purposes, but if there is chance for a proper change to get merged then I'll try to get it done. I'd make it so that it is backward compatible so that if you don't provide a custom ID then one would be assigned incrementally as it is done now. If you assign a custom ID I'd add a check that the ID is not already assigned to some other accessory. |
This sounds like the tricky part. I am loading my devices from a text file (which is being produced by my smart home control unit). I am currently having about 25 lights I am feeding into the transport and loading them from a slice changes their ID if I restart the app so its impossible to restart the app without deleting everything and adding all the devices in the ios app again. |
We could add an ID property to accessory.Info and use that if specified. |
I second adding an ID property to accessory.Info. Implementing dynamic bridges, where accessories are added after the fact or may disappear when decomissioned, is not possible otherwise.
|
Thanks, those changes are now available in the master branch. |
Hey all!
I am so happy I found this project!!! :-)
I don't have exactly "an issue" but rather a very noob question, need small help and don't know where else to ask...
I am trying to create multiple accessories at the same time as it seems to be supported by the ip transport:
"The transports can contain more than one accessory. If this is the case, the first accessory acts as the HomeKit bridge."
...yet I got stuck here...
I have a map of the accessories (my code needs to store the device name and its unique address I am passing to the ON/OFF commands which communicate further via telnet), but I am not sure how to properly construct multiple accessories from this map and pass all the accessories to the transport...
My idea is to build a slice and pass it to the transport, yet the is the place where I got unsure:
acc := accessory.NewLightbulb(info)
, but what if I have more light bulbs? Should I create a slice and append all theseacc's
(if so then of what type this slice should be?)?I tried to create a slice
var lampSlice []*accessory.Lightbulb
and fed my custom lightbulbs into this slice, yet I can't use this slice in NewIPTransport() and this function expects*accessory.Accessory
.......acc.Lightbulb.On.OnValueRemoteUpdate(func(on bool) {}
which are created for the accessory which are created for the specific accessory?Is there an example of creating multiple accessories I could check and consult with?
Thanks a lot!
The text was updated successfully, but these errors were encountered: