lukasroegner / homebridge-apple-tv-remote

Plugin for controlling Apple TVs in homebridge.
MIT License
132 stars 13 forks source link

Feature request app specific playstate #62

Closed Luitwieler closed 4 years ago

Luitwieler commented 4 years ago

Hi Lukas!

I really like the plugin and works great for automation scenes. However I have a feature request for the play state button. Currently I use this button to change the lights in the living room when a movie starts playing. I would like to change the state of the button based on the application that is currently playing something.

for example if isPlaying = (m.payload.playbackState == 1 && m.payload.client.bundleIdentifier == "com.netflix.Netflix") but not for com.google.Youtube.

I tried adding it myself in a fork branch. However I now experience some issues getting my version registered in Homebridge.

image

Could we add something like this and make the app configurable via the config?

Many thanks in advance!

lukasroegner commented 4 years ago

Feel free to submit a PR for such a feature. I would suggest something like this:

{
    "platforms": [
        {
            "platform": "AppleTvPlatform",
            "devices": [
                {
                    ...,
                    "appPlayPauseSwitches": [
                        {
                            "name": "<UNIQUE-SWITCH-NAME>",
                            "bundleIdentifier": "<BUNDLE-IDENTIFIER-OF-THE-APP>"
                        }
                    ]
                }
            ],
            ...
        }
    ]
}
Luitwieler commented 4 years ago

I added all the required logic.

I changed the config file to be able to handle the following: image

which results in two independent buttons in HomeKit: image

Don't worry about the overwhelming amount of commits in my fork. It is the result of testing on my Raspberry and pushing my changes to it.

RaymondMouthaan commented 4 years ago

@Luitwieler,

First of all, I like this proposal of change and the PR you already submitted for it. 👍

I assume this makes it possible to set different light scenes, depending on the bundleIdentifier playing? Even when playing Apple Music? Can these states also been requested by the Api of the plugin?

Luitwieler commented 4 years ago

@RaymondMouthaan

Bedankt! 😉

Yes that is indeed the case. Whenever a playback change event is sent by the Apple TV it also includes the technical app name. This app name looks like: com.netflix.Netflix. The apple-tv-controller.ts is now also keeping track of the latest bundleindentifier that it received.

The new button uses this value and the evaluation logic looks like this:

I didn’t add logic in the API part of the plug-in, this shouldn’t be a big change in the code. @lukasroegner what do you think? Shall we add api support in the next pull request?

lukasroegner commented 4 years ago

The new feature is now on master and new version on NPM!

@Luitwieler If you want, you can also add it to the API, that shouldn't be too much work, as you already implemented the complicated part (the client).

Luitwieler commented 4 years ago

@RaymondMouthaan

FYI the bundleIdentifier for Apple Music tv app is com.apple.TVMusic

RaymondMouthaan commented 4 years ago

@Luitwieler & @lukasroegner thanks for adding this new feature !

Maybe its a good idea to add a list of bundleIdentifiers the readme so that its easier for users to use this feature? Or at least a few instructions how to get these?

When the Api supports it, I'll add up a nice flow in Node-RED to control my lights based upon the state of the Apple TV :-)

Greetz, Raymond

Luitwieler commented 4 years ago

https://support.apple.com/nl-nl/guide/mdm/mdmc90dce69e/web 😉 will add the link and known bundle identifiers to the reader in the next PR.

RaymondMouthaan commented 4 years ago

@Luitwieler, that's great! Didn't know about this list, adding Youtube, Disney+, Prime and maybe Videoland (for Dutch users) would cover most of them I guess :)

lukasroegner commented 4 years ago

New version on master and NPM, which includes the changes to the API! Again, thank you @Luitwieler for your collaboration on this plugin!