Page 1 of 1

Convert to Python

PostPosted: Wed Dec 18, 2019 1:02 pm
by ckeyes888
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

Re: Convert to Python

PostPosted: Wed Dec 18, 2019 1:45 pm
by jay (support)
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.

Re: Convert to Python

PostPosted: Wed Dec 18, 2019 6:44 pm
by ckeyes888
Perfect, thanks Jay. Thought the last if was an issue.

Carl

Re: Convert to Python

PostPosted: Thu Dec 19, 2019 6:33 pm
by ckeyes888
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

Re: Convert to Python

PostPosted: Thu Dec 19, 2019 6:46 pm
by FlyingDiver
Comparing an integer value to off isn’t likely to work.


Sent from my iPhone using Tapatalk

Re: Convert to Python

PostPosted: Thu Dec 19, 2019 7:05 pm
by ckeyes888
Yep, that was it.

Thanks,

Carl