Vizio SmartCast TV configuration via pyvizio

I have been attempting to setup my Vizio Tv on my Hass.io running on my RaspberryPi3b+.

When I enter

pyvizio --ip=0 discover

I receive the following output

INFO:pyvizio.cli:Available devices:
IP      Model      Friendly name

I thought maybe I’ll just skip the discover step since I already know the IP and that it is a TV so I tried

pyvizio --ip=192.168.1.40 --device_type=tv pair
(tried using :9000 and :7345 to the same ends)

but the connection keeps timing out and I get the following

INFO:pyvizio.cli:Initiating pairing process, please check your device for pin upon success

ERROR:pyvizio.vizio:Failed to execute command: HTTPSConnectionPool(host='192.169.1.40', port=7345): Max retries exceeded with url: /pairing/start (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10db93910>: Failed to establish a new connection: [Errno 60] Operation timed out'))

I’m not sure where to go from here to get myself an authentication token. Any help would be appreciated. Thanks.

UPDATE: I am attempting to pair from my mac terminal running python 3.7.4 and pip 19.0.3

I don’t know if this will help with your issue, but you don’t need to use pyvizio to pair with your TV. You can do it from the command line. I wrote this script a while back and I don’t want to re-pair my TV, but from memory I think that both of the variables that it prompts for will appear on either the TV or in your terminal. Modify the IP address and port as needed.

#!/bin/bash

VIZIO_IP="192.168.0.15"
VIZIO_PORT="7345"

curl -k -H "Content-Type: application/json" -X PUT -d '{"DEVICE_ID":"pyvizio","DEVICE_NAME":"Python Vizio"}' https://${VIZIO_IP}:${VIZIO_PORT}/pairing/start

read -p "PIN:  " VIZIO_PIN
read -p "PAIRING_REQ_TOKEN:  " VIZIO_PAIRING_REQ_TOKEN

curl -k -H "Content-Type: application/json" -X PUT -d '{"DEVICE_ID": "pyvizio","CHALLENGE_TYPE": 1,"RESPONSE_VALUE": "'"${VIZIO_PIN}"'","PAIRING_REQ_TOKEN": '"${VIZIO_PAIRING_REQ_TOKEN}"'}' https://${VIZIO_IP}:${VIZIO_PORT}/pairing/pair

I know this is an older post, but can you be so kind as to walk me through how you run this script? I’m getting an error on line 6, referencing the curl: command not found. Any insight?

EDIT: I got this to work! but the issue now seems to be the controls on hassio don’t actually control anything on the tv. meaning, i’ll hit the power button or volume button on hassio and the tv doesn’t respond. any thoughts?

I am having issues setting this up following these steps. Everything works until the last command, which fails with the error below. I am running Home Assistant on an older Intel Nuc. I had initially setup my Vizio on a raspberry pi 3. It was working perfectly on my Nuc but then just quit working until my pfsense box SSD failed. I setup an older router I had so everything on DHCP got new IP addresses. I thought just changing the IP in configuration.yaml would fix it but it did not.

pyvizio --ip=0 discover

*pi@pihole:~ $ pyvizio --ip=0 discover*
*INFO:pyvizio:[ZeroconfDevice(ip='xxx.xxx.x.x', port='7345', name='TV', model='TV', id='None')]*
*INFO:pyvizio.cli:*
*IP              Port  Model    Name*
*------------  ------  -------  ------*
*xxx.xxx.x.x    7345  TV       TV*

All good, run the next command

pyvizio --ip=xxx.xxx.x.x:7345 --device_type=tv pair

Initially I was getting the below so I checked and it was still paired on my Vizio in Menu>System>Mobile Devices so I removed it, unplugged my vizio for 1 minute. Verified that the integration had been removed, commented out the previous successful connection in configuration.yaml, rebooted HA, Then attempted again but got the same message.

INFO:pyvizio.cli:Initiating pairing process, check your device for pin upon success
ERROR:asyncio:SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0xb53d48b0>
transport: <_SelectorSocketTransport fd=6 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
  File "/usr/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/usr/lib/python3.7/asyncio/sslproto.py", line 207, in feed_ssldata
    self._sslobj.unwrap()
  File "/usr/lib/python3.7/ssl.py", line 767, in unwrap
    return self._sslobj.shutdown()
ssl.SSLError: [SSL: KRB5_S_INIT] application data after close notify (_ssl.c:2609)

So, my mistake, I initially had been running these commands from Windows laptop using the Linux subsystem installed with Ubuntu. I tried repeatedly from my Raspberry pi 3 and 4 but got the same results. Below are the steps I took but I’m pretty sure running the pair commands as sudo is what was causing the issue the entire time.

1 - Deleted .db file from config. Might seem like overkill but was over 1GB and I have had issues once the db gets to big like history not working or taking forever to load
2 - I did a complete Entity cleanup. This is much easier in the latest version of HA
3 - Removed Integration. It was still there but with no devices.
4 - Synced with Amazon and Google after entity cleanup. This probably made zero difference but did it anyways
5 - Unplugged TV, waited on minute, plugged back in and turned on.

I ran the below. I’m pretty sure running the last two commands as sudo is what made it work.

pi@raspberrypi:~ $ pyvizio --ip=0 discover
INFO:pyvizio:[ZeroconfDevice({'name': 'TV', 'ip': 'xxx.xxx.xxx.xxx', 'port': 7345, 'model': 'TV', 'id': None})]
INFO:pyvizio.cli:
IP             Port  Model    Name
-----------  ------  -------  ------
xxx.xxx.xxx.xxx    7345  TV       TV
pi@raspberrypi:~ $ sudo pyvizio --ip=xxx.xxx.xxx.xxx:7345 --device_type=tv pair
INFO:pyvizio.cli:Initiating pairing process, check your device for pin upon success
INFO:pyvizio.cli:Challenge type: 1
INFO:pyvizio.cli:Challenge token: 123456
pi@raspberrypi:~ $ ^C
pi@raspberrypi:~ $ xxxx
bash: xxxx: command not found
pi@raspberrypi:~ $ sudo pyvizio --ip=xxx.xxx.xxx.xxx:7345 --device_type=tv pair-finish --ch_type=1 --token=500511 --pin=xxxx
INFO:pyvizio.cli:Finishing pairing
INFO:pyvizio.cli:Authorization token: 0123456789
pi@raspberrypi:~ $

6 - Added configuration.yaml entry
7 - Rebooted, went to Integrations, added and everything is working
8 - Save the Authorization Token somewhere to be safe