Script some calculations

Posted on
Thu May 16, 2019 10:55 am
Betacruxis offline
Posts: 60
Joined: Apr 03, 2010

Script some calculations

Hello guys.
I tried to convert to Python the following AS using the syntax in the other translations, but was unsuccessful.
Would you please convert it for me?
Thanks in advance.

Code: Select all
set Hum to round ((value of variable "Kitchen_Hum") as integer) + 0
if Hum > 100 then
   set value of variable "Kitchen_Hum" to 100
else
   set value of variable "Kitchen_Hum" to Hum
end if

set lum to round ((value of variable "Kitchen_Lum") as integer)
set value of variable "Kitchen_Lum" to lum

set temp to round ((((value of variable "Kitchen_Temp") as integer) - 32) * 5 / 9)
set value of variable "Kitchen_Temp" to temp

Posted on
Thu May 16, 2019 1:02 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Script some calculations

[MODERATOR NOTE] started a new thread for this post rather than adding it to an existing post.

Untested, but pretty close:

Code: Select all
# set Hum to round ((value of variable "Kitchen_Hum") as integer) + 0
kitchen_hum_var = indigo.variables[ID_OF_Kitchen_Hum]
hum = int(round(kitchen_hum_var.value)) # not sure why the +0, doesn't seem to do anything
# if kitchen_hum > 100 then
#    set value of variable "Kitchen_Hum" to 100
# else
#    set value of variable "Kitchen_Hum" to Hum
# end if
if hum > 100:
    indigo.variable.updateValue(kitchen_hum_var, value=str(100))
else:
    indigo.variable.updateValue(kitchen_hum_var, value=str(hum))

# set lum to round ((value of variable "Kitchen_Lum") as integer)
kitchen_lum_var = indigo.variables[ID_OF_Kitchen_Lum]
lum = int(round(kitchen_lum_var.value)) # not sure why the +0, doesn't seem to do anything
#set value of variable "Kitchen_Lum" to lum
indigo.variable.updateValue(kitchen_lum_var, value=str(lum))

# set temp to round ((((value of variable "Kitchen_Temp") as integer) - 32) * 5 / 9)
kitchen_temp_var = indigo.variables[ID_OF_Kitchen_Temp]
temp = (int(kitchen_hum_var.value) - 32) * 5 / 9
# set value of variable "Kitchen_Temp" to temp
indigo.variable.updateValue(kitchen_temp_var, value=str(temp))


I left the old AS code in there so you could see how each line converts. Also, not sure why you have the +0 on the first line, doesn't seem like that does anything so I left it out.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests