Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mludowise opened this issue Jul 7, 2018 · 16 comments
Open

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

mludowise opened this issue Jul 7, 2018 · 16 comments

Comments

@mludowise
Copy link

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.
@ersan
Copy link

ersan commented Jul 12, 2018

Currently no - this does seem like an important feature though especially because CEC is not sent when using the 'suspend' command as per #24

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

@jaydisc
Copy link

jaydisc commented Jul 12, 2018

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

@DarKOrange75
Copy link

I would love that feature too!

@sadden3194
Copy link

Same here !! :)

@MsCopernic
Copy link

Also here !! It's a very important future

@allstrike
Copy link

also for me :)

@bradskeds
Copy link

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
Copy link

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
Copy link

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

@bradskeds
Copy link

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

@allstrike
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

With this command my tv and my AV receiver shutdown too

@MsCopernic
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants