Page 2 of 3

Re: Convert to Python

PostPosted: Sat Aug 06, 2022 12:48 pm
by jay (support)
Untested, but close:

Code: Select all
# Get the variable values
timer_sprinkler_start = indigo.variables[TimerSprinklerStart_IDHERE].getValue(int)
day_long = indigo.variables[DayLong_IDHERE].value
# Perform the logic
if timer_sprinkler_start > 2000:
    if day_long == "Sunday":
        indigo.variable.updateValue(sprinklerNextRun_IDHERE, "Tuesday")
    elif day_long == "Monday"
        indigo.variable.updateValue(sprinklerNextRun_IDHERE, "Wednesday")

Re: Convert to Python

PostPosted: Sat Aug 06, 2022 3:34 pm
by DaveL17
Something like this:

Code: Select all
if int(indigo.variable.value("TimerSprinklerStart")) > 2000:
    if indigo.variable.value("DayLong") == "Sunday":
        indigo.variable.updateValue("sprinklerNextRun", "Tuesday")
    elif indigo.variable.value("DayLong") == "Monday":
        indigo.variable.updateValue("sprinklerNextRun", "Wednesday")

Re: Convert to Python

PostPosted: Sun Aug 07, 2022 12:16 pm
by ckeyes888
Thanks so much.
Very close now to updating Indigo for the first time in years.

Carl

Re: Convert to Python

PostPosted: Sun Aug 07, 2022 12:53 pm
by DaveL17
Don't forget to convert the variable names to variable ID numbers (no quotes) to "future-proof" your scripts. :D

Re: Convert to Python

PostPosted: Wed Aug 10, 2022 6:32 pm
by ckeyes888
Will do, thanks.

Carl

Re: Convert to Python

PostPosted: Fri Aug 12, 2022 7:50 pm
by ckeyes888
Ugh, keep finding more.

Help converting?
Code: Select all
tell application "IndigoServer"
   set rainDay to the value of variable "wsDaily_Rain" as real
   set rainSeason to the value of variable "RainSeason" as real
   
   set rainSeason to rainSeason + rainDay
   set the value of variable "RainSeason" to rainSeason
   
   set X to value of variable "RainSeason"
   set X to 100 * X as integer
   set X to X / 100
   set value of variable "RainSeason" to X as string
   
end tell


Thanks,

Carl

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 6:04 am
by DaveL17
I don't know AppleScript, but it looks like the stuff at the bottom (the last 4 lines) is unnecessary). Someone should check me on this, but I think this will do it:

Code: Select all
rainDay = float(indigo.variables['wsDaily_Rain'].value)
rainSeason = float(indigo.variables['RainSeason'].value)

rainSeason += rainDay
indigo.variable.updateValue('RainSeason', str(int(rainSeason)))

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 6:16 am
by howartp
I’m thought that initially, but it’s actually a clever way of rounding to 2 D.P.

I’ve done the same myself before now.


Sent from my iPhone using Tapatalk Pro

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 1:08 pm
by ckeyes888
The script just rounds off the RainSeason variable to a whole number…doesn’t add the rainDay to it.

Thanks,

Carl

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 2:55 pm
by DaveL17
I'm confused. Isn't that what this line does?
Code: Select all
set rainSeason to rainSeason + rainDay

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 2:55 pm
by DaveL17
I'm confused. Isn't that what this line does?
Code: Select all
set rainSeason to rainSeason + rainDay

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 3:06 pm
by howartp
howartp wrote:
I’m thought that initially, but it’s actually a clever way of rounding to 2 D.P.

I’ve done the same myself before now.

It may be that once AppleScript has X as an integer, it retains it as integer, so dividing by 100 would do as Carl says - ie the last four rows round off the value of RainSeason to a whole number.

Either way, the earlier setting of the variable is superfluous as it's overwritten by either a 2DP or whole number.

ckeyes888 wrote:
The script just rounds off the RainSeason variable to a whole number…doesn’t add the rainDay to it.

Thanks,

Carl

It DOES add rainDay to it.

The first section adds rainDay to rainSeason then stores it back into RainSeason.
The second section re-grabs RainSeason (which has now been incremented) then rounds it off to either 2DP or integer.

DaveL17 wrote:
I'm confused. Isn't that what this line does?
Code: Select all
set rainSeason to rainSeason + rainDay

Yes.

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 3:24 pm
by ckeyes888
Sorry guys. I’m confused.

When running python script above on a rainDay variable of 0.09 and a rainSeason variable of 7.09 the return on the rainSeason is just 7, not 7.18.

Thanks,

Carl

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 4:02 pm
by FlyingDiver
Change the last line to:

Code: Select all
indigo.variable.updateValue('RainSeason', f"{rainSeason:.2f}")

Re: Convert to Python

PostPosted: Sat Aug 13, 2022 4:17 pm
by ckeyes888
Get this error.

Carl