Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - claymic

Pages: [1] 2 3 ... 10
1
Kodi (XBMC) Frodo / Gotham / Isengard / Jarvis / Re: XBMC radio add-on?
« on: October 25, 2013, 12:37:25 PM »
I use the tune.in here, works fine. Thanks for the reply i will test the rad.io here. Today is my day to install VoxCommando in my new htpc, i will have some fun.

2
Kodi (XBMC) Frodo / Gotham / Isengard / Jarvis / Re: XBMC radio add-on?
« on: October 25, 2013, 11:41:42 AM »
Hi guys,
This add-on is better then the Tune.in ? I never used the rad.io
Thanks
Clayton

3
Very thanks to share Kalle.
Cool  ;)

4
Python Scripting / Re: We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 03:41:24 PM »
 :biglaugh :biglaugh :biglaugh :biglaugh
James
When we use a Results.SetVar we are not setting a Global Variable too ? Do you think that we have to avoid it too ? I have to be very carefull now, i will insert several and several new function in Vox, i dot want to mess up with anything.
Thanks for your help
Clayton

5
Python Scripting / Re: We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 11:48:02 AM »
 :biglaugh :biglaugh :biglaugh :biglaugh :biglaugh :biglaugh
I have to remember to not ask you guys to fix anything for me in the future.

6
Python Scripting / Re: We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 10:31:24 AM »
I am a bad programmer.
Really ?..... :bonk
If you are a bad programmer i dont know who will be good.
You are much modest today.

7
Python Scripting / Re: We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 10:17:17 AM »
Thanks Kalle.
James, sometimes there is no other way, we have to use Global Variables, but i will avoid to use this if possible. Thanks for the tip.
Clayton

8
Python Scripting / Re: We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 09:41:51 AM »
Ok, i think that will be nice to explain how to get the value of the "variable3" that we set in the function "changeVariables()".
Lets change our script test and insert a new line on it:
Code: [Select]
#Global Variables
variable1 = "test1"
variable2 = "test2"
def changeVariables():
    variable1 = "change1"
    variable2 = "change2"
    #Local Variable
    variable3 = variable1+variable2
    return variable3
def changeVariablesGlobal():
    global variable1
    global variable2
    variable1 = "change1"
    variable2 = "change2"
We insert the "return variable3" in the function, when we do that Python will return any data of us, in this case it will return our variable3.
Now we have to insert a new action in VoxCommando

Get the files and make a test.
Hope that help
Clayton

9
Python Scripting / We Need To Talk About Python - 1 Variables
« on: May 28, 2013, 09:16:19 AM »
OK, i decided to learn Python to use with Vox, i am more comfortable with Javascript and i really love it. Somethings in python let me crazy sometimes, so i decided to share here what i learn, when i get sometime free of course  ;D
Today i will try to explain how python treat Local and Global variables.
Dont worry about the previous explanations, the example will cover everything that you need.
- What is a Local Variable :
  Well, like the name suggest, "local variables" can only be used inside the function that was created.
- What is a Global Variables:
  You can call this variables from any place in the code.
Let see the examples and learn how we can change Global Variables inside a function.
Code: [Select]
#Global Variables
variable1 = "test1"
variable2 = "test2"
def changeVariables():
    variable1 = "change1"
    variable2 = "change2"
    #Local Variable
    variable3 = variable1+variable2
def changeVariablesGlobal():
    global variable1
    global variable2
    variable1 = "change1"
    variable2 = "change2"
Copy the code above and save in your "PY" folder, give the name TestVariables.py.
Now, see in the code that we have three variables. Two of them are declared outside the functions (variable1 and variable2), when we do that we are creating Global Variables and we can use this variables in any place of the code, see that i am using this variables in the function "changeVariables" to set the value of another variable.
The "variable3" otherwise its a Local Variable, was declared inside the function "changeVariables", so we can only use it inside this function, if you try to use this variable in the function "changeVariablesGlobal" you will get a error.
So far so good, but Python its a bad snake, we have to understand how to change the Global Variables now.
Lets put Vox to teach us. Copy the command bellow and paste in your VoxCommando, i think that you already now how to do that and i believe that you already put your script the folder PY, if you need change the path.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1791" name="variables" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecFile</cmdType>
    <cmdString>PY\TestVariables.py</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>changeVariables()</cmdString>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>changeVariablesGlobal()</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>result = variable1 + " " + variable2</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{LastResult}&amp;&amp;3000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>
So, now that you have the command we need to edit it to make some tests. Set your command like the picture bellow:

Ok, let understand the actions.
We will block the actions 2 and 3 (see the picture above) for this test.
Now, when we run the command, the action 1 will run the script file, everything that is outside a function will run, in our case we have only this outside the function:
Code: [Select]
variable1 = "test1"
variable2 = "test2"
So when Vox run the script this will set our global variables.
In the action 4 we will set our result to be equal to the variable1 and variable2, in the action 5 we show the result, so Vox will show this to you:

Nice...now we know how to set and use Global Variables in Vox.
To next test we will set the command like this:

Ok...see that now we enable the action 2. When we ask Vox to run the "PY.ExecString" we are saying to Vox to only run a small peace of code, in our case this means that we will run the function "changeVariables()", see:
Code: [Select]
def changeVariables():
    variable1 = "change1"
    variable2 = "change2"
    #Local Variable
    variable3 = "test3"
When we do that, the script will not run anything more, this means that the Global Variables will not be set again in our case.
What will be the result when we run the command in Vox ? Will be the same, the snake bite us ;D

In the function changeVariables() we are setting the values of the variable1 and the variable2, but when we do that we are not setting the value of the Global Variable, because Python will understand this like a Local Variable.
So, How we can change the value of a Global Variable ? Before  change the value of any Global Variable (if we are inside the function) we have to tell Python that it is a Global Variable. See the function changeVariablesGlobal()
Code: [Select]
def changeVariablesGlobal():
    global variable1
    global variable2
    variable1 = "change1"
    variable2 = "change2"
See ? We have to use the "global variable1", this will tell for Python that we will change the value of the Global Variable.
Now set your command in Vox like the picture bellow:

Run the command and now we will have a new result:

Ok...we can now use Global Variables in all our scripts, once we set the value of a Global Variable we can get this value from any place in our code, even in a different script.
Hope that help
Clayton

10
Python Scripting / Re: File.Read
« on: May 27, 2013, 10:08:32 PM »
By the way...thanks for change the
Code: [Select]
File.WriteAnd since you are working hard this days, maybe you can insert a option in the actions window to determine a time (miliseconds) that this action will have to wait to run again, will be a nice future.
Thanks again for all your help and all the improvements in VoxCommando.

11
Python Scripting / Re: File.Read
« on: May 27, 2013, 10:05:27 PM »
I don't know what you are asking me any more...  it is a bit hard to follow after all your posts.

What error are you getting?  Maybe if you can upload all the xml and all the python that you are using, I can try to make some sense of it.
Impossible.  vc.callAction will never return a value.

The first question I would ask is, why is the sensor sending the event more than once?  What kind of sensor is it?

One way to avoid the problem with the sensor triggering multiple times is this.

1 - When your code is initialized, store the current time in a variable called "lastTriggerTime".
2 - Every time the sensor triggers your code, you compare the current time to the last time that was stored in lastTriggerTime.  If it has been less than 5 seconds (or whatever period of time works best) then exit.
3 - Update the variable lastTriggerTime to the current time.

another option would be to use a timer, but that is more difficult.
Ok, you can test this by yourself, but this is working
Code: [Select]
powerArCondition =vc.callAction("File.Read","{Path.VC}\Devices\ArGree.txt",None)I tested this a few minutes ago, but maybe i did something wrong or forgot to delete something, but i am almost sure that this is working because was my first test with a OSD showing the value of the powerArCondition, before change the script.
What i want understand is how Vox call the actions when a script is running (or stating to run), because i need to understand if this is a asynchronous thing. Sorry but i will not be able to explain again, try to read my last posts, i know, my English is bad, but i explained two situations: One its using the action to set a variable and prevent the action to run again, the other way is use the script, but the action run every time that i get a new feedback (its a serial feedback).
My objective its not exactly put the code to work, i can do this in a few ways. What i want is understand how a action, a event and a script are related.
- If two events run almost at the same time, and the first event have a script, what will run first ? The script or the second event ? In the example that i put in the previous post the second event run first.
- If a script is running and Vox get another event that trigger a action, what will happen ? Vox will wait until the script stop to run or will execute the action immediately ?
I have to understand this to prevent a variable to change before the script finish the code, among other things.


12
Python Scripting / Re: File.Read
« on: May 27, 2013, 08:02:31 PM »
Maybe i can use something like {PreviousCommand} to avoid the sensor to speek the TTS again, but this will not let me to prevent errors. Who knows, i have to test.

13
Python Scripting / Re: File.Read
« on: May 27, 2013, 07:43:52 PM »
Ops, this is the event that will run after 1 second
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="1645" name="porta home speek" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>PY.ExecString</cmdType>
    <cmdString>sensorControl["DOORSPEEK"] = "True"</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>speekDoor</event>
</command>

14
Python Scripting / Re: File.Read
« on: May 27, 2013, 07:41:36 PM »
Thanks James, i will use rstrip() to remove the line for now.
I am a little tired, but i will post another question here, its about the same script.
My sensor sometimes send not only one feedback, but 2 o 3, in less then one second.
To avoid the action to run 2 or 3 times i created a dic
Code: [Select]
sensorControl = {
   "GARAGESPEEK""" :"True",
   "GARAGESPEEKFECHADO""" :"True",
   "DOORSPEEK" : "True",
   "DOORSPEEKFECHADO" : "True",
   "WINDOWSIDESPEEK": "True",
   "WINDOWCOUCHSPEEK": "True",
}
So, when the door of my room is opened i get the feedback and this will run a event :

See that i set the DOORSPEEK to false, then wait for 1 second to avoid the action to run again, since i am getting 2 or 3 feedback in 200 or 300ms.
In another action i am monitoring the air condition, everytime that i power on or power off the Air Condition using my ipad a event is sent for Vox and i set the state of the AC
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="409" name="CFPower ArGree" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>File.WriteLine</cmdType>
    <cmdString>{Path.VC}\Devices\ArGree.txt&amp;&amp;Ligado</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>File.WriteLine</cmdType>
    <cmdString>{Path.VC}\Devices\ArGreeTemp.txt&amp;&amp;{2}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>ArGree</event>
</command>
Now, when the door is opened the script run and if the AC is power on a TTS will inform that and ask to close the door. I will insert the rest of the code tomorrow, if the door dont close in 1 minute vox will power off the AC.
Now, my question, finally.
Every thing works fine with the action above, but let say that i want to do the same thing using only the script. I blocked the "IF condition" and tried this code :
Code: [Select]
powerArCondition = vc.getObject("lastresult", None)
powerArCondition  = powerArCondition.rstrip()
doorSpeek = sensorControl["DOORSPEEK"]
doorSpeekFechado = sensorControl["DOORSPEEKFECHADO"]
def _doorOpen():
   vc.callAction("OSD.ShowText",powerArCondition+doorSpeek, None)
   if powerArCondition == "Ligado" and doorSpeek == "True":
      sensorControl["DOORSPEEK"]= "False"
      vc.callAction("TTS.Speak","Porta aberta", None)
      vc.callAction("VC.SetEventTimer","1&&speekDoor",None)
      variable = "True"
   else:
      variable = "False"
   return variable
But with this i get 2 or 3 TTS. I think that before run the script vox is running the action 2 or 3 times (from the feedback).
I dont know if i explain right, but what i wanna do its prevent the action to run again (sensorControl["DOORSPEEK"]= "False") and avoid this serial feedback from my sensors. I can use the first method above(works), but i believe that this code will be very big in a near future, i just start to make it and i will insert several conditions, so i will prefer to use the script to control everything, if its possible of course.
Thanks for your help.
Clayton

15
Python Scripting / Re: File.Read
« on: May 27, 2013, 07:07:26 PM »
Same thing, this is a copy of the text
Ligado

You can see a new line in the end.

Pages: [1] 2 3 ... 10