applescript to python - help pls

Posted on
Sat Jan 22, 2022 3:54 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: applescript to python - help pls

You aren't picking up the variable values and changing them to floating point (or integer) when using calculations in your scripts.

A variable looks like this to Indigo e.g. :
Code: Select all
description :
folderId : 0
globalProps : MetaProps : (dict)
id : 276413021
name : test_1
pluginProps : emptyDict : (dict)
readOnly : False
remoteDisplay : True
sharedProps : com.indigodomo.indigoserver : (dict)
value : 5.0
You need to append .value when you access the value of a variable.

Your code:
Code: Select all
poolFactortemp = indigo.variables[1681753265] * indigo.variables[1420782175]
should be something like:
Code: Select all
poolFactortemp = float(indigo.variables[1681753265].value) * float(indigo.variables[1420782175].value)
Hopefully this will get you moving in the right direction. :)

Posted on
Sat Jan 22, 2022 10:44 am
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

thanks jon! knew i was tripping over that.

but what am i doing wrong here?? grr. thx,,,

Code: Select all
indigo.variable.updateValue[677709449, poolFactortemp]

Posted on
Sat Jan 22, 2022 10:55 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: applescript to python - help pls

Code: Select all
indigo.variable.updateValue(677709449, poolFactortemp)
updateValue is a function so enclose with ( ) not [ ] :)

Posted on
Sat Jan 22, 2022 12:00 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

:roll:

yes. thx

Posted on
Sat Jan 22, 2022 6:35 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

can't crack this one. python baby talk... one day me talk good. :D

still pretty much at this stage.. viewtopic.php?p=207507#p207507

Posted on
Sat Jan 22, 2022 7:14 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: applescript to python - help pls

Can you post the most recent version, after you've made Jon's corrections?

Image

Posted on
Sat Jan 22, 2022 8:13 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

thanks guys, for any thoughts. really much appreciated, i know we're all busy.

there's this little guy, that.. yes, not quite happening yet, have nudged a few things but still not cracked;

Code: Select all
poolFactortemp = float(indigo.variables[1681753265].value) * float(indigo.variables[1420782175].value)

indigo.variable.updateValue(677709449, poolFactortemp)

#indigo.variables[1681753265] # "irrFactor"
#indigo.variables[677709449] # "irrFactor_Pool"
#indigo.variables[1420782175] # "irrFactor_Pool_multiplier"



but really it's this whole thing that's not firing yet, can't sort how to tweak per jon's guidance here exactly, tried several things.. but:

Code: Select all
### init vars and lists

#indigo.variable.updateValue(HumidDerate, 1)


tempAvgA = 0
tempAvgB = 0

tempTempA_List = [1322938653,691920204,260089793,1574995402,1850069036,1456307235,119394488,1354783145]
tempTempB_List = [433928592,1250118759,1624471510,444110768,758052807,1494625438,812101647,1354783145]

tempHumidA_List = [1172786570,331598169,1485751975,936737288,554095003,251870260,1568860020,162814321]
tempHumidB_List = [44964193,1077221341,1828836314,95069692,345600646,1518668036,923885739,162814321]


### temp averaging

for temp_id in tempTempA_List:
   tempvar = indigo.variables[temp_id]
   tempAvgA = (tempvar + tempAvgA)
## float(indigo.variables[1681753265].value) * float(indigo.variables[1420782175].value)

tempAvgA = (tempAvgA/8)

for temp_id in tempTempB_List:
   tempvar = indigo.variables[temp_id]
   tempAvgB = (tempvar + tempAvgB)
   
tempAvgB = (tempAvgB/8)

TempAvg = (tempAvgA+tempAvgB)/2


### humid averaging

for humid_id in tempHumidA_List:
   humidvar = indigo.variables[humid_id]
   humidAvgA = (humidvar + humidAvgA)
   
humidAvgA = (humidAvgA/8)

for humid_id in tempHumidB_List:
   humidvar = indigo.variables[humid_id]
   humidAvgB = (humidvar + humidAvgB)
   
humidAvgB = (humidAvgB/8)

HumidAvg = (humidAvgA+humidAvgB)/2
   
   
### set irrFactor

AvgAvgVar = (rnd(((TempAvg / (HumidAvg * HumidDerate)) * 100)) / 100)
indigo.variable.updateValue[1681753265, AvgAvgVar]
#irrFactor" to (round (((TempAvg / (HumidAvg * HumidDerate))) * 100)) / 100


### set max var and banners   

FactorVar = indigo.variables[1681753265] # "irrFactor"   
maxFactorVar = indigo.variables[958042151] # "irrFactorMax"
#indigo.variables[1571233000] # "irrFactorMax_banner"

if indigo.variables.value[1681753265] > indigo.variables.value[958042151]:
   indigo.variable.updateValue(1681753265, maxFactorVar)
   indigo.variable.updateValue(1571233000, "MAX")
   indigo.server.log("Irrigation Factor: " + "Held to maximum preset. Check variables.")
else:
   indigo.variable.updateValue(1571233000, "")
   
FactorVar = indigo.variables[1681753265] # "irrFactor"   

### set average vars   

#indigo.variables[888344166] # "WeatherTempAvg"
#indigo.variables[202189053] # "WeatherHumidAvg"
#indigo.variables[694982593] # "WeatherIndex"

indexAvgVar = ((((TempAvg / HumidAvg) * 0.5) * 100) / 100)

wthrTempAvgvar = indigo.variable.updateValue(888344166, rnd(TempAvg))
wthrHumidAvgvar = indigo.variable.updateValue(202189053, rnd(HumidAvg))
wthrIndexvar = indigo.variable.updateValue(694982593, rnd(indexAvgVar))


### log vars   

#indigo.server.log("Weather Index: " + str(wthrIndexvar))
#indigo.server.log("Irrigation Factor: " + str(FactorVar))

Posted on
Sun Jan 23, 2022 12:03 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: applescript to python - help pls

You still haven't appended .value everywhere you should have; for example, the line in the for loop which sets up tempvar:
Code: Select all
for temp_id in tempTempA_List:
   tempvar = indigo.variables[temp_id]
   tempAvgA = (tempvar + tempAvgA)
is missing .value! ;)

Whenever you want a value from a variable you MUST append .value otherwise you pick up the whole variable object which isn't what you want. :)

Posted on
Sun Jan 23, 2022 12:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: applescript to python - help pls

Those appear to be two different scripts, so I'm not sure which one to comment on. The first should be:

Code: Select all
poolFactortemp = float(indigo.variables[1681753265].value) * float(indigo.variables[1420782175].value)

# Indigo variable values are always strings - to above you had to cast them to floats
# to successfully do the multiplication. Now, you have to convert it back to a string
# to update the Indigo variable.
indigo.variable.updateValue(677709449, str(poolFactortemp))


Here's my cut as the second. My comments start with ### and there are several places where you will need to fix (marked with FIXME) because I don't know the correct values. I may not have gotten all of the issues because it's a lengthy script, but I think I found most of the problems.

Code: Select all
''' Notes on the changes

Aside from the syntactical errors I mention below, I did a little rearranging to
encapsulate each section so that it's easier to debug each part.

There are a couple of things you have to fix, marked by FIXME: below. I don't know the
right values so you'll have to fix them.
'''

######## temp averaging ########
tempAvgA = 0
tempAvgB = 0
tempTempA_List = [1322938653,691920204,260089793,1574995402,1850069036,1456307235,119394488,1354783145]
tempTempB_List = [433928592,1250118759,1624471510,444110768,758052807,1494625438,812101647,1354783145]

for temp_id in tempTempA_List:
   tempvar = float(indigo.variables[temp_id].value)  ### Use the value and convert to float
   tempAvgA = (tempvar + tempAvgA)

tempAvgA = (tempAvgA/8)

for temp_id in tempTempB_List:
   tempvar = float(indigo.variables[temp_id].value)  ### Use the value and convert to float
   tempAvgB = (tempvar + tempAvgB)
   
tempAvgB = (tempAvgB/8)
TempAvg = (tempAvgA+tempAvgB)/2

######## humid averaging ########
### Init the average variables - this wasn't done before and would cause an error
humidAvgA = 0
humidAvgB = 0
tempHumidA_List = [1172786570,331598169,1485751975,936737288,554095003,251870260,1568860020,162814321]
tempHumidB_List = [44964193,1077221341,1828836314,95069692,345600646,1518668036,923885739,162814321]

for humid_id in tempHumidA_List:
   humidvar = float(indigo.variables[humid_id].value)  ### Use the value and convert to float
   humidAvgA = (humidvar + humidAvgA)

humidAvgA = (humidAvgA/8)

for humid_id in tempHumidB_List:
   humidvar = float(indigo.variables[humid_id].value)  ### Use the value and convert to float
   humidAvgB = (humidvar + humidAvgB)

humidAvgB = (humidAvgB/8)
HumidAvg = (humidAvgA+humidAvgB)/2
   
######## set irrFactor ########
HumidDerate = ????  ### FIXME: This isn't defined, so I don't know what it is
### FIXME: I'm not sure you have your parenthesis right here since there's no need for the
###  outermost set. I don't know what your forumula is so you'll have to fix it. And, you
###  use round for rounding values, not rnd...
AvgAvgVar = (round(((TempAvg / (HumidAvg * HumidDerate)) * 100)) / 100)
### FIXME: I don't think this variable ID is correct since it appears to the the same ID
###  as the irrFactor variable used below.
indigo.variable.updateValue(1681753265, str(AvgAvgVar)) ### Fixed function call, converted value to string
#irrFactor" to (round (((TempAvg / (HumidAvg * HumidDerate))) * 100)) / 100


######## set max var and banners ########
### I can't tell if these numbers are integers or floats, but I suspect they are integers
### If not, just change int to float on the next two lines
FactorVar = int(indigo.variables[1681753265].value) # "irrFactor"   
maxFactorVar = int(indigo.variables[958042151].value) # "irrFactorMax"

if FactorVar > maxFactorVar:
   indigo.variable.updateValue(1681753265, maxFactorVar)
   indigo.variable.updateValue(1571233000, "MAX")
   indigo.server.log("Irrigation Factor: " + "Held to maximum preset. Check variables.")
else:
   indigo.variable.updateValue(1571233000, "")
   
### FIXME: this line doesn't appear to do anything - delete if not needed
FactorVar = indigo.variables[1681753265] # "irrFactor"   

######## set average vars ########
indexAvgVar = ((((TempAvg / HumidAvg) * 0.5) * 100) / 100)

indigo.variable.updateValue(888344166, rnd(TempAvg))     # "WeatherTempAvg"
indigo.variable.updateValue(202189053, rnd(HumidAvg))    # "WeatherHumidAvg"
indigo.variable.updateValue(694982593, rnd(indexAvgVar)) # "WeatherIndex"


######## log vars ########

#indigo.server.log("Weather Index: " + str(wthrIndexvar))
#indigo.server.log("Irrigation Factor: " + str(FactorVar))

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 23, 2022 12:53 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

jay and jon, thanks!


so, added missing parens on the first little one, thx


the second one now works - thanks!

i had to tweak several things, and append .value etc, as noted, phew. brilliant.

jay, re: one of your notes, i have the irrFactor var updating in two places because if it ends up being held to the max allowed value it needs to be re-updated.
and, the humid derate is a factor that can be hardcoded here to lessen the influence of humidity in the formula. it's usually set to 1.

think it's working correctly, we'll see in few weeks if everything is yellow or fried to a crisp :D

thanks guys.
really appreciate the help.

Posted on
Sun Jan 23, 2022 2:08 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: applescript to python - help pls

Well crud, I accidentally nuked your post. I had pressed "edit" to look at what was in your code blocks and ended up deleting it. The good news is although your question is lost, I still have my answer:

There isn't a way to have no type printed, but you can customize what type is used like this example that sets it to Irrigation:

Code: Select all
indigo.server.log("Weather Index: " + indigo.variables[694982593].value, type="Irrigation")
indigo.server.log("Irrigation Factor: " + indigo.variables[1681753265].value, type="Irrigation")

Image

Posted on
Sun Jan 23, 2022 3:14 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: applescript to python - help pls

lol - thanks matt! i think i had tried adding that before and it didn't work, but i think i had it in the wrong position. this works. thx

Who is online

Users browsing this forum: No registered users and 1 guest