Page 1 of 1

Toggle Script

PostPosted: Thu Oct 10, 2019 9:02 am
by Umtauscher
Hi guys,

I really need some help converting this simple AppleScript in python or a workarround without scripting.
The virtual device "Musiccast Badezimmer" has to be toggled by calling 2 action groups.

Code: Select all
tell application "IndigoServer"
   if on state of device "Lautsprecher Badezimmer" is false then
      execute group "Musiccast Badezimmer On"
   else
      execute group "Musiccast Badezimmer Off"
   end if
end tell


I am really frustrated having such problems to convert one simple If then else statement to python and why do I even have to script such a simple thing?
What am I missing?
TIA
Wilhelm

Re: Toggle Script

PostPosted: Thu Oct 10, 2019 9:35 am
by FlyingDiver
Code: Select all
dev = indigo.devices[91776575]              # ID of "Lautsprecher Badezimmer"
if dev.onState:
    indigo.actionGroup.execute(12345678)    # ID of "Musiccast Badezimmer Off"
else:
    indigo.actionGroup.execute(65432996)    # ID of "Musiccast Badezimmer On"


I am really frustrated having such problems to convert one simple If then else statement to python and why do I even have to script such a simple thing?
What am I missing?


As you can see, the Python code is just as simple as the AS code. Though I do agree that Virtual Devices ought to be able to have a default implementation for the toggle action. All it really needs is a way to specify what the default condition is (on or off).

Re: Toggle Script

PostPosted: Thu Oct 10, 2019 10:07 am
by Umtauscher
Thanks Joe,

that helps.
What would I have to do to use the device names instead of the ids?

Re: Toggle Script

PostPosted: Thu Oct 10, 2019 11:14 am
by FlyingDiver
Umtauscher wrote:
What would I have to do to use the device names instead of the ids?


I think this works, but it's generally considered bad practice. Changing the name breaks the script. Using the ID it doesn't.

Code: Select all
dev = indigo.devices['Lautsprecher Badezimmer'] 
if dev.onState:
    indigo.actionGroup.execute('Musiccast Badezimmer Of')
else:
    indigo.actionGroup.execute('Musiccast Badezimmer On')

Re: Toggle Script

PostPosted: Thu Oct 10, 2019 11:23 am
by Umtauscher
Yes it does, thanks a lot!