[RELEASE] Roku Virtual Buttons

Is there any sort of scheduled state refresh that can occur? I’ve successfully installed MrDalek fork along with the ‘remote’ device which does appear to be able to show the current state of the device in SmartThings. I have a few Roku TV (TCL and Sharp branded) with built-in Roku and I’m trying to add an automation that will automatically turn off the Roku TV after it has been powered on for a set period of time, say 4 hours or so.

I have the automation working using the native smart lights and switches power allowance smart app but I’ve noticed that the Roku Manager does not appear to automatically/periodically update the state of the Roku devices in Smart Things.

Can this be enabled?

EDIT: Actually I was able to solve this myself and add a quick times refresh to the Roku device handler.
I simply added “runEvery5Minutes(refresh)” to the def refresh section to refresh the current state every 5 minutes. Not exact timing in the grand scheme but also not overly chatty either.

def refresh() {
  log.debug "refresh"
  runEvery5Minutes(refresh)
  rokuDeviceInfoAction()
  getCurrentActivity();
  getAllActivities()
}

@MrDalek I originally used MadMouses code to have my TCL/Roku TV turn on via motion sensor connected to smart things. The IP address on the the TV periodically changes. During the last time I had to set it up, I used your modified code. The TVs IP address changed again but it doesn’t seem to be discovered. I cannot see a way to reset the application or delete/re-add. Any advice for having the Roku Manager discover the new IP address of the existing TV? Thank you

@MrDalek I was able to find my own resolution. Since the buttons were associated to Google, I had to disconnect the Google connection before it allowed me to remove the existing Roku TV and then the app. Then reloaded the app and new IP address for the TV popped up. All good. Thanks again.

Anyone dropping in here fresh like I was a couple days ago look here:
Use the files here by MrStevenFeldman, the originally posted ones won’t get this working: https://github.com/MrStevenFeldman/RokuSmartThings

Now go find the Roku device made through RokuConnect and press the power button in there. You should be able to get it to turn off. You’ll know you’re good to go add the buttons because your TV will turn off and additionally the bottom right of the app will say ‘n Channels’ meaning it sees how many unique ‘channels’ you can launch from the home screen. Once you do go back to add the virtual buttons and all of your apps/custom named inputs should then list out. If you don’t do this step when you go to flip on the buttons you want in the virtual buttons app setup you won’t see any of you Home screen apps and your inputs will have their generic names like HDMI 1.

If you’re using Google Home and your Smartthings account is already connected then all the Virtual buttons made in Smartthings will transfer to Google Home and you just need to assign them to a room (I made a Roku TV room since there’s a lot) then you can add them to a routine. This will save you a step from setting them up as a scene in Smartthings then triggering that scene through a Routine in Google. You just don’t need the Smartthings scene at all (also note if you’re new to this like me that you don’t put a period at the end of a custom Google routine, it has issues if you add punctuation to the voice command).

It does appear the Virtual Buttons Smartthings app will only work for one TV unfortunately. You can add multiple TVs through RokuConnect but virtual buttons doesn’t let you individually setup buttons for both.

The official Roku integration with Google does now allow multiple devices though the voice commands are weaker than what you can setup here.

I stumbled across this thread because i’m wanting to setup a IFTTT Applet to tell Google to “Power on the Living Room” which i would want my lights powered on (connected via smartthings) AND to power on my TCL Roku TV. Trying to decipher what you guys are saying, is there a way to somehow have it power on the TV via Smartthings? I already linked the Roku account to my Google Home which I can power on the TV with my voice, but wanted to encompass IFTTT to power on everything.

Yes, this smart app can be installed on smartthings and will allow you to do exactly that.

I tried this, but my Roku ‘Remote Device’ status is still not updating. It’s constantly saying “On”.

So to be clear - the Roku virtual button smartapp and associated DTH will allow you to control your Roku. But if you want it to maintain and keep updated/synced the current status of the Roku devices power then you’ll need to modify one line of code in the DTH as I specified in post 81 above - thought it has since been tweaked slightly after one of the more recent smartthings updates broke my previous mod:

Simply replace one single line - line 231 in the DTH

Replace:    'log.debug "refresh"
With:   runEvery5Minutes(refresh)

It should look like this when you are finished:

def refresh() {
  runEvery5Minutes(refresh)
  rokuDeviceInfoAction()
  getCurrentActivity();
  getAllActivities()
}

Once that is set, the DTH will obtain the current status from the Roku device every 5 minutes and return that status back to Smartthings. You can change that interval number to be longer or shorter but 5 minutes was more than adequate for my purposes.

One other note: you will have to turn on/enable fast start on your Roku AND the Roku TV has to be on the same network as your SmartThings hub.

2 Likes

@ThomasTrain

A couple questions.
I just set this up using the MrStevenFeldman DTH and Smartapps.

I have buttons for my TV’s but they do not stay in sync if the remote is used. I know you said to replace line 231 in the DTH but I That line of code

This DTH doesn’t do immediate status update and sync of the TV into the app… it is timed so the status will not immediately sync when you use the remote. If your refresh interval is set to 5 minutes then it will update the status in the app to what the TV actually is after 5 minutes.

First, ensure that you can power on and off the TV using the device in smartthings - that will at least tell you things are communicating. Then turn off the TV using smartthings and ensure the status is reflected in the app. Then power on the TV with the remote - then after 5 minutes (or whatever your refresh time is) that should update in the app.

1 Like

In an earlier post you said a line of code needed to be updated. I am not finding that line of code you said to update the refresh interval in.

You add that line.

Simply replace one single line - line 231 in the DTH

Replace:    'log.debug "refresh"
With:   runEvery5Minutes(refresh)

It should look like this when you are finished:

def refresh() {
  runEvery5Minutes(refresh)
  rokuDeviceInfoAction()
  getCurrentActivity();
  getAllActivities()
}

Once that is set, the DTH will obtain the current status from the Roku device every 5 minutes and return that status back to Smartthings. You can change that interval number to be longer or shorter but 5 minutes was more than adequate for my purposes.

Thank you for being so patient with my questions! I finally got this set up and controlling TV’s and I replaced the line of code to refreshEvery5Minutes but the status will not sync.

Are you able to control the TV from Smartthings?

The only remote button I create for my TVs is the remote power.

Also ensure the TV and your Smartthings hub are on the same network (don’t put your TV on a guest network). The Smartthings hub has to be able to directly query the TV over the network.

Do you mean you created 1 button that controls on/off?
I created power on and power off buttons. I don’t seem to have an option for 1 button. They do control the TV but don’t sync despite making the changes you said.


There are more options but they are all for channels.

Ok. I figured out the single button for remote. I will see if that stays in sync

Sorry - whoever authored this DTH definitely didn’t make it intuitive. The only ‘button’ you want to create is the one for ‘Roku remote’ and give it a name.

See my example here:

image

@ThomasTrain Update: I deleted everything and did a fresh install. I can control my TV’s power. I then update the code to refresh every 5 minute as you posted above. I can manually control tv but will not sync status. I tried deleting and doing a fresh install (again) but changed the refresh section before adding the Smartapp. Buttons were created but I could not control the TV. When pressed, the button would just spin and never execute.


I’m only using the ‘Roku Remote’ button - I haven’t tested this with any other remote buttons and this is working for 6 separate TVs in my network so I know it works - at least for me.

In IDE, are you clicking ‘save’ followed by choosing ‘publish → for me’ after you make the edit to make the modified DTH active in your account?

Last ditch effort before I give up. I have taken pictures of my DTH, Smartapp, edited DTH, buttons. Maybe you can spot if I did something wrong. These are the only 3 buttons I created.