[Release] Sony Bravia TV Rest Control

Hello all,

I have a Sony TV and have written a Hubitat driver using httpPost call with Sony REST API. I decided to bring my TV over to this method after writing a similar driver for Sony Audio devices and seeing all the available API's and how much more efficient it was than emulating button clicks.

Most functions here should work with all recent Sony Bravia Smart TV's, but some functions may be specific to certain models or obviously certain TV settings.

Prerequisites
You must enable your TV to accept commands and set a PSK on your TV.

Limitations
Sony did not expose a way to see the current app currently on the TV, so unless TV is on Tuner or one of the HDMI ports, it will always come back with "SmartMode"

IMPORT URL:
https://raw.githubusercontent.com/jonesalexr/hubitat/master/Drivers/SonyBravia/SonyBraviaTVRestControl.groovy

Install Driver
Import Driver
Add virtual device
Input IP address and PSK set on TV
If you are in EU, you may need to enable Wake-On-Lan on TV and check box in preferences.

Commands

States
BraviaStates

Capabilities
BraviaCapabilities

Preferences

KeyPress This button had a limit to the number of available dropdowns in hubitat, you can change out any of these in Line 59-94 with the available options in line 640-785.

LaunchApp This button will launch an App if it already exist on your TV.

Reboot This will reboot your TV.

SendDebugStringThis will allow you to send a json command to your TV and check the log for response. This is so you can check your TV capability if needed

SendURL This will allow you to send a full url including the http:// to your TV screen. This will be handy for showing remote streams or dashboards, websites. No apps needed on the TV.

Terminate Apps This will close out all smart apps and turn the TV back to tuner mode.

10 Likes

looks great, will try it tomorrow :+1:. Would you be willing to add this to hubitat package manager?

can't get volume to work but it's doing stuff :slight_smile:

image

Gawking at Stephen Fry's runcible spoons? :wink:

1 Like

:rofl: :rofl:

was just the channel it landed on when testing, i knew someone would call it out :slight_smile:

Oh sure it was.

:wink:

1 Like

Your TV is older so it may have a different API version for volume. Also, are you trying set level or pressing volume up or volume down?

Can you do the below steps and then send me the response from your log?

  1. Change refresh to 30 minutes
  2. Enable debug log
  3. On the SendDebugString button paste the below fields
    libpath= /sony/audio
    jsonmsg= {"method":"getMethodTypes","id":73,"params":[""],"version":"1.0"}
  4. Send me the log piece that says sony response
1 Like

both. it shows up on the screen so must be triggering something, it just doesn't change. reboot works, mute, change input and call the apps :slight_smile: so not bad.

Okay, press volumeup and show the log from that. Your API is version 1.2 (same as mine). So call should be working. I know my setlevel may not work correctly when sound is going out through ARC.
Do you have sound going out through a soundbar or receiver?

yes. i think that's the cause

I think I can force it, but it's going to depend on the sound device. I'll check later and see. My TV outputs to a soundbar and max on the soundbar is 30 and max on the TV is 100, so setlevel doesn't know what to do, but volumeup and volume down work great. Set level works great on my Sony soundbar because it's the primary device, not the slave.

I might have to add a logic that checks the current sound output device and vary the setvolume depending on the setting.

2 Likes

get this when its off as well? anyway to disable the poll?

Yeah I caught that last night. Fix will be in next version. Also I'll try to get this on hpm.

1 Like

I am probably going to poll only things that change like volume input and power. Things like the Mac and serial and stuff only when the save button is hit.
Also going to add a few other settings like speaker output, powersave, to the states.

1 Like

posted an update to the github on the first post. Main changes are listed below.

New Features
added some of the channel/input info as an attribute.
added the ability to see if sound is going through the TV speakers or out through HDMI
added attribute to check is WakeOnLan or PowerSave is enabled

Optimizations
Info like mac addresses, tv serial, and powersave settings will only check every 30 minutes or when save button is clicked on driver.

Updated debug logging to display certain rows as info to make them more distinct.

Bugfixes
Added a parse for the response from the SOAP call that sends button commands, this is just to prevent a groovy error that showed up when you send a button command.

Polling will only check the powerstatus when the TV is off. An error was being thrown when the volume level was getting checked when the TV is off.

I was sending volume change to TV speakers only. Now the command SHOULD update whatever the speaker output is.

1 Like

Surely that any needs to check on the save, as them values never change unless the IP is changed to which he could have changed the TV?

Hi @ajones,
Thank you very much for this driver!!!

I'm living in The Netherlands, so I've got some Dutch apps on my tv which I would like to add to my personal App Menu. I have to add that my programming knowledge is non-existent...

I have downloaded the displaycontrol.html and I have discovered the Knowledge Center. getApplicationList (v1.0) | BRAVIA Professional Displays Knowledge Center

However, I cannot produce a list of Apps on my television... Could you please point me in the right direction?

Thank you in advance.

Hi @ajones,

Super nice driver you've done, thanks! I have a question... is there a way to know if the TV is on/off in rule machine?

Hi Yes, you can query your TV directly and update a few lines of code. Steps to find the app URL on your TV is below.

  1. Turn refresh interval to 30 minutes and enable debug logging.
  2. Enter below two strings into senddebugstring button
    libpath= /sony/appControl
    jsonmsg= {"method": "getApplicationList","id": 60,"params": [],"version": "1.0"}
  3. Open log and filter by your TV device.
  4. There will be an Info log with a response saying "raw data result is" followed by a list of apps.
  5. In the string, there will be a field below for each app you have. You are interested in the URI for the app.
    [title:YouTube, uri:*com.sony.dtv.com.google.android.youtube.tv.com.google.android.apps.youtube.tv.activity.ShellActivity*
  6. Take the URI for the app you want to add it to line 584 of the code in the same format as the lines above it.
  7. Then replace any appname in line 33-45 with the name you added next to the URI. There is a Hubitat limit to the number of dropdowns on this button, so that's why I have a limited app list here.
  8. Remember to change your refresh back to whatever it was before. This step is just so your logs don't get spammed each minute with messages you don't need.

SendDebugString

Yes, it reports a state change just like any zwave outlet you would buy. You just check switch for on/off. I have mine checking every minute.