Vizio TV Binding

logo

This is a new binding to control Vizio TVs via openHAB.
The TV must support the Vizio SmartCast API that is found on 2016 and later models. The binding must be used with openHAB 3.3.0 and later.

Supported Things

There is currently only one supported thing type, which represents a Vizio TV using the vizio_tv id.
Multiple Things can be added if more than one Vizio TV is to be controlled. If Eco mode is used, the TV must be turned on at binding startup to retrieve the TV’s self-signed SSL certificate.

Discovery

Auto-discovery is supported if the Vizio TV can be located on the local network using mDNS.
Otherwise the thing must be manually added.
When the TV is discovered, a pairing process to obtain an authentication token from the TV must be completed using the openHAB console. See below for details.

Binding Configuration

The binding has no configuration options, all configuration is done at the Thing level.

Thing Configuration

The thing has a few configuration parameters:

Parameter Description
hostName The host name or IP address of the Vizio TV. Mandatory.
port The port on the Vizio TV that listens for https connections. Default 7345; Use 9000 for older model TVs.
authToken The token that is used to authenticate all commands sent to the TV. See below for instructions to obtain via the openHAB console.
appListJson A JSON string that defines the apps that are available in the activeApp channel drop down. See below for instructions for editing.

Console Commands for Pairing:

To obtain an authorization token that enables openHAB to authenticate with the TV, the following console commands must be used while the TV is turned on.
The first command will send a pairing start request to the TV. This triggers the TV to display a 4-digit PIN code on screen that must be sent with the second command.

Start Pairing:

openhab:vizio <thingUID> start_pairing <deviceName>

Substitute <thingUID> with thing’s id, ie: vizio_tv:00bc3e711660
Substitute <deviceName> the desired device name that will appear in the TV’s settings, under Mobile Devices, ie: Vizio-openHAB

Submit Pairing Code:

openhab:vizio <thingUID> submit_code <pairingCode>

Substitute <thingUID> with the same thing id used above
Substitute <pairingCode> with the 4-digit pairing code displayed on the TV, ie: 1234

The console should then indicate that pairing was successful (token will be displayed) and that the token was saved to the thing configuration.
If using file-based provisioning of the thing, the authorization token must be added to the thing configuration manually.
With an authorization token in place, the binding can now control the TV.

The authorization token text can be re-used in the event that it becomes necessary to setup the binding again.
By simply adding the token that is already recognized by the TV to the thing configuration, the pairing process can be bypassed.

Channels

The following channels are available:

Channel ID Item Type Description
power Switch Turn the power on the TV on or off. Note: The TV cannot be turned back on if power is switched off and the TV is configured for Eco mode.
volume Dimmer Control the volume on the TV (0-100%).
mute Switch Mute or unmute the volume on the TV.
source String Select the source input on the TV. The dropdown list is automatically populated from the TV.
activeApp String A dropdown containing a list of streaming apps defined by the appListJson config option that can be launched by the binding. An app started via remote control is automatically selected.
control Player Control Playback e.g. Play/Pause/Next/Previous/FForward/Rewind
button String Sends a remote control command the TV. See list of available commands below.

List of available button commands for Vizio TVs:

PowerOn
PowerOff
PowerToggle
VolumeUp
VolumeDown
MuteOn (may only work as a toggle)
MuteOff (may only work as a toggle)
MuteToggle
ChannelUp
ChannelDown
PreviousCh
InputToggle
SeekFwd
SeekBack
Play
Pause
Up
Down
Left
Right
Ok
Back
Info
Menu
Home
Exit
Smartcast
ccToggle
PictureMode
WideMode
WideToggle

App List Configuration:

The Vizio API to launch and identify currently running apps on the TV is very complex.
To handle this, the binding maintains a JSON database of applications and their associated metadata in order to populate the activeApp dropdown with available apps.

When the thing is started for the first time, this JSON database is saved into the appListJson configuration parameter.
This list of apps can be edited via the script editor on the thing configuration.
By editing the JSON, apps that are not desired can be removed from the activeApp dropdown and newly discovered apps can be added.

An entry for an application has a name element and a config element containing APP_ID, NAME_SPACE and MESSAGE (null for most apps):

{
   "name": "Crackle",
   "config": {
      "APP_ID": "5",
      "NAME_SPACE": 4,
      "MESSAGE": null
   }
},

If an app is running that is not currently recognized by the binding, the activeApp channel will display a message that contains the APP_ID and NAME_SPACE which can be used to create the missing record for that app in the JSON.

If an app that is in the JSON database is not recognized by the biding when running or fails to start when selected, try adjusting the NAME_SPACE value for that app. NAME_SPACE seems to be a version number and adjusting the number up or down may correct the mis-match between the TV and the binding.

A current list of APP_ID’s can be found at http://hometest.buddytv.netdna-cdn.com/appservice/vizio_apps_prod.json
and NAME_SPACE & MESSAGE values needed can be found at http://hometest.buddytv.netdna-cdn.com/appservice/app_availability_prod.json

If there is an error in the user supplied appListJson, the thing will fail to start and display a CONFIGURATION_PENDING message.
If all text in appListJson is removed (set to null) and the thing configuration saved, the binding will restore appListJson from the binding’s JSON db.

Full Example

vizio.things:

// Vizio TV
vizio:vizio_tv:mytv1 "My Vizio TV" [ hostName="192.168.10.1", port=7345, authToken="idspisp0pd" ]

vizio.items:

// Vizio TV items:

Switch TV_Power       "Power"              { channel="vizio:vizio_player:mytv1:power" }
Dimmer TV_Volume      "Volume [%d %%]"     { channel="vizio:vizio_player:mytv1:volume" }
Switch TV_Mute        "Mute"               { channel="vizio:vizio_player:mytv1:mute" }
String TV_Source      "Source Input [%s]"  { channel="vizio:vizio_player:mytv1:source" }
String TV_ActiveApp   "Current App: [%s]"  { channel="vizio:vizio_player:mytv1:activeApp" }
Player TV_Control     "Playback Control"   { channel="vizio:vizio_player:mytv1:control" }
String TV_Button      "Send Command to TV" { channel="vizio:vizio_player:mytv1:button" }

vizio.sitemap:

sitemap vizio label="Vizio" {
    Frame label="My Vizio TV" {
        Switch item=TV_Power
        // Volume can be a Setpoint also
        Slider item=TV_Volume minValue=0 maxValue=100 step=1 icon="soundvolume"
        Switch item=TV_Mute icon="soundvolume_mute"
        Selection item=TV_Source icon="screen"
        Selection item=TV_ActiveApp icon="screen"
        Default item=TV_Control
        Selection item=TV_Button
    }
}

Changelog

Version 1.0.0 Beta

Initial Add-on Marketplace release of Vizio binding

Version 1.1.0 Beta

Fix issue with pairing and only poll for linked channels

Version 1.1.1 Beta

Handle ipv6 address if used by thing

Resources

https://github.com/mlobstein/openhab-addons/releases/download/1.0.0/org.openhab.binding.vizio-3.4.0-SNAPSHOT.jar

1 Like

Thanks for your efforts.
I recently bought a Vizio for use as both a PC monitor and TV. I ran into an error with the start_pairing maybe because I was using a monitor?. When I switched to Smartcast I do not see any code. I searched settings and found a 4 digit code under Admin & Privacy…Support Code. Is that how it is supposed to work? I entered the code and OH shows as online, channels appear, but do not work yet, but I did not submit the code in the console yet. I wanted to make sure this was just not some random code.

The PIN code will actually display on the top of the screen when the pairing process is triggered. Here is what it looks like on mine. You probably want to just be on an HDMI input or TV channel (not in a streaming app) when doing this.

This is what the console interaction will look like:

You mention that your Vizio is a monitor? Or you are using a TV as a monitor? Can you try to use the Vizio Mobile app on android? It uses the same pairing process that the binding it attempting to emulate.

Thanks for the information I was using the HDMI and did not get that display. Let me try again. I’ll also copy the error message if I get one… I’m on IOS, but there should be a vizio app for that will check that out too.

Edit: ok worked ! Thanks. Do not know what the earlier problem was.

Thanks for the feedback and I am glad to hear that it worked. There were a few minor issues with the pairing process that I have fixed in the latest build.

When I turn the TV off, the “Thing” shows Offline communication error. That’s okay as it is true. What is odd, is that I get a log full of errors when the TV is turned back on. Everything works, so there is no lasting issue. Odder still, of the three times, no errors once. That time it was only off for a couple of hours. The other times it was overnight. Maybe a timing issue?
Visio-errors.txt (24.9 KB)

It looks like the code that gets the self-signed certificate from the TV is getting sent a mangled host name/IP address somehow. I will try to address that. Can you try and see if the issues go away if the ‘Eco Mode’ setting on the TV is turned off?

Turned eco off, will let you know.
Bob
Edit: None of the above error messages in the last two days with eco off. it does use 8 watts in this quick start mode

I don’t know how it happened for you, but in the error messages the binding was trying to use an ipv6 address to communicate with the TV. I have updated the code to correctly create the URL if an ipv6 address is encountered.

I turned on Eco Mode on my TV and did not observe this behavior. My TV dropped off of the wi-fi network almost immediately when switched off in Eco Mode.

I can’t explain the ipv6. Loaded new jar and will go back to eco mode. Will let you know. Since it seemed to happen only overnight, will need a day or so. Again thanks

Bob

Still seems to be an issue with eco mode after an overnight shutdown
Visio-errors.txt (34.8 KB)
Binding


Sorry to be a bother

Just to understand, do you shutdown your openHAB instance at night? The behavior seen is when the binding attempts to retrieve the self-signed certificate from the TV at startup. It fails to connect if the TV is off in Eco mode.
Currently the TlsTrustManagerProvider code cannot handle this properly. @cweitkamp Do you have any suggestions to make the getTrustManager() method able to handle a temporarily un-reachable host?

No nightly S/D of OH. I try to help out in the forum with testing, so only shutdown is to get next milestone. I’m on 3.4M1 at this point. My whole testing of the Vizio has been with no interruption of OH

I did notice the first error message was from the core. I was wondering if there is a way in the UI to extend the certificate expiration? These errors only has happen overnight, so don’t know if the cert is cleared at midnight if the device is down or after some number of hours. Also since it does work (even after the error messages, maybe some delay to get the certs in order?

Another thought, my wife actually unplugs the Sony overnight, but the sony binding seems to come back ok. I don’t know the details, but it does some sort of wake on lan (WOL). That log over a few days (we plug the TV in about 8pm;

2022-08-29 19:55:18.041 [INFO ] [g.sony.internal.AbstractThingHandler] - Starting state polling every 60 seconds
2022-08-30 20:10:23.210 [INFO ] [g.sony.internal.AbstractThingHandler] - Starting state polling every 60 seconds
2022-08-31 19:52:16.701 [INFO ] [g.sony.internal.AbstractThingHandler] - Starting state polling every 60 seconds
2022-09-01 19:17:10.566 [INFO ] [g.sony.internal.AbstractThingHandler] - Starting state polling every 60 seconds
2022-09-02 19:41:23.883 [INFO ] [g.sony.internal.AbstractThingHandler] - Starting state polling every 60 seconds

Hi @mlobstein,

after reviewing my code for the PEMTrunstManager I think it might be the better way to rethrow occuring IOExceptions instead of swallowing them and just log a warning.

After that change the calling instances are able to implement a proper error handling. One more question isn’t there a CertificateInstantiationException if the server is unreachable after an IOException? How do you handle that in your code?

I have updated the build to suppress the error message that is generated when the attempt to retrieve the TV’s certificate fails. I will revisit once @cweitkamp adjusts the PEMTrustManager code. If an IOException is thrown, I could catch this and re-try until successful.

Won’t I still get the first error from the core? Anyway will give it a go (I had just removed the binding until this was sorted)

edit: If I’m on the right page, it looks like the last change was 5 days ago?

Yeah you are right the “An unexpected exception occurred” message from getPEMCertificateFromServer() in core will still occur. Any exceptions from VizioTlsTrustManagerProvider (malformed url, etc.) will now go to the debug log instead of the error log.

@cweitkamp I will need to change my code to handle the certificate retrieval failure. I think a simple flag being set after the successful retrieval will be enough. If the flag is not set, any commands send to the TV will trigger another retrieval attempt.

The method getInstanceFromServer(URL) either returns a valid PEMTrustManager or throws an exception if the instantiation fails. I will change the code to throw a CertificateInstantiationException which cause is set to the IOException thrown. The log message will be suppressed in such case. This way there is no breaking change in core implementation, just an improvement of the code.

1 Like

PR