Skip to content
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

Creating a Speaker to control an amplifier #178

Closed
aurels opened this issue Jul 2, 2020 · 6 comments
Closed

Creating a Speaker to control an amplifier #178

aurels opened this issue Jul 2, 2020 · 6 comments

Comments

@aurels
Copy link

aurels commented Jul 2, 2020

Hello,

I’d like to control an amplifier.

Main functionalities I want to control :

  • on / off
  • volume (int 1 to 30)
  • mute (boolean)
  • source (int 1 to 6)

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
Copy link
Author

aurels commented Jul 2, 2020

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
Copy link
Contributor

timoschilling commented Jul 2, 2020

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
Copy link
Author

aurels commented Jul 3, 2020

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
Copy link
Contributor

timoschilling commented Jul 3, 2020

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
Copy link
Author

aurels commented Jul 3, 2020

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.

@aurels aurels closed this as completed Jul 3, 2020
@rob121
Copy link

rob121 commented Mar 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants