Umtauscher wrote:Thanks a lot Neil, and it looks so simple....
Thanks again
Wilhelm
Not a problem, I should probably have added some comments, and I corrected an error I spotted editing the original post ( adding the 'u' due to the accented characters in your device name to declare it as unicode). In my defence I am English and we expect everyone else to speak our language, even if our America cousins get a little confused with the spelling
Let me know if you need any help as any errors should be easy to flush out.
- Code: Select all
# the standard python 'os' module gives access to operating system capability, in this case I will use 'os.system' to execute the commands from your AppleScript
# this is really just fire and forget and assumes they run successfully, look into subprocess if you want greater control and feedback from the execution
# the import makes the 'os' module available to this script (probably an overly simplistic explanation, but it will do)
import os
# the python try/except block allows you to test some code for errors, and handle them if an error occurs, the indentation following the try and identifies the code either to be tried, or on error
try:
# in this case I am trying to set the variable 'var' to the value of the indigo variable "AlarmScharf", if the variable does not exist it will cause an error
var = indigo.variables["AlarmScharf"]
except:
# which is then caught in the except block on error, and the line below creates the indigo variable and sets the value to false, indigo variables are strings
indigo.variable.create("AlarmScharf", "false")
# os.system simply executes the command
os.system("afplay /Users/wilhelm/Music/STARWAVE/c827.WAV")
# the if statement is pretty clear (and uses the same principle of indentation that was used in the try/except block)
# in the if statement you don't actually need the "== True", you can omit it as the device state is a boolean but it reads a little more clearly when new to python
# the 'u' is to identify the literal that follows is unicode, as your device name has accented characters
if indigo.devices[u"Alarmsensoren ausgelöst"].onState == True:
os.system('say "Alarmsensoren sind aktiv, der Alarm kann nicht scharfgeschaltet werden"')
else:
indigo.variable.updateValue(AlarmScharf, "true")
os.system('say "Alarm ist scharf"')
I am still a Python novice and get some of the basics wrong (like forgetting unicode), but I did follow Jay's advice and did one of the online tutorials (the free one from Microsoft
https://www.youtube.com/watch?v=jFCNu1-Xdsw) and conversations I previously didn't follow now make sense, and I even managed to knock out a plugin or two with the help of the Indigo hive (especially Jay, Joe and Dave)
Neil