SphtKr / homebridge-itunes

Control iTunes on a Mac from HomeKit and Siri
53 stars 9 forks source link

iTunes Volume #3

Open jer78 opened 8 years ago

jer78 commented 8 years ago

When a speaker is off and then turned back on, it seems to forget the last volume it had. If I use the AppleScript plugin to toggle the AirPlay device on/off it doesn't seem to do this. Any ideas?

SphtKr commented 8 years ago

Yes, I'm seeing this too, unsure why. I'm just using AppleScript under the hood as well. What actual AppleScript are you using that seems to behave better?

jer78 commented 8 years ago

The AppleScript I use is:

"tell application "iTunes" to set selected of AirPlay device "Living Room" to true"

SphtKr commented 8 years ago

Um... Okay. That's essentially exactly what I'm doing in here https://github.com/SphtKr/homebridge-itunes/blob/master/index.js#L295 .

I just use the id instead because it's a number and I don't have to worry about escaping quotes or command injection 😄 . But that's...odd. I wonder why it's doing this...?

jer78 commented 8 years ago

That's odd! I'll try tonight to do some testing. I noticed there is a 0.2.0 alpha now. How do I install that version to give it a try?

SphtKr commented 8 years ago

Don't yet, I discovered that it won't update cleanly from 0.1.x...gotta put in a little migration code somewhere.

jer78 commented 8 years ago

I had uninstalled it previously and went back to my AppleScript plugin so maybe it would work cleanly for me?? Anxious to test it ;)

jer78 commented 8 years ago

So I had some time tonight and did a little testing. Here's my setup, expected behaviour and test results. Now I understand this may not be as you programmed so in your terms in may actually work as expected for you.

Setup: 4 AirPlay speakers each named: "AirPlay " and Siri command of: " Speaker" 3 speakers (excluding "Computer" and "Office") and the Playing State are in a Service Group named "Speakers". I exclude Office because if all AirPlay devices are turned off it reverts to "Computer" and I never want that scenario since it messes up my Mac Mini as previously mentioned.

Test 1: Living Room Airplay is Unselected but another AirPlay speaker "Office" is selected and iTunes is Not Playing. From Siri say "Turn on the Living Room Speaker" Expected Behavior: The living room AirPlay turns on. The Office speaker remains on. The Airplay volume resumes the previously used volume. iTunes begins playing. Siri responds "The Living Room speaker is on". The state of the AirPlay devices and Playing State are updated in the HomeKit app I use. Test 1 Result: Mostly pass. The Office speaker turns off when it should stay on.

Test 2: Living Room AirPlay is Selected and iTunes is Not Playing. From Siri say "Turn on the Living Room Speaker" Expected Behavior: The living room AirPlay remains on. The Airplay volume remains the same. iTunes begins playing. Siri responds "The Living Room speaker is on". The state of the AirPlay devices and Playing State are updated in the HomeKit app I use. Test 2 Result: pass

Test 3: Living Room AirPlay is Unselected. The Office AirPlay is Selected. iTunes is Playing. From Siri say "Turn on the Living Room Speaker" Expected Behavior: The living room AirPlay turns on. The Airplay volume remains the same as previously used. iTunes keeps playing current track. Siri responds "The Living Room speaker is on". The state of the AirPlay devices and Playing State are updated in the HomeKit app I use. Test 3 Result: Fail. The Living Room speaker turns on. Office speaker turns off. iTunes stops playing.

Test 4: iTunes is Stopped. Only one speaker is selected. From Siri say "Turn on the Speakers" Expected Behavior: The 3 AirPlay speakers in the service group turn on. The Airplay volume remains the same as previously used. iTunes starts playing. Siri responds "The Speaker are now on". The state of the AirPlay devices and Playing State are updated in the HomeKit app I use. Test 4 Result: Mostly pass. Turns off the speaker that was on. Turns on another speaker (seems to be random) but retains volume.

Test 5: iTunes is Playing. All speakers are selected. From Siri say "Turn off the Speakers" Expected Behavior: The Airplay speakers turn off with the exception of "Office" (which is left out of the service group on purpose). Siri responds "The Speaker are now off". The state of the AirPlay devices and Playing State are updated in the HomeKit app I use. Test 5 Result: pass

Also I did figure out the volume issue. If all speakers get turned off, and iTunes auto selects "Computer" and sets the volume to 61%. The next time a speaker is turned on it gets the volume level from "Computer" (61%).

SphtKr commented 8 years ago

Hey there, the above is great. I'm going to have to dig through it. Test 3 result really puzzles me. I'm going to have to try to reproduce here. Funny, it's always 61% I see here, too...what's magical about that number??

jer78 commented 8 years ago

So I had to delete all of my homekit accessories and start again because I was having issues with inviting users since the latest iOS update. After I re-installed everything and re-tested #3 it works as it should. No idea what was wrong with my previous set-up.

As for the 61%, I'm figuring its an Apple thing and we are stuck with that volume level. To stop that from happening, I always leave one airplay speaker on.

SphtKr commented 8 years ago

Need to look into it more, but I think there may be a lurking variable here. Like whether iTunes is set to "single" or "multiple" audio destinations before the plugin gets a hold of it. Could be a red herring though.