Toggle Script

Posted on
Thu Oct 10, 2019 9:02 am
Umtauscher offline
User avatar
Posts: 553
Joined: Oct 03, 2014
Location: Cologne, Germany

Toggle Script

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

Posted on
Thu Oct 10, 2019 9:35 am
FlyingDiver offline
User avatar
Posts: 5411
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Toggle Script

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).

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Oct 10, 2019 10:07 am
Umtauscher offline
User avatar
Posts: 553
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Toggle Script

Thanks Joe,

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

Posted on
Thu Oct 10, 2019 11:14 am
FlyingDiver offline
User avatar
Posts: 5411
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Toggle Script

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')

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Oct 10, 2019 11:23 am
Umtauscher offline
User avatar
Posts: 553
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Toggle Script

Yes it does, thanks a lot!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest