lukasroegner / homebridge-apple-tv-remote

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

Feature Request: Additional Switches #14

Closed Nastras closed 4 years ago

Nastras commented 4 years ago

It's me again.)

Would it be possible that you add an option in the config that allows to show additional switches on the apple tv like the play switch?

The idea behind this is that you could have a script for various functions or apps on the Apple TV that accesses your API. You could build such a small remote control or open the appropriate app directly via Siri.

For example a switch Netflix, here you can define in your script which order the commands have to run so that the app Netflix is called when the switch is pressed.

The script can be linked via shortcuts or what would be even cooler and more stable if you have a cmd function for the additional switches.

What do you think of the idea?

lukasroegner commented 4 years ago

I'll implement it this way:

{
    "platforms": [
        {
            "platform": "AppleTvPlatform",
            "devices": [
                {
                    "name": "<UNIQUE-NAME>",
                    "credentials": "<CREDENTIALS>",
                    "isOnOffSwitchEnabled": false,
                    "isPlayPauseSwitchEnabled": false,
                    "commandSwitches": [
                        {
                            "name": "Netflix",
                            "commands": [...]
                        }
                    ]
                }
            ],
            "isApiEnabled": false,
            "apiPort": 40304,
            "apiToken": "<YOUR-TOKEN>"
        }
    ]
}

The commands in the array are the same ones that the API supports. Switches are exposed as "stateless" switches (i.e. the go back to "off" after you've activated them). What do you think?

Nastras commented 4 years ago

👍👍👍

lukasroegner commented 4 years ago

Here you go:

https://github.com/lukasroegner/homebridge-apple-tv-remote.git#command-switches

Will be merged into master after testing phase.

Nastras commented 4 years ago

Hey Luke another question for you, how are the orders separated from each other? Is it actually possible to insert a sleep command between two commands to get a delay?

"commands": [Play, Pause] ???

lukasroegner commented 4 years ago

Take a look at the sample in the Readme: „API - Send commands“, the JSON is shown there

Nastras commented 4 years ago

Hello, Lukas,

I installed the plugin with: sudo npm install -g https://github.com/lukasroegner/homebridge-apple-tv-remote.git#command-switches

npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)

My config looks like this: "plugins": [ "homebridge-apple-tv-remote" ],

"platforms": [ { "platform": "AppleTvPlatform", "devices": [ { "name": "Spiegel Flur", "credentials": "XXXXXX", "isOnOffSwitchEnabled": true, "isPlayPauseSwitchEnabled": true }, { "name": "Dashboard", "isOn": true, "isPlaying": false, "commands": [ { "wait": 6000 },
{ "key": "topmenu", "longPress": false }, { "wait": 1000 }, { "key": "topmenu", "longPress": false }, { "wait": 2000 }, { "key": "down", "longPress": false }, { "wait": 1000 }, { "key": "select", "longPress": false }, { "wait": 1000 }, { "key": "home", "longPress": false }, { "key": "home", "longPress": false }, { "wait": 1000 }, { "key": "up", "longPress": false }, { "key": "up", "longPress": false }, { "wait": 1000 }, { "key": "topmenu", "longPress": false }, { "key": "topmenu", "longPress": false }, { "wait": 2000 }, { "key": "down", "longPress": false }, { "wait": 1000 }, { "key": "select", "longPress": false } ], "isApiEnabled": true, "apiPort": XXXXX, "apiToken": "XXXXXXX" } ] } ] }

The config is valid, I get the following error when starting the plugin:

Bildschirmfoto 2020-03-25 um 19 02 29

Could you explain these two options:

"isOn": true, "isPlaying": false,

Thank you!!!

lukasroegner commented 4 years ago

Sorry! I switched to TypeScript, simple installation from GitHub is not possible anymore.

I've published the new version on NPM, just update the plugin via name (the error in the log should be gone).

Second issue: you mixed up several settings in the config. I assume that you want to expose a switch named "Dashboard", this is how it should look:

"platforms": [
    {
        "platform": "AppleTvPlatform",
        "devices": [
            {
                "name": "Spiegel Flur",
                "credentials": "XXXXXX",
                "isOnOffSwitchEnabled": true,
                "isPlayPauseSwitchEnabled": true,
                "commandSwitches": [
                    {
                        "name": "Dashboard",
                        "commands": [
                            {
                                "wait": 6000
                            },
                            {
                                "key": "topmenu",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "topmenu",
                                "longPress": false
                            },
                            {
                                "wait": 2000
                            },
                            {
                                "key": "down",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "select",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "home",
                                "longPress": false
                            },
                            {
                                "key": "home",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "up",
                                "longPress": false
                            },
                            {
                                "key": "up",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "topmenu",
                                "longPress": false
                            },
                            {
                                "key": "topmenu",
                                "longPress": false
                            },
                            {
                                "wait": 2000
                            },
                            {
                                "key": "down",
                                "longPress": false
                            },
                            {
                                "wait": 1000
                            },
                            {
                                "key": "select",
                                "longPress": false
                            }
                        ]
                    }
                ]
            }
        ],
        "isApiEnabled": true,
        "apiPort": XXXXX,
        "apiToken": "XXXXXXX"
    }
]
Nastras commented 4 years ago

Test successfully completed. It works great! You also succeeded in the implementation very well! Thank you for your effort!!!

If you could explain these two options to me?

"isOn": true, "isPlaying": false,

lukasroegner commented 4 years ago

Those options are only available in the API. They are shortcuts for changing on/off and play/pause via the API (instead of explicitly writing the commands).