For the Vizio I use the rest interface so I have a rest_command.yaml included that contains this:
vizio_processkey:
url: 'https://{{ ip }}:{{ port }}/key_command/'
method: put
content_type: "application/json"
headers:
AUTH: '{{ auth }}'
payload: '{"KEYLIST": [{"CODESET": {{ codeset | int }},"CODE": {{ code | int }},"ACTION":"KEYPRESS"}]}'
verify_ssl: false
Then the buttons use custom:button_card with templates. A TV template would be:
bedroom_vizio:
triggers_update: all
variables:
tv: bedroom_vizio
ip: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'bedroom_vizio').ip ]]]
port: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'bedroom_vizio').port ]]]
auth: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'bedroom_vizio').auth ]]]
clientaddr: >-
[[[ return states['sensor.vizio_tvs'].attributes.tvs.find(x=>x.name ==
'bedroom_vizio').clientAddr ]]]
This is reading attributes for the IP, PORT, AUTH for the bedroom_vizio TV a sensor that reads that data from a JSON file I keep around with all the TV data, It also reads the CLIENTADDR which is a code for the DIrecTV box if you have Genie devices.
A snippet of this custom JSON file is like this (my auth and clientAddr is blocked out, you would need yours and also the proper IP address. For a Vizio, the port is likely 7345. As you can see, I also create a map of my favorite channels (on DIrecTV and a set of inputs or quick actions to get to DirecTV or Netflix or Hulu in one click):
{
"tvs": [
{
"name": "patio_vizio",
"ip": "192.168.2.90",
"port": 7345,
"auth": "************",
"clientAddr": "**************",
"favorites": [
{
"callsign": "ESPNHD",
"channel": 206
},
{
"callsign": "ESPN2HD",
"channel": 209
},
{
"callsign": "NFLHD",
"channel": 202
},
{
"callsign": "NFLHD",
"channel": 212
},
{
"callsign": "NHLHD",
"channel": 215
},
{
"callsign": "MLBHD",
"channel": 213
},
{
"callsign": "NBAHD",
"channel": 216
},
{
"callsign": "GolfHD",
"channel": 218
},
{
"callsign": "FS1HD",
"channel": 219
},
{
"callsign": "NBCSHD",
"channel": 220
},
{
"callsign": "CBSSHND",
"channel": 221
},
{
"callsign": "RedZone",
"channel": 702
},
{
"callsign": "BTNHD",
"channel": 610
}
],
"inputs": [
{
"fname": "Power off",
"input": "Power off"
},
{
"fname": "DirecTV",
"input": "HDMI-1"
},
{
"fname": "Smartcast",
"input": "CAST"
},
{
"fname": "Netflix",
"input": "Netflix"
},
{
"fname": "HBOMax",
"input": "HBO Max"
},
{
"fname": "YouTube",
"input": "YouTube"
},
{
"fname": "Amazon Prime",
"input": "Prime"
},
{
"fname": "Hulu",
"input": "Hulu"
},
{
"fname": "AppleTV",
"input": "Apple TV"
},
{
"fname": "Discovery+",
"input": "discovery+"
},
{
"fname": "Disney+",
"input": "Disney+"
},
{
"fname": "Fox Now",
"input": "FOX NOW"
}
]
},
Then another button_card_template is used to create the actual action:
vizio_action:
variables:
codeset: 4
code: 3
tap_action:
action: call-service
service: rest_command.vizio_processkey
service_data:
ip: '[[[ return variables.ip ]]]'
port: '[[[ return variables.port ]]]'
auth: '[[[ return variables.auth ]]]'
codeset: '[[[ return variables.codeset ]]]'
code: '[[[ return variables.code ]]]'
The IP and PORT and AUTH codes are stored in a JSON file. So at least you do not have to repeat all these things within the code of a button as that card supports templates which import.
Using the custom:button-card and templates totally simplifies things. Like this:
- type: custom:button-card
icon: mdi:arrow-up-circle
template:
- icon_button
- bedroom_vizio
- vizio_action
variables:
codeset: 3
code: 8
So a button just needs to set the codeset and code. You could actually go further and do a lookup table and pass a variable like âupâ but I did not go that far because I believe all Vizioâs have the same REST interface and it would save passing one variable (you would have a table that said âupâ is codeset 3, code 8 ⌠you would still pass âupâ. Possibly that could be nice understanding though.
Putting that all together, that button is like clicking the âup arrowâ on a remote. The TV would be the bedroom_vizio television (whose template gets the IP, PORT and AUTH code) and it sends codeset 3 and code 8 in the rest_command.
I am just starting to write this up and post all the code for both DIrecTV and Vizio but there are many things/assumptions in mine because of my setup. I also have Broadlink setup for a few TVs to do the volume because these are in old stereo recievers that have no interface except IR. But I will post it all for people to chop up as they desire.