Author Topic: Python and voxcommando with infrared signals  (Read 9442 times)

0 Members and 1 Guest are viewing this topic.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Python and voxcommando with infrared signals
« on: May 03, 2013, 02:27:56 PM »
Greeting's all
Another new guy to VC, found the program on XBMC forums and absolutely loving it. My extend of knowledge with programming is as much as installing XBMC, although I've now spent three days on learning Python and I'm hooked!

A bit about my setup:
Amplifier
Projector
HTPC (XBMC on OpenELEC)
Television
Using Global Cache iTach to control all devices.

At the moment I'm using VC on my pc learning how things work.
I've a managed to setup IR Codes from VC to iTach via EventGhost. I know James is working on a TCPip plugin, but until then I'm having fun learning.

*side note* - if using iConvert from Global Cache to convert hex decimal ir codes to global cache codes make sure to close VC and EG, cause if you copy and paste hex codes into iConvert it won't work. Trust me I spent a full day learning hex codes to find the problem, in the end it was just cause VC was open. Something about the two program's that iConvert doesn't like. Once converted to global cache code everything works fine.

1. What I'd like to do is have all my IR Codes in one file with the code needed to connect to the iTach and just call on words to send the codes eg:
TV-On = ircode
TV-Off = ircode
The bit I'm stuck on is the connection between VC and calling the code. I know the macro  PY.ExecFile to execute a python file, but from there I'm lost. Do I put something in the parameter to run it or execute something or does it go in a payload? Speaking of which, parameters and payloads I still haven't completely understood yet. I'm guessing something like a payload XML might help?
Does anyone know of some good documentation that might help explain how python, XML and VC work together? Or some more tutorials I haven't found yet?

2. I've also been playing around with groups, which by the way is a 'WAY COOL' feature.  Is there a way to have a group return to the previous state?
Eg: group 1, 2, and 3.
Group 1 & 2 are enabled - give a command and 1 & 2 are disabled and 3 is enabled. At this point, is there a command to have 3 disable and not just enable 1 &2 but use something that returns to previous state which a would be 1 & 2 enabled and 3 disabled.

Well that's about it, feel free to share some advice, in the mean time ill keep reading.
Thumbs up on such a great product too.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Python and voxcommando with infrared signals
« Reply #1 on: May 03, 2013, 07:28:55 PM »
Hi Mace,

Welcome to the VC community.

PayloadXML files let you store a large number of phrases.  When you use them in a command, which ever one you say becomes a payload.  A payloadXML can either be set up to use the phrases itself as the payload, or to map it to a value.  In your case with the iTach, you would want to map your phrase ("power on") to a value (the iTach sequence).  When we talk about things that we can say that have a value we can use later, we call it a payload.

It is easy to confuse payloads with parameters because they are very similar.  Once the speech engine figure out which command you are saying it will execute it and pass the payloads if any along to the "macro" for that command.  This "macro" is made up of the actions that are defined in the LCB (logical command builder) for a given command.  Actions usually do one thing.  Actions will usually expect parameters.  Some parameters are required for the action to work, and some are optional.  In the LCB you can specify the parameters as "static" (unchanging) values that always do the same thing, or you can use payloads to make them more "dynamic".  If you have defined a command with a payload, you are only 1/2 done.  You still need to make sure that you use the payload.  You don't have to, but usually you want to, and if you want you can use the payload more than once in your macro.

EventGhost also uses payloads, which can cause a certain amount of confusion.  In EventGhost we have events.  The name of the event is generally what determines which commands will be executed, and a payload can carry extra data, so the concept is very similar to a payload in VoxCommando.

One important note about payloadXML files is that they can't be the only part of a command.  You should have some other phrase before them that indentifies the command.

example:  "play artist" >> payloadXML of all artists

When you say "play artist" VC will know which command you are executing and will attach a value (payload) for which ever artist you want.  But you can't just say an artist name by itself.  If you want to do that you need to create a command for each artist.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #2 on: May 03, 2013, 08:16:44 PM »
Excellent!
That's some great information for my learning curve.

So i can map a 'phrase' to a 'value' in a payloadXML eg: Power On sends Ir value.

Does a payloadXML run the same as a python script?
using your example:
If i had a payload XML of all my IR codes for all my devices,  i could then use a command, which could be the same title as the payload, which will gather the correct code and execute it? is that correct?

Can it work as a single python script with all the data ie:

import socket

s = socket.socket()
HOST = "iTachip"
PORT = 4998
s.connect((HOST,PORT))

s.send()

print s.recv(1124)
s.close()

And have a list of all IR codes in there with a variable somehow (haven't worked that part out yet) that when VC executes a PY.ExecFile command it will send the Phase/payload and send the correct value matched to the payload.

At least this is what i'm thinking. My goal is to have all codes in one spot so they are easy to alter should i change devices and need to update codes, then it's only a matter of the initial setup.

i have a feeling i'm talking about 2 of the same thing. No doubt i'll look back in a week and think what a stupid ass question, but least it might help someone in the mean time.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Python and voxcommando with infrared signals
« Reply #3 on: May 03, 2013, 10:33:08 PM »
I'm not sure I quite follow you here,   but maybe it will be clear when I give you an example, which I will do soon.

In this python code you posted, you are using s.send() without any parameters.  This is where the payload value would go... as in s.send (payload1).  It would be the string that gets sent to the itach to initiate a particular IR blast.  If you wanted to, you could do this using the python plugin in VC but it will be a bit easier with the TCP plugin I think.

If you want you can send me some of your itach codes and I'll use them in a real example for you.

If you have not already viewed them, please watch these tutorials:
http://voxcommando.com/forum/index.php?topic=1004.0

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #4 on: May 04, 2013, 04:21:37 AM »
Yep exactly right, at the moment I use ' import module' to grab the string name I need and put that in s.send () in each command in EG. Sorry should have added that bit in, the joys of trying to do something constructive after night shift. When I'm back home ill add some codes here to make more sense for everyone.

The bit I'm stuck on is what to put in here () so that when I send a payload string name (string name I'm calling the keywork- PowerOn = ircode)  from VC command it will place it in s.send (PowerOn) and send the code.
I'd like to have one script and VC just sends whatever payload from a command and the script will use it.

Maybe an input function, I'm not sure.

data = input ()
S.send (data)

More reading, I'm sure ill get it. On the plus side its fun learning about all the python script I don't need right now. lol



Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #5 on: May 04, 2013, 05:38:04 AM »
James, you write here a very helpful explanation how the payloads in VC works  :clap
You can add some text from your first post in the WiKi.

Kalle
***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Python and voxcommando with infrared signals
« Reply #6 on: May 04, 2013, 08:15:14 AM »
http://gphangouts.com/google/hangout/software/111676462313545255894/

Feel free to join our weekly goggle plus hangout today for help.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #7 on: May 04, 2013, 09:37:37 AM »
If I wasn't working I'd be there.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #8 on: May 04, 2013, 08:57:23 PM »
ok for those interested here's how to make python work with Global Cache (iTach) Ir Codes.

Python Script:

Code: [Select]
import socket

TvPowerOn = "sendir,1:1,1,38000,1,1,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,64,21,1517,341,85,21,3655"+"\r\n"
TvPowerOff "sendir,1:1,1,38000,1,1,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,1517,341,85,21,3655"+"\r\n"


s = socket.socket()
HOST = "Enter Ip of iTach"
PORT = 4998
s.connect((HOST,PORT))

data=input()
s.send(data)

print s.recv(1124)
s.close()

That's about it, run that script and when presented with command prompt type in 'TvPowerOn' and code gets sent.
but i have no idea yet how to make that work in VC.

p.s TCPip Plugin does exactly this and works like a charm.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #9 on: May 05, 2013, 04:09:04 AM »
Hi mace, nice work  :clap
I think a good start for how do you make the script work with VC is here: http://voxcommando.com/mediawiki/index.php?title=Python

I hope it helps
« Last Edit: May 05, 2013, 08:32:29 AM by jitterjames »
***********  get excited and make things  **********

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #10 on: May 05, 2013, 10:12:01 AM »
Thanks Kalle, I'll pay around with some of those option and see what else I need to play with

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Python and voxcommando with infrared signals
« Reply #11 on: May 05, 2013, 12:43:07 PM »
This will give you something interesting to think about, play with, and hopefully will prove useful to people who are interested in learning more about how VoxCommando and Python can work together...

Note that I'm not using the TCP plugin at all here, but there are ways that it could be integrated as well.

Save the attached file into your "VoxCommando\py" folder and then edit it as necessary with your own codes and the correct IP address for your iTach.  This file contains python code that will be loaded into the python "machine" when VC starts, and it defines some functions that we can later call from our actions.

then import the following group and start to play:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="Python iTach Tests" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="893" name="do python test" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>result=iTach_TV('VOL DOWN')</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <cmdString>{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>result=iTach_TV('VOL UP')</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <cmdString>{LastResult}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>do python test</phrase>
  </command>
  <command id="894" name="load python startup code" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <cmdString>py\mapping.py</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>load python startup code</phrase>
    <event>python ready</event>
  </command>
</commandGroup>

If you need help, maybe we can "hangout" today at some point, if you want.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #12 on: May 05, 2013, 01:27:30 PM »
A true genius!

Look forward to trying this out when I get home from work.
Currently 2:30 in the morning. Got to love night shift.
Am free tomorrow
« Last Edit: May 05, 2013, 01:31:08 PM by Mace »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Python and voxcommando with infrared signals
« Reply #13 on: May 05, 2013, 02:30:02 PM »
Tricky.  You are 14 hours ahead of us here, and you work night shifts.  If we are going to hang-out at some point, you'll have to suggest a possible time that might work for both of us.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Re: Python and voxcommando with infrared signals
« Reply #14 on: May 05, 2013, 02:41:49 PM »
One bonus of working nights and days, it doesn't really matter what time of day or night to hang-out, so long as its days off. And working a roster means it changes every week.
Next 4 days are free, send me a message if any time in there suits.