Applescript Conversion

Posted on
Fri Dec 22, 2017 4:45 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Applescript Conversion

Having quite o few of this type of AS I'd appreciate any help in converting it to Python.

Code: Select all
tell application "IndigoServer"
   if the value of variable "Awake" is "true" and the value of variable "NightstandLight" is "0" then
      dim device "Bedroom Upstairs Nightstand Light" to "100"
      
   else
      if the value of variable "Awake" is "true" and the value of variable "NightstandLight" is "100" then
         dim "Bedroom Upstairs Nightstand Light" to "40"
         
      else
         if the value of variable "Awake" is "true" and the value of variable "NightstandLight" is "40" then
            dim "Bedroom Upstairs Nightstand Light" to "100"
            
            
         else
            if the value of variable "Awake" is "false" and the value of variable "NightstandLight" is "0" then
               dim "Bedroom Upstairs Nightstand Light" to "40"
               
               
            else
               if the value of variable "Awake" is "false" and the value of variable "NightstandLight" is "40" then
                  dim "Bedroom Upstairs Nightstand Light" to "100"
               else
                  if the value of variable "Awake" is "true" and the value of variable "NightstandLight" is "off" then
                     dim "Bedroom Upstairs Nightstand Light" to "100"
                     
                  end if
                  
               end if
               
            end if
         end if
      end if
   end if
end tell


Thanks,

Carl

Posted on
Fri Dec 22, 2017 7:12 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Applescript Conversion

There are several ways to go about this--here is a (somewhat) literal conversion. Obviously, I can't test it.

Code: Select all
awake = indigo.variables["Awake"].value
night_stand_light = indigo.variables["NightstandLight"].value

if awake == "true" and night_stand_light == "0":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=100)
 
if awake == "true" and night_stand_light == "100":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=40)
 
if awake == "true" and night_stand_light == "40":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=100)
 
if awake == "false" and night_stand_light == "0":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=40)
 
if awake == "false" and night_stand_light == "40":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=100)
 
if awake == "true" and night_stand_light == "off":
    indigo.dimmer.setBrightness("Bedroom Upstairs Nightstand Light", value=100)
 

Once you convert the script to Python, it's good practice to use device and variable ID numbers rather than their names. It gives you greater protection against something breaking if the name of a device or variable should change. So you can (in my opinion, *should*) change: "Awake", "NightStandLight", and "Bedroom Upstairs Nightstand Light" to the corresponding ID numbers.

Please feel free to post back with any questions.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Dec 22, 2017 7:19 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Applescript Conversion

How is this script run? I don't think you actually need a script to do this. You could do it with multiple schedules or triggers.

Also, I think the script is either broken or redundant. Here's a table of the two inputs and the output:

Code: Select all
Awake       NightStandLight     Light

true        0                   100
true        100                 40
true        40                  100

false       0                   40
false       40                  100

true        off                 100


Looks like a value of 40 for the Light variable always sets it to 100, regardless of the value of awake. And since 0 == off, the last conditional shouldn't be needed.

Code: Select all
awake = indigo.variables[123]
NightStandLight = indigo.variables[456]
lightDevice = indigo.devices[7890]

if awake.value == "true" and NightStandLight.value == 0:
    indigo.dimmer.setBrightness(lightDevice, value=100)
elif awake.value == "true" and NightStandLight.value == 100:
    indigo.dimmer.setBrightness(lightDevice, value=40)

elif awake.value == "false" and NightStandLight.value == 0:
    indigo.dimmer.setBrightness(lightDevice, value=40)

elif NightStandLight.value == 40:
    indigo.dimmer.setBrightness(lightDevice, value=100)


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

Posted on
Fri Dec 22, 2017 9:24 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Applescript Conversion

Thanks a bunch all. Works great.
Now on to adapting the script to a hundred others. :?

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests