Help converting a simple AppleScript Serveraction to Python

Posted on
Sun Jan 26, 2020 7:11 pm
Dave G offline
Posts: 2
Joined: Apr 23, 2019

Help converting a simple AppleScript Serveraction to Python

Maybe I'm getting to be an old dog, but my programming days go back to C and Unix and I'm not up, at the moment, to hone my object-oriented programming skills.

I've got some simple AppleScript code embedded in a Server Action on a Control Page in Indigo that switches a Somfy shade remote control from Open to Close:

#
# The original AppleScript was:
#
# if (binary outputs of device "Guest BR roller shades") is equal to {false} then
# set binary outputs of device "Guest BR roller shades" to {true}
# else
# set binary outputs of device "Guest BR roller shades" to {false}
# end if
#

I know this is simple switch logic, but could somebody help me do a quick conversion to Python? Thanks so much.

Posted on
Mon Jan 27, 2020 10:02 am
jay (support) offline
Site Admin
User avatar
Posts: 16820
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help converting a simple AppleScript Serveraction to Py

Code: Select all
roller_shades = indigo.devices[1234567890] # "Guest BR roller shades" - substitute ID of this device
# If the first output of the device is True - your script implies a binary output device with only 1 output - so we get the first (and only) one.
# Note that you could write it "if roller_shades.binaryOutputs[0] is True", but since the values of the binaryOutputs list are booleans it's not necessary.
if roller_shades.binaryOutputs[0]:
    # the output is True so set it to False
    indigo.iodevice.setBinaryOutput(roller_shades, index=0, value=False)
else:
    # the output is False so set it to True
    indigo.iodevice.setBinaryOutput(roller_shades, index=0, value=True)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests