Convert to Python

Posted on
Sat Aug 06, 2022 12:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Convert to Python

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")

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Aug 06, 2022 3:34 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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")

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Aug 07, 2022 12:16 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Thanks so much.
Very close now to updating Indigo for the first time in years.

Carl

Posted on
Sun Aug 07, 2022 12:53 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

Don't forget to convert the variable names to variable ID numbers (no quotes) to "future-proof" your scripts. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Aug 10, 2022 6:32 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Will do, thanks.

Carl

Posted on
Fri Aug 12, 2022 7:50 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

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

Posted on
Sat Aug 13, 2022 6:04 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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)))

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Aug 13, 2022 6:16 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert to Python

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

Posted on
Sat Aug 13, 2022 1:08 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

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

Thanks,

Carl

Posted on
Sat Aug 13, 2022 2:55 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Aug 13, 2022 2:55 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Aug 13, 2022 3:06 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert to Python

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.

Posted on
Sat Aug 13, 2022 3:24 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

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

Posted on
Sat Aug 13, 2022 4:02 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Convert to Python

Change the last line to:

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

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

Posted on
Sat Aug 13, 2022 4:17 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Get this error.

Carl
Attachments
7CA05B21-D12B-42D5-9E0D-A9887F5AEC25.jpeg
7CA05B21-D12B-42D5-9E0D-A9887F5AEC25.jpeg (146.14 KiB) Viewed 1495 times

Who is online

Users browsing this forum: No registered users and 1 guest