Now I have to figure how to pass temp to Python and read back from
Learn some basic ifs in Python
Figure a way to make the script a generic function that I pass a long the temp the various ranges
Seems gonna be a bumby ride
Not to discourage you from doing any of this independently, as I think it's very worthwhile/fun, and I suspect it won't be as challenging for you as you think. But here is one of
many different ways you could do this using Python in VC.
I think it's a nice example of something that many VC users -- with varying backgrounds and levels of technical know-how -- might want to experiment with.
(Maybe others can follow up with other suggested solutions, to give everyone an idea of the many ways to tackle the same problem?
...)
Within my VC command I check the temperature using the WUnder plugin, and then execute the Python file, checkTemp.py (attached), which handles the rest.
To figure out how to get my LastResult (temperature) data from VC for my Python script,
I referred to the wiki documentation on using Python. http://voxcommando.com/mediawiki/index.php?title=PythonI also directly stole from the "Actions" example on that page, as you will see.
As per the documentation, LastResult returns a string, and we don't want a string for our purposes.
As you mention above, we also don't necessarily want to restrict ourselves to integers, since WUnder data sometimes returns decimal temp values. I begin by converting the string to a floating point value.
Python makes this kind of string to int or string to float conversion very easy, and a quick Google search usually retrieves the correct syntax without a lot of hunting.
Here is my VC command.
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.3.1-->
<command id="1155" name="checktemp" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>WUnder.GetCustom</cmdType>
<params>
<param>{C.temp_c}</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>PY.ExecFile</cmdType>
<params>
<param>PY\checkTemp.py</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<phrase>What's the temperature, How warm is it, How cold is it</phrase>
<phrase optional="true">outside, out there</phrase>
</command>
I've attached the Python file; I usually place my Python files in the PY folder of my VC directory, but whatever floats your boat.
I'm pasting the Python code from my checkTemp.py file here below (this is the same as what is in the attachment), just for those who want to see the code without having to download the attachment and try it for themselves.
The main thing to be careful of with Python is indentation levels. I write my code in Notepad++. (Update: there is now a decent editor/script tester in the Python plugin window itself:
http://voxcommando.com/mediawiki/index.php?title=Python#Testing_Code)
tempC=float(vc.getObject("LastResult",""))
if 0 <= tempC <= 10:
vc.callAction("TTS.Speak","It is pretty cold. You might want a hat.", None)
vc.callAction("OSD.ShowText","It is pretty cold.", None)
elif 10 <= tempC <= 19:
vc.callAction("TTS.Speak","It is chilly. You'll want a light jacket.", None)
vc.callAction("OSD.ShowText","It is chilly out.", None)
elif 19 <= tempC < 30:
vc.callAction("TTS.Speak","It is perfect weather. You should find a patio and knock back a cold one.", None)
vc.callAction("OSD.ShowText","It is perfect weather.", None)
else:
vc.callAction("TTS.Speak","It is %s degrees Celsius"%tempC, None)
vc.callAction("OSD.ShowText","It is %s degrees Celsius."%tempC, None)
As you can see, I've used your range of temps from 0 to 30 degrees Celsius, with my "else" covering the exceptions.
Follow up discussion, alternative solutions are encouraged!