In an effort to automate my home and not depend on infrared remotes, I created this IP-based control of DirecTV (satellite) receivers using DirecTV's published API.
Fair warning: I am in no way a developer of any kind, and this was used to learn what I needed to do without changing careers. Fortunately, I have a good knowledge of Perl and JavaScript and was able to muddle my way through. I would greatly appreciate anyone with actual development knowledge to help.
For those looking for ways to automate IP-based devices but don't know how to code, I think this driver will help you learn what you can do - it's not super hard. I put excessive amounts of documentation and debugging in the code to help people learn and find what they could use.
This driver permits direct control of a DirecTV receiver to do the following:
Check the operating mode of the receiver
Change the operating mode of the receiver (on or standby)
Check the currently playing channel and program
Change the channel
Send "remote" buttons
Use receiver program info in dashboards (via state attributes)
Control the receiver as a switch in Hubitat
Use Rule Machine "run custom command" against an actuator to run the driver functions
Thank you for your work on this, and I apologize in advance for my limited knowledge here. I read over the documentation, installed the driver, configured the I.P. address and I can successfully control my DirecTV Genie receiver from selections on the devices page. I then tried to create a Rule Machine rule and using the "Send Key" + "chanup" and using the "test the rule" function was able to change channels. It looks like this:
What I am having trouble with is taking that rule and applying it to a dashboard "button", for instance. So do I need to create a Rule Machine rule plus a related virtual "button" for every function I want to appear on a dashboard, or is their an easier way to do this? Again, thanks for the help.
Correct, you can't issue commands directly from a dashboard. You need to use a button-controller app to do that as an intermediary.
What you need to do isn't hard at all!
Here's how:
Install the button controller built in app if you don't already. [Apps> Add built-in at top of screen > Button Controller]
Next, create a virtual button device (any number of buttons you want). (add device > virtual > virtual button)
Next, go to your button controller app and tell it:
When button [numer] of [button device] is pressed.. run your rule machine script with "run rules from another rule"
OR easier- replicate your rule machine steps directly in the button controller, specfically:
run custom command > actuator > Directv device > sendKey(chanup)
Next, go to the dashboard config page (where you select what devices are in the dash board) and add the button device so the dashboard sees it.
Then, go to your dashboard, add a button and assign it to the button device you just added, specify the button number and if it's pressed, or held (whatever you chose in the button controller). Note: every time I add a button to the dashboard, it doesn't keep the configuration. Go to the button you added and configure it after adding it to the dashboard.
Here's what it should look like. make sure "chanup" is lowercase. The DirecTV API is case sensitive for button names:
Thanks so much! Worked great, and I did use your suggestion:
Within each button controller "child", I added a second command line to do a "refresh". That way when I change channels the "channelCallsign" and "channelNumber" buttons on my dashboard update. I did not have any luck with trying the "getTuned" command.
So one more question. How did you create the dashboard you showed above? That is really awesome. My dashboard are all using the Hubitat dashboard app and very generic - just a bunch of buttons.
I looked back at the code and recommend you change "refresh" to getTuned command.
Refresh does a getMode status check to see if the receiver is on (which should be unnecessary in your case)
and a getLocations check (to see if there's other client receivers)
which are just excessive if you're just changing channels, especially if you'll be channel flipping.
getTuned will just ask what's playing on the current channel.
oh, you need to put a 1 second delay between the commands. Changing channels isn't immediate. Do a hubitat delay command of ~1 second to give the receiver time to do it's thing.
I've seen random cases of the receiver throwing an error with two much back-to-back commands.
My dashboard is a standard dashboard with a bunch of custom CSS which do:
-remove all the hubitat built in labels (volume buttons)
-add my own text labels (all other buttons)
-adjust the images so they fill the button space (the logos)
-stack tiles on top of each other and adjust the z-level (so I have an indicator light to identify the current "activity"- a la logitech harmony - the light under the directv button)
The "current activity" lights are based on the Denon receiver I have (which the Hubitat folks have a built-in driver for) so I have a rule-machine rule that monitors the Denon for an input or power change, then changes the activity indicator (which is just a virtual switch) accordingly.
The logos at the top are buttons that fire off a logitech-harmony-like rule machine I have to power things on/off without me pressing a bunch of buttons.
The images are hosted in google photos. You just upload them, make the album public ("anyone with link") then grab the link to the photo you want. You then put it as the background image of the tile in the tile configuration (and custom CSS makes them fit correctly).
Drop me a message and I can show you how to do the custom CSS on your dashboard to remove labels.