lprhodes / homebridge-apple-tv

Apple TV 4th & 5th gen plugin for homebridge: https://github.com/nfarina/homebridge
Apache License 2.0
105 stars 15 forks source link

Any way to do a press & hold advanced command? #34

Open mludowise opened 5 years ago

mludowise commented 5 years ago

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..

ersan commented 5 years ago

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.

jaydisc commented 5 years ago

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

DarKOrange75 commented 5 years ago

I would love that feature too!

sadden3194 commented 5 years ago

Same here !! :)

MsCopernic commented 5 years ago

Also here !! It's a very important future

allstrike commented 5 years ago

also for me :)

bradskeds commented 5 years ago

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 commented 5 years ago

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.

allstrike commented 5 years ago

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

bradskeds commented 5 years ago

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

allstrike commented 5 years ago

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

bradskeds commented 5 years ago

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?

allstrike commented 5 years ago

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

MsCopernic commented 5 years ago

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"
    }
allstrike commented 5 years ago

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

With this command my tv and my AV receiver shutdown too

MsCopernic commented 5 years ago

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.