Changing Vizio TV Inputs with Google Assistant via openHAB

Was getting frustrated with needing my remote to swap inputs on my Vizio E50-F2 (I use it as a computer monitor, to watch casts and to watch OTA TV. Did some searching for an API (because one must exist) and found a library - pyvisio - https://github.com/vkorn/pyvizio. My implementation is kind of kludgy & probably will not work on pi without jumping through path and permission hoops, but it works for me and hopefully helps you, if you need. Took me longer to document what I did than to do it.

Existing configuration: openHAB 2 on Windows, python installed, some of my items already available through google assistant, Vizio E50-F2 tv


Install pyvisio - https://github.com/vkorn/pyvizio

pip3 install git+https://github.com/vkorn/pyvizio.git@master

One time setup
Get the IP of the TV
my tv has 2 connections, this lets me know which one to use
(I think one is for casts, one is for control?)

>pyvizio --ip=0 --auth=0 discover INFO:pyvizio.cli:Available devices: IP Model Friendly name 192.168.0.17 E50-F2 Vizio TV

Start the pairing. PIN code appears top center of television

pyvizio --ip=192.168.0.17 pair
INFO:pyvizio.cli:Initiating pairing process, please check your TV for pin upon success
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
INFO:pyvizio.cli:Challenge type: 1
INFO:pyvizio.cli:Challenge token: 809647

replace value for --token= with the Challenge token: from previos step
replace value for --pin= with the 4 digit pin top ceenter of the tv.
This step may need to be done while the PIN is displayed

pyvizio --ip=192.168.0.17 pair-finish --token=809647 --pin=6186
INFO:pyvizio.cli:Finishing pairing
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
INFO:pyvizio.cli:Authorization token: Zynv0at4fz

To avoid repeating IP and Auth params, you can add them to environment variables as VIZIO_IP and VIZIO_AUTH respectively

initial setup complete

Get list of inputs, so we can switch later
NB: github documentation may have input-list swapped with input_list
Ignore InsecureRequestWarning

pyvizio --ip=192.168.0.17 --auth=Zynv0at4fz input-list
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
INFO:pyvizio.cli:Available inputs:
Name Friendly name Type ID
CAST SMARTCAST T_DEVICE_V1 4003165621
HDMI-1 Computer T_DEVICE_V1 2812393194
HDMI-2 HDMI-2 T_DEVICE_V1 292178829
HDMI-3 HDMI-3 T_DEVICE_V1 3938325493
COMP COMP T_DEVICE_V1 2214376780
TV 6-1 CBWT-DT T_DEVICE_V1 4293234485

Missing from this list is WATCHFREE for Pluto
CAST is SmartCast
ignore the InsecureRequestWarning

Test out some calls from the command line
Switch to HDMI-1 (computer monitor)

pyvizio --ip=192.168.0.17 --auth=Zynv0at4fz input --name=HDMI-1
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
INFO:pyvizio.cli:Switching input
INFO:pyvizio.cli:OK

click the Input button on the remote…

pyvizio --ip=192.168.0.17 --auth=Zynv0at4fz input-next
c:\users\theclyde\appdata\local\programs\python\python37-32\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
INFO:pyvizio.cli:Circling input
INFO:pyvizio.cli:OK

all commands

  • input-next
  • input --name=HDMI-1 {CAST|HDMI-1|HDMI-2|HDMI-3|COMP|TV}
  • power {on|off|toggle}
  • power
  • volume {up|down} amount
  • volume_current
  • mute {on|off|toggle}
  • channel {up|down|prev} amount

Add items to openHAB
[“Switchable”] to show up in Google Home “Hey Google, turn Pluto Input On”
able to fuzzy search “Hey Google, turn Pluto On”
has voice control conflict with existing TV on/off command because of this
Does not need to be in your Home or a Room in google home to work, but I have put my openHAB
items in an openHAB room

Switch pyvizio_input_computer  "Computer Input"    ["Switchable"]
Switch pyvizio_input_tv        "TV Input"          ["Switchable"]
Switch pyvizio_input_cast      "SmartCast Input"   ["Switchable"]
Switch pyvizio_input_next      "Next Input"        ["Switchable"]
Switch pyvizio_input_pluto     "Pluto Input"       ["Switchable"]

Add rules

var VIZIO_IP = "192.168.0.17"
var VIZIO_AUTH = "Zynv0at4fz"

rule "pyvizio_input_computer"
when
    Item pyvizio_input_computer received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input --name=HDMI-1")
end

rule "pyvizio_mute"
when
    Item pyvizio_mute received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " mute toggle")
end

rule "pyvizio_input_computer"
when
   Item pyvizio_input_computer received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input --name=HDMI-1")
end

rule "pyvizio_input_tv"
when
   Item pyvizio_input_tv received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input --name=TV")
end

rule "pyvizio_input_cast"
when
    Item pyvizio_input_cast received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input --name=CAST")
end

rule "pyvizio_input_pluto"
when
    Item pyvizio_input_pluto received command
then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input --name=WATCHFREE")
end

rule "pyvizio_input_next"
when
    Item pyvizio_input_next received command
 then
    executeCommandLine("pyvizio --ip=" + VIZIO_IP + " --auth=" + VIZIO_AUTH  + " input-next")
end

Sync google - either “ok google, sync my devices” or “ok google, sync openhab”

1 Like

Why do you think that? Python is pretty OS independent. I don’t see anything that makes me think it wouldn’t work on a Pi.

I would request that you put your code in code fences.

When you do, paste the code into the forum between the code fences again. The forum will convert "" to ‘’" (note they are slightly different) which do not work in code. As it is above, it will not work if users try to just copy and paste.

I think the Exec binding would work for this.

Thanks for posting!

Good point about the code fences, will edit presently.

re: python - I guess I meant you may have to jump through a lot more hoops, as windows relieves me of a lot of path and permission restraints. I could be wrong, as I have not run it on a pi and have not run linux for a while.

thanks