bklavet / Echo-skill-to-control-Directv

amazon echo skill that will control a networked Directv Receiver so that users can control Directv with their voice
18 stars 67 forks source link

Scheduled Alexa command to DirecTV #84

Open mikerain99 opened 5 years ago

mikerain99 commented 5 years ago

Our DirecTV boxes switch to a screen saver after an hour or two of not touching the remote, even if we're watching a show. This is infuriating in the final minutes of a sporting event. DirecTV forum posts indicate this is a bug that DirecTV hasn't fixed.

This is different from the power saver. The DTV box can be configured to disable the power saver, but you can't disable the screen saver.

As a solution, I'm thinking Alexa could send a command to all our DTV boxes every half hour, to keep the box from turning on the screen saver. It would have to be a command that doesn't do anything annoying on the screen.

Is this doable?

weiljx commented 5 years ago

Alexa needs to be invoked in order to send a command. You can not just keep a timer open and send a command every x minutes because this would be a major security flaw for Amazon. With Alexa skills you must invoke an action by voice, they are starting to open up other avenues with smart home skills and routines based on timing however I think this would be to complex for a routine at the moment. Hope that helps

mikerain99 commented 5 years ago

I saw that Alexa now has scheduled routines, and I was hoping to utilize that somehow. If that's too complex, is there some other non-Alexa way to do this? For example, a command can be sent via http like this one to replicate pressing the Enter key on the remote:

http://[DTV_IP]:8080/remote/processKey?key=enter&hold=keyPress

Is there some way to make this happen every 60 minutes?

vmweaver commented 5 years ago

Is your DTV box accessible publicly? Are you currently using this skill? If so, then you may be able to use a service like IFTTT to do what you want. Do you have a Raspberry Pi running at home? A desktop computer that's always on? Windows and Linux systems have schedulers which could do it, most likely. They would just need a script or command to run. Let us know....

On Mon, Apr 22, 2019 at 10:58 PM mikerain99 notifications@github.com wrote:

I saw that Alexa now has scheduled routines, and I was hoping to utilize that somehow. If that's too complex, is there some other non-Alexa way to do this? For example, a command can be sent via http like this one to replicate pressing the Enter key on the remote:

http://[DTV_IP]:8080/remote/processKey?key=enter&hold=keyPress

Is there some way to make this happen every 60 minutes?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-485634759, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPOFZM3HOGQMFU7RXNLPR2CP7ANCNFSM4HHS52LA .

mikerain99 commented 5 years ago

The DTV boxes are accessible publicly. I'm currently using a skill which I created, with the help of this forum, to verbally command the DTV boxes via Alexa. There isn't a Raspberry Pi but I could get one. There's a computer that is usually on.

bklavet commented 5 years ago

Hello friends, I hope you are all holding life in the palm of your hands!

If the PC that is usually on is windows, and it is working on the same network as the DirecTV receivers... you could try setting up a task schedule event. Create an action to run a DirecTV remote control command through IE and close. Then schedule it to run every hour. That way you wouldn't need to open it up to the public.

This could be a great prank to drive others in the house crazy if you put in the wrong remote code like...fast forward, channel up, etc, choose wisely

B

mikerain99 commented 5 years ago

I like what you're thinking about an April Fool's Day prank. Regarding the scheduled task, I'm familiar with those, but how do I tell the scheduled task to make IE close after the command?

bklavet commented 5 years ago

https://forums.tomshardware.com/threads/close-program-using-task-scehduler.1230888/

Maybe a follow up task like this to close the browser.

vmweaver commented 5 years ago

I would just do a simple powershell one liner using invoke-webrequest. Let me write it up when I get back to my laptop.

On Tue, Apr 23, 2019, 7:59 PM B money notifications@github.com wrote:

https://forums.tomshardware.com/threads/close-program-using-task-scehduler.1230888/

Maybe a follow up task like this to close the browser.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-486027044, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPLZ5SICTSK4LKW26UDPR6WF5ANCNFSM4HHS52LA .

mikerain99 commented 5 years ago

Oh, a one-liner! I love simple solutions.

vmweaver commented 5 years ago

Try running this command from a windows command prompt: Just change to be whatever you ip address is.

schtasks /create /sc hourly /tn "DTV" /TR "powershell -command &{invoke-webrequest -uri http://:8080/remote/processKey?key=exit| out-null}" /st 21:00

This should create a scheduled task named "DTV" set to run every hour beginning at 9pm today and go on forever. This sends the "Exit" command to it, so it doesn't do anything. Just change the key=exit to whatver other key you want to send.

If you want to kick it off manually, you can do it in the UI for Task Scheduler or do this from a command prompt.: schtasks /run /tn "DTV" Let me know how it goes.

On Tue, Apr 23, 2019 at 8:08 PM mikerain99 notifications@github.com wrote:

Oh, a one-liner! I love simple solutions.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-486028682, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPONU3LUX3HS7V7JL5LPR6XJHANCNFSM4HHS52LA .

mikerain99 commented 5 years ago

Thanks, this is excellent. I may have spoken too soon. I'm not sure if there is a computer running all the time. (This is a friend's house, not mine.) How would I do this with a Raspberry Pi? He doesn't have one, but might be willing to buy one instead of dedicating a 24x7 computer.

vmweaver commented 5 years ago

Besides setting up the RPi, it's pretty easy to schedule that same call.

You could even do an RPi Zero W, which is cheaper and would serve the same purpose. It may be worth it to see if this will actually work by testing the Windows task before going super deep down this rabbit hole.

For RPi it would be as simple as setting up a cron job to run (like Task Scheduler in windows). Once you have your RPi on the the work and can SSH into it:

  1. Login via SSH
  2. We should backup the crontab file first: sudo bash -c 'cp /etc/crontab /etc/crontab.orig'
  3. From command line: sudo bash -c 'echo "0 pi curl -s http://:8080/remote/processKey?key=exit > /dev/null" >> /etc/crontab'
  4. Then confirm it with this from a command line: grep 8080 /etc/crontab

This basically tells cron (scheduler) to run the "curl" command (like the powershell invoke-webrequest) at the "0" minute of every hour, every day, every month..etc... If you wanted to run every 30 minutes, I think you could replace the "0" with "*/30" or even "0,30" (note no spaces in those 2 examples). If you wanted it to run at the BOTTOM of the hour (1:30, 2:30,etc) just replace "0" with "30".

In order to remove the schedule, it is easiest to "sudo nano /etc/crontab" and just go delete the last line and save it.

On Wed, Apr 24, 2019 at 9:55 AM mikerain99 notifications@github.com wrote:

Thanks, this is excellent. I may have spoken too soon. I'm not sure if there is a computer running all the time. (This is a friend's house, not mine.) How would I do this with a Raspberry Pi? He doesn't have one, but might be willing to buy one instead of dedicating a 24x7 computer.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-486277201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPJTNYJMWAXJMM76QWTPSBYG3ANCNFSM4HHS52LA .

vmweaver commented 5 years ago

There are also some more "cloudy" ways to do it, if you want... Since this is a publicly-exposed endpoint, you could also sign up for IFTTT.com (if this, then that) and create a simple applet.

if THIS: Time -every hour at 00 then THAT: Webhook - web request URL: http://<dtv public address:port>/remote/processKey?key=exit

I would STRONGLY recommend not fully exposing your DTV box to the internet as it has no security on it. I wrote a post on setting up an RPI to make it a bit more secure to integrate it with this skill and you could run the cron job from it: https://geekweaver.wordpress.com/

On Wed, Apr 24, 2019 at 10:35 AM Mark Weaver geekweaver@gmail.com wrote:

Besides setting up the RPi, it's pretty easy to schedule that same call.

You could even do an RPi Zero W, which is cheaper and would serve the same purpose. It may be worth it to see if this will actually work by testing the Windows task before going super deep down this rabbit hole.

For RPi it would be as simple as setting up a cron job to run (like Task Scheduler in windows). Once you have your RPi on the the work and can SSH into it:

  1. Login via SSH
  2. We should backup the crontab file first: sudo bash -c 'cp /etc/crontab /etc/crontab.orig'
  3. From command line: sudo bash -c 'echo "0 pi curl -s http://:8080/remote/processKey?key=exit > /dev/null" >> /etc/crontab'
  4. Then confirm it with this from a command line: grep 8080 /etc/crontab

This basically tells cron (scheduler) to run the "curl" command (like the powershell invoke-webrequest) at the "0" minute of every hour, every day, every month..etc... If you wanted to run every 30 minutes, I think you could replace the "0" with "*/30" or even "0,30" (note no spaces in those 2 examples). If you wanted it to run at the BOTTOM of the hour (1:30, 2:30,etc) just replace "0" with "30".

In order to remove the schedule, it is easiest to "sudo nano /etc/crontab" and just go delete the last line and save it.

On Wed, Apr 24, 2019 at 9:55 AM mikerain99 notifications@github.com wrote:

Thanks, this is excellent. I may have spoken too soon. I'm not sure if there is a computer running all the time. (This is a friend's house, not mine.) How would I do this with a Raspberry Pi? He doesn't have one, but might be willing to buy one instead of dedicating a 24x7 computer.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-486277201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPJTNYJMWAXJMM76QWTPSBYG3ANCNFSM4HHS52LA .

mikerain99 commented 5 years ago

Thanks a lot for all of this. The DTV has to be exposed to the internet in order for the Alexa skills to control it, doesn't it? We do this via port forwarding on the home's cable modem/router.

Also, I want to double-check your command: schtasks /create /sc hourly /tn "DTV" /TR "powershell -command &{invoke-webrequest -uri http://:8080/remote/processKey?key=exit| out-null}" /st 21:00

Is it correct to have & before {invoke, or is that a typo?

vmweaver commented 5 years ago

The "&" is correct.

Well, SOMETHING had to be exposed to the internet. That's what the nginx api proxy is for.

Basically, the lamba function makes a call to the nginx endpoint which you expose via NAT instead of your DirecTV box. The nginx server then sends the api call over to your DirecTV box. The benefit is that lambda makes a secure/encrypted call to nginx and uses a user name/password combination whereas the DirecTV receiver had absolutely zero security.

On Fri, Apr 26, 2019, 6:10 PM mikerain99 notifications@github.com wrote:

Thanks a lot for all of this. The DTV has to be exposed to the internet in order for the Alexa skills to control it, doesn't it? We do this via port forwarding on the home's cable modem/router.

Also, I want to double-check your command: schtasks /create /sc hourly /tn "DTV" /TR "powershell -command &{invoke-webrequest -uri http://:8080/remote/processKey?key=exit| out-null}" /st 21:00

Is it correct to have & before {invoke, or is that a typo?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-487228170, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPK33MYMJDTGGFIKDSLPSODWJANCNFSM4HHS52LA .

mikerain99 commented 5 years ago

Sorry for my elementary questions. Can you explain what the & does? I did the following without an & and it worked fine. powershell -command "Test-Connection 192.168.0.155" Why is the & needed in your command? powershell -command &{invoke-webrequest -uri http://:8080/remote/processKey?key=exit|out-null}"

vmweaver commented 5 years ago

The & and curly braces are a bit more explicit to say that everything here is to be executed.

Powershell is pretty flexible so it may not be needed, i guess, in every case. Just habit for me, i suppose. :-)

On Fri, Apr 26, 2019, 7:29 PM mikerain99 notifications@github.com wrote:

Sorry for my elementary questions. Can you explain what the & does? I did the following without an & and it worked fine. powershell -command "Test-Connection 192.168.0.155" Why is the & needed in your command? powershell -command &{invoke-webrequest -uri http:// :8080/remote/processKey?key=exit|out-null}"

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bklavet/Echo-skill-to-control-Directv/issues/84#issuecomment-487238405, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUJWPKPC7FZOIXFFKYONFLPSOM53ANCNFSM4HHS52LA .