Skip to content

TV Channel Change

Northern Man edited this page Apr 16, 2020 · 4 revisions

As part of my goal to Alexa enable my entertainment centre, you can now change the channels on your TV by voice and say such things as Alexa, change channel to CTV on TV or Alexa, change channel to 9 on TV. Setup for this will require installing node-red and to change the channels on your TV, you will need an IR Blaster or something similar that you can control thru node-red.

This flow was written for my setup which uses an ESP8266-HTTP-IR-Blaster device controlling an LG TV. The IR Codes are part of the node Channel to Code and will need to be updated for a different TV. If your using a different IR Blaster, you will need to update the logic in Channel to Code to create the message for your controller.

Steps

  1. Install node-red and the node node-red-contrib-homekit-bridged

  2. Install from flow into node-red

  3. Edit the node "Station to Node" to map your stations to the channel number.

  4. Update the node IR Blaster to point to your IR Blaster device.

  5. In the homebridge-alexa config.json, add the channel change device config option. Details here

  6. Deploy and good luck

Here is my flow

[{"id":"813ecfd3.76e62","type":"debug","z":"a781f703.dc51e","name":"Channel","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":380,"y":220,"wires":[]},{"id":"33649007.91bfc","type":"homekit-service","z":"a781f703.dc51e","isParent":true,"bridge":"b29a0b93.d191d","parentService":"","name":"Channel","serviceName":"Television","topic":"","filter":false,"manufacturer":"Channel","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\"ConfiguredName\":true}","x":80,"y":160,"wires":[["effe6fdf.0e08f"]]},{"id":"3a68c4b2.0c46f4","type":"debug","z":"a781f703.dc51e","name":"Channel Number","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":220,"wires":[]},{"id":"2cfec13.15b073e","type":"debug","z":"a781f703.dc51e","name":"Blaster","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1000,"y":220,"wires":[]},{"id":"1e8524c8.c4c9e3","type":"function","z":"a781f703.dc51e","name":"Channel to Code","func":"var channel = msg.payload;\nvar response = [];\n\n\nresponse.push({\n \"type\": \"nec\",\n \"data\": \"20DFF00F\", // Tuner\n \"length\": 32,\n \"repeat\": 1,\n \"rdelay\": 100\n});\n\nresponse.push({\n \"type\": \"delay\",\n \"rdelay\": 700\n});\n\n\n[...channel].forEach((item, i) => {\n // console.log(item, i);\n var data;\n switch (item) {\n case \"0\":\n data = \"20DF08F7\";\n break;\n case \"1\":\n data = \"20DF8877\";\n break;\n case \"2\":\n data = \"20DF48B7\";\n break;\n case \"3\":\n data = \"20DFC837\";\n break;\n case \"4\":\n data = \"20DF28D7\";\n break;\n case \"5\":\n data = \"20DFA857\";\n break;\n case \"6\":\n data = \"20DF6897\";\n break;\n case \"7\":\n data = \"20DFE817\";\n break;\n case \"8\":\n data = \"20DF18E7\";\n break;\n case \"9\":\n data = \"20DF9867\";\n break;\n case \"-\":\n data = \"20DF32CD\"; // - key\n break;\n default:\n console.log(\"ERROR: missing symbol\");\n }\n // /msg?repeat=2&rdelay=100&pdelay=1&code=20DF33CC:NEC:32?simple=1\n response.push({\n \"type\": \"nec\",\n \"data\": data,\n \"length\": 32,\n \"repeat\": 1,\n \"rdelay\": 100\n });\n \n response.push({\n \"type\": \"delay\",\n \"rdelay\": 700\n });\n});\n\n\nresponse.push({\n \"type\": \"nec\",\n \"data\": \"20DF22DD\", // Enter/OK\n \"length\": 32,\n \"repeat\": 1,\n \"rdelay\": 100\n});\n\nmsg.payload = response;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":160,"wires":[["6e9ae43c.24216c"]]},{"id":"effe6fdf.0e08f","type":"switch","z":"a781f703.dc51e","name":"","property":"payload.ConfiguredName","propertyType":"msg","rules":[{"t":"regex","v":"^[0-9]*$","vt":"str","case":false},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":210,"y":160,"wires":[["319c012.dc08bfe","813ecfd3.76e62"],["8af7bc55.09fb9","813ecfd3.76e62"]]},{"id":"6e9ae43c.24216c","type":"http request","z":"a781f703.dc51e","name":"IR Blaster","method":"POST","ret":"txt","paytoqs":true,"url":"http://192.168.1.62/json?simple=1","tls":"","persist":false,"proxy":"","authType":"","x":840,"y":160,"wires":[["2cfec13.15b073e"]]},{"id":"a13fb229.5b53b","type":"inject","z":"a781f703.dc51e","name":"Fox","topic":"","payload":"{\"ConfiguredName\":\"29\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":60,"wires":[["319c012.dc08bfe"]]},{"id":"109b0ce5.e612c3","type":"inject","z":"a781f703.dc51e","name":"CTV","topic":"","payload":"{\"ConfiguredName\":\"9\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":100,"wires":[["319c012.dc08bfe"]]},{"id":"8af7bc55.09fb9","type":"function","z":"a781f703.dc51e","name":"Station to Channel","func":"var station = msg.payload.ConfiguredName;\nvar data = \"\";\n\nswitch (station) {\n case \"ctv\":\n data = \"9-1\";\n break;\n case \"cbc\":\n data = \"5-1\";\n break;\n case \"create\":\n data = \"17-2\";\n break;\n case \"fox\":\n data = \"29-1\";\n break;\n case \"citytv\":\n data = \"57-1\";\n break;\n case \"global\":\n data = \"41-1\";\n break;\n case \"globaltv\":\n data = \"41-1\";\n break;\n case \"global tv\":\n data = \"41-1\";\n break;\n case \"ptv global\":\n data = \"41-1\";\n break;\n case \"pbs\":\n data = \"17-1\";\n break;\n case \"tvo\":\n data = \"19-1\";\n break;\n default:\n console.log(\"ERROR: unknown station\", station);\n }\n\nmsg.payload = data;\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":160,"wires":[["1e8524c8.c4c9e3","3a68c4b2.0c46f4"]]},{"id":"319c012.dc08bfe","type":"function","z":"a781f703.dc51e","name":"Normalize Channel","func":"msg.payload = msg.payload.ConfiguredName + \"-1\";\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":100,"wires":[["1e8524c8.c4c9e3","3a68c4b2.0c46f4"]]},{"id":"b29a0b93.d191d","type":"homekit-bridge","z":"","bridgeName":"Walter-NodeRed-Channel","pinCode":"031-45-154","port":"51840","allowInsecureRequest":true,"manufacturer":"node-red","model":"Default Model","serialNo":"Default Serial Number","customMdnsConfig":false,"mdnsMulticast":true,"mdnsInterface":"","mdnsPort":"","mdnsIp":"","mdnsTtl":"","mdnsLoopback":true,"mdnsReuseAddr":true}]

Clone this wiki locally