brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

Creating a Speaker to control an amplifier #178

Closed aurels closed 4 years ago

aurels commented 4 years ago

Hello,

I’d like to control an amplifier.

Main functionalities I want to control :

I was able to run the switch example but I’m kind of confused about what I have to use in my case since Speaker is a Service and not an Accessory.

Do I have to create an Accessory and link a Speaker Service to it ? But what type of Accessory then ? Other?

I tried this :

acc := accessory.New(info, 0)

speakerSer := service.NewSpeaker()
acc.AddService(speakerSer.Service)

volumeChar := characteristic.NewVolume()
speakerSer.AddCharacteristic(volumeChar.Characteristic)

speakerSer.Mute.OnValueRemoteUpdate(func(on bool) {
    if on == true {
        log.Println("mute")
    } else {
    log.Println("unmute")
    }
})

t, err := hc.NewIPTransport(hc.Config{Pin: ""}, acc)

It builds but as soon as there is a service associated to the accessory, it’s not discoverable. I guess it does not make sense to have a Switch with a Service, I’m experimenting :D

I could not find how to subscribe to Volume and Active characteristics neither. I may get something wrong.

Please excuse me if the problem is that I don’t understand core concepts of HomeKit, I could not find any clear information anywhere in Apple's docs.

Thanks for any help or pointers.

aurels commented 4 years ago

Here is a new version. It compiles, it is discovered and I was able to add the Accessory in the Home app !

But it appears has "not currently supported by the Home app". I guess I have to meet some requirements to be compatible ? Some minimal characteristics ?

Thanks.

acc := accessory.New(info, 0)

speakerSer := service.NewSpeaker()
acc.AddService(speakerSer.Service)

volumeChar := characteristic.NewVolume()
speakerSer.AddCharacteristic(volumeChar.Characteristic)

activeChar := characteristic.NewActive()
speakerSer.AddCharacteristic(activeChar.Characteristic)

speakerSer.Mute.OnValueRemoteUpdate(func(on bool) {
    if on == true {
        log.Println("mute")
    } else {
        log.Println("unmute")
    }
})

volumeChar.OnValueRemoteUpdate(func(volume int) {
    log.Println("volume ", volume)
})

activeChar.OnValueRemoteUpdate(func(blop int) {
    log.Println("active ", blop)
})

t, err := hc.NewIPTransport(hc.Config{Pin: "12345677"}, acc)
if err != nil {
    log.Fatal(err)
}

hc.OnTermination(func() {
    <-t.Stop()
})

t.Start()
timoschilling commented 4 years ago

No that's not your fault that the app says "not currently supported by the Home app", the Home app didn't support all kinds of accessories. Maybe it will be changed with iOS 14.

A workaround can be to use an light bulb device and use the brightness as volume.

aurels commented 4 years ago

Whaat :p Thanks for that information.

Is there an official list of what from the specification is supported (or not) by the Home app ?

timoschilling commented 4 years ago

I don't know.

My way is to build my custom homekit devices in the "HomeKit Accessory Simulator" (can be downloaded from apple.com, simply google it) first and then check it in the home app.

aurels commented 4 years ago

Yes I tried in the simulator, it also resulted in a "not supported" accessory (Speaker). I'll experiment with other types of accessories, I'll have to fiddle... Thanks.

rob121 commented 3 years ago

Anyone finding this issue, it turns out that while the home app doesn't support this device, the device is controllable by apps that load in homekit devices. I tested with the Eve [1] app and I get all the events in the code @aurels posted!

[1] https://apps.apple.com/app/elgato-eve/id917695792