Jump to content

A/V Multiple digit Channel to Single digit Network Resource


dmorales

Recommended Posts

If you have old TVs that cannot be controlled by network (exposed API or else), you might find this useful. I have a few TVs like that, and the only way I have to control them is with an IR emitter such as iTach FLEX (one of many options on the market) or the TV remote itself.

By using the FLEX, you can create network resources in ISY that send messages to the FLEX with the desired IR code representing a single digit/button on your remote. Nothing new here, I've had this for years. But since the A/V device types showed up on the ISY Portal for Alexa, I saw how you could now instantiate a virtual device and tie actions such as volume or channel changing to either programs, variables or network resources. This by itself is cool, but still posed a challenge: how to convert a spoken number (normally 2-3 digits) in the instruction "Alexa, set channel to XX on device YY" to single digits for processing by individual network resource calls?

To achieve this, I've created a series of programs/network resources that handle such a thing, with the use of some simple math to split the number into its forming single digits. Example: "Alexa, set channel to 29 on device Bedroom TV" has to be converted to 2 different calls to network resources that represent the "2" and then the "9", and they must be executed in order to obtain the expected result. Let's see the code:

 

Step 1. Create a State Variable (for the full channel number) and a Integer Variable (for each digit to process)

Both should be precision 0 so this trick works 

image.png.6a349cc6cdfba3ada329521fb244e805.png

image.png.a619e9a9aad308382fee158eec85a197.png

 

Step 2. Create one network resource per digit (0 to 9)

This step is very dependent on what you are using to send the IR signal to the TV. Using iTach FLEX a network resource looks like this:

image.png.b20e6f88385c34bd56c269410a1c0d0d.png

Exported version of the same network resource above:

POST /api/v1/irports/1/sendir HTTP/1.1
Host: xxx.xxx.x.xxx:80
User-Agent: Mozilla/4.0
Connection: Close
Content-Type: application/x-www-form-urlencoded
Content-Length: 294

{
  "frequency": 38000,
  "irCode": "340,86,20,3664",
  "preamble": "340,169,20,20,20,20,20,64,20,20,20,20,20,20,20,20,20,20,20,64,20,64,20,20,20,64,20,64,20,64,20,64,20,64,20,20,20,20,20,20,20,20,20,64,20,20,20,20,20,20,20,64,20,64,20,64,20,64,20,20,20,64,20,64,20,64,20,1545",
  "repeat": 1
}

 

Step 3. Create a program for each digit (0 to 9) to call each corresponding network resource from above

image.png.8b327be445a313f1b9feb0f62f3b0d43.png

 

Step 4. Create a program to parse each digit you extract

Call all the single digit programs in order by the IF statement

image.png.656c7067b67d53ea82536a190087f9e1.png

 

Step 5. Create a program to trigger when the channel State Variable changes

image.png.a11284ebd83ccb54f55dcc5e7d9c4671.png

The key here is to get each digit by applying some simple math

  1. Full Channel DIV/ 10 = Digit 1. Example: 29 / 10 = 2.9 (saved in a prec 0 variable becomes 2)
  2. Full Channel MOD% 10 = Digit 2. Example: 29 % 10 = 9

 

Step 6. Configure your A/V device on the ISY Portal

image.thumb.png.4eab83f7360f4d9ec6b0dfc84ddb6b38.png

 

Step 7. You may need to forget the device and rediscover it in the Alexa app so it recognizes the changes

image.png.32f07b68123525874df2265bfb371c09.png

 

By now you should be able to ask "Alexa, set channel to 42 on deviceX" and voila! Watch it magically work! :)

 

DISCLAIMER: This will work as it is, with 2 digit channels. If you have digital TV, you might have 3 digit channels (ex 713). For that you would need to modify the logic of step 5 to parse the number 3 times with some more math:

Given channel 713, if you

  1. divide it by 1 and mod 10, you get 3
  2. divide it by 10 and mod 10, you get 1
  3. divide it by 100 and mod 10, you get 7
Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...