homebridge-apple-tv icon indicating copy to clipboard operation
homebridge-apple-tv copied to clipboard

Any way to do a press & hold advanced command?

Open mludowise opened this issue 6 years ago • 16 comments

I'd like to add a few commands that involve pressing and holding buttons for a duration of time. Is there any way to do that in an advanced command? I only saw ways to string multiple commands together with pause periods in between.

For example, I'd like to..

  • Press & hold "menu" for 2 seconds to go to the home screen
  • Press & hold "tv" for 2 seconds and then press "select" to put the Apple TV to sleep
  • Press & hold "siri" for 5 seconds to give me enough time to talk to the remote and give the TV a command.

mludowise avatar Jul 07 '18 21:07 mludowise

Currently no - this does seem like an important feature though especially because CEC is not sent when using the 'suspend' command as per https://github.com/lprhodes/homebridge-apple-tv/issues/24

Turning the TV off and on is the only reason I even wanted this plugin and it does not work.

ersan avatar Jul 12 '18 01:07 ersan

Same here, I'd love to be able to hold TV for 2 seconds for sleep.

jaydisc avatar Jul 12 '18 01:07 jaydisc

I would love that feature too!

DarKOrange75 avatar Jul 12 '18 07:07 DarKOrange75

Same here !! :)

sadden3194 avatar Aug 03 '18 15:08 sadden3194

Also here !! It's a very important future

MsCopernic avatar Aug 30 '18 22:08 MsCopernic

also for me :)

allstrike avatar Oct 01 '18 18:10 allstrike

I'm not a node.js developer, and this is not the correct place to fix it, I think it should properly be fixed in the node-appletv package and not homebridge-apple-tv package. However, I tested an update to homebridge-apple-tv/helpers/sendCommand.js

case "hold_menu": return device.sendKeyPress(1, 0x86, true);
return setTimeout(device.sendKeyPress(1, 0x86, true), 3000);

this uses the sendKeyPress from the node-appletv project directly, and allows you to set a timeout on the value. You can modify this for any button, but the above is for the menu button.

The proper place to fix it would be to create a new function in node-appletv to create a copy of sendKeyPressAndRelease and make a new function such as sendKeyPressHoldAndRelease that adds a delay between the press and release of the command in node-appletv.

But, just making the code change above seemed to work for my limited use. I'd like to get a proper fix into a pull request to add to node-appletv. But, i don't have time to do so as this is just a hobby project. But, I wanted to add here in case it was helpful.

bradskeds avatar Oct 25 '18 19:10 bradskeds

Actually the line should be return setTimeout(device.sendKeyPress(1, 0x86, false), 3000); not return setTimeout(device.sendKeyPress(1, 0x86, true), 3000); but it didn't seem to matter much in my testing.

bradskeds avatar Oct 25 '18 19:10 bradskeds

what is the full path for this file on our homebridge installs ? i can't find where it is

allstrike avatar Oct 25 '18 19:10 allstrike

i found it on my Mac at /usr/local/lib/node_modules/homebridge-apple-tv/helpers/sendCommand.js

bradskeds avatar Oct 25 '18 19:10 bradskeds

perfect i found it but the problem is, i want to shut down my apple TV with this command and it is using the "menu" button and not the "top_menu" or "tv" button, i tried to find the correct path for this one but i can't find it

allstrike avatar Oct 25 '18 19:10 allstrike

Possibly try this, changing the code that the button sends from menu to top_menu; basically change 1, 0x86 to 12, 0x60

like this:

case "hold_menu": return device.sendKeyPress(12, 0x60, true); return setTimeout(device.sendKeyPress(12, 0x60, false), 3000);

Then you can string together hold_menu and select to achieve what you want?

I haven't tested this but maybe it works?

bradskeds avatar Oct 25 '18 20:10 bradskeds

that's awesome, it's working perfectly. thanks for your help.

To resume the way to put Apple tv and the others gear off via CEC :

open the file /usr/local/lib/node_modules/homebridge-apple-tv/helpers/sendCommand.js

add :

case "hold_menu": return device.sendKeyPress(12, 0x60, true); return setTimeout(device.sendKeyPress(12, 0x60, false), 3000);

go to your config.json and put this in your accessories :

{ "deviceID": "Apple TV", "name": "sleep", "command": [ { "command": "hold_menu", "pause": 3 }, { "command": "select" } ] },

restart your homebridge and everything should work perfectly

the perfect thing now will be to have the opportunity to make one button in home kit using the simple menu key to power on your devices and this new command to put it off, and to have a way to give the information to this button if the appletv is on or off

allstrike avatar Oct 25 '18 20:10 allstrike

There is a command that I have been using for a long time that turns off the Apple TV without the prior step, it's part of the plugin:

    {
      "deviceID":"YourDeviceId",
      "name":"YourDeviceName",
      "disableLogs": true,
      "command":"sleep"
    }

MsCopernic avatar Oct 25 '18 21:10 MsCopernic

Yes but the sleep command doesn’t give the hdmi CEC info.

With this command my tv and my AV receiver shutdown too

allstrike avatar Oct 25 '18 21:10 allstrike

Yup, you are right, but there is also a workaround. In my case, I have to turn 0n the Apple TV, TV and surround system and set HDMI in the amplifier and TV and later turn them off. The following code + HomeKit automation, does all the work (on/off - settings), with a single button:

    {
      "name":"Device name",
      "type":"switch",
      "host":"34:ea:34:42:fa:xx",
      "disableLogs": true,
      "data":{
        "on":[
          {
            "_comment":"Turn on amplifier",
            "data":"2600..",
            "pause": 5
          },
          {
            "_comment":"Change amplifier input  to Apple TV",
            "data":"2600...",
            "pause": 0.5
          },
          {
            "_comment":"Turn On TV",
            "data":"26008...",
            "pause": 1.5
          },
          {
            "_comment":"TV input to HDMI2",
            "data":"0000 ...."
          }
        ],
        "off":[
          {
            "_comment":"TV off",
            "data":"2600...",
            "pause":0.3
          },
          {
            "_comment":"Turn amplifier off",
            "data":"2600...",
          }
        ]
      }
    }

Now create a new automation in HomeKit, to link this code with the on/off AppleTv plugin buttons. This way you can manage complex settings.

MsCopernic avatar Oct 25 '18 21:10 MsCopernic