Convert to Python

Posted on
Wed Dec 18, 2019 1:02 pm
ckeyes888 offline
Posts: 2279
Joined: Nov 26, 2009
Location: Kalispell, MT

Convert to Python

I have some scripts that have an added twist that I'm not sure how to convert.
Appreciate any help!

Thanks,

Carl
Code: Select all
tell application "IndigoServer"
   if the value of variable "GuestCeilingLight" is "0" then
      dim device "Bedroom Guest Lights" to "100"
   else
      if the value of variable "GuestCeilingLight" is "100" then
         dim device "Bedroom Guest Lights" to "35"
      else
         if the value of variable "GuestCeilingLight" is "35" then
            dim device "Bedroom Guest Lights" to "15"
         else
            if the value of variable "GuestCeilingLight" is "15" then
               dim device "Bedroom Guest Lights" to "100"
            else
               if the value of variable "GuestCeilingLight" is not "0" and the value of variable "GuestCeilingLight" is not "35" and the value of variable "GuestCeilingLight" is not "15" and the value of variable "GuestCeilingLight" is not "100" then
                  dim "Bedroom Guest Lights" to "100"
               end if
            end if
         end if
      end if
   end if
end tell

Posted on
Wed Dec 18, 2019 1:45 pm
jay (support) offline
Site Admin
User avatar
Posts: 16778
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Convert to Python

This one is not tricky in any way. Here's a pretty straight-up conversion:

Code: Select all
bedroom_guest_lights = indigo.devices[IDOF_Bedroom_Guest_Lights]
guest_ceiling_light_var_value = indigo.variables[IDOF_GuestCeilingLight].getValue(int)
if guest_ceiling_light_var_value == 0:
    indigo.dimmer.setBrightness(bedroom_guest_lights, value=100)
elif guest_ceiling_light_var_value == 100:
    indigo.dimmer.setBrightness(bedroom_guest_lights, value=35)
elif guest_ceiling_light_var_value == 35:
    indigo.dimmer.setBrightness(bedroom_guest_lights, value=15)
elif guest_ceiling_light_var_value == 15:
    indigo.dimmer.setBrightness(bedroom_guest_lights, value=100)
elif guest_ceiling_light_var_value not in [0, 35, 15, 100]:
    indigo.dimmer.setBrightness(bedroom_guest_lights, value=100)


However, it could be further simplified while maintaining the exact logic of your script:

Code: Select all
bedroom_guest_lights = indigo.devices[IDOF_Bedroom_Guest_Lights]
guest_ceiling_light_var_value = indigo.variables[IDOF_GuestCeilingLight].getValue(int)
if guest_ceiling_light_var_value == 100:
    indigo.dimmer.setBrightness(guest_ceiling_light_var, value=35)
elif guest_ceiling_light_var_value == 35:
    indigo.dimmer.setBrightness(guest_ceiling_light_var, value=15)
else:
    indigo.dimmer.setBrightness(guest_ceiling_light_var, value=100)


Because the logic in the original script basically says that unless the value of the variable is 100 or 15, set the brightness to 100. For 100 it goes to 35 and for 35 it goes to 15.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 18, 2019 6:44 pm
ckeyes888 offline
Posts: 2279
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Perfect, thanks Jay. Thought the last if was an issue.

Carl

Posted on
Thu Dec 19, 2019 6:33 pm
ckeyes888 offline
Posts: 2279
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Thinking it will take me years to convert all my scripts.
I get stuck on the simplest bits of code. :(

I based this on the conversion you helped with but can't get it to work.
Code: Select all
ned_lights_var_value = indigo.variables[586928780].getValue(int) ##Varible NedLights
if ned_lights_var_value == off:
    indigo.actionGroup.execute(1961572810)
elif ned_lights_var_value == 1:
    indigo.actionGroup.execute(485838780)


Appreciate any help!

Thanks,

Carl

Posted on
Thu Dec 19, 2019 6:46 pm
FlyingDiver online
User avatar
Posts: 5321
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Convert to Python

Comparing an integer value to off isn’t likely to work.


Sent from my iPhone using Tapatalk

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

Posted on
Thu Dec 19, 2019 7:05 pm
ckeyes888 offline
Posts: 2279
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Yep, that was it.

Thanks,

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest