Page 1 of 3

Convert to Python

PostPosted: Wed Aug 03, 2022 7:32 pm
by ckeyes888
Hey,

Having trouble converting this one to python.
Appreciate any help!
Code: Select all
tell application "IndigoServer"
   set the value of variable "TimerSpklrDurationMin" to (value of variable "TimerSpklrDuration") & " " & "min" & " " & "remain"
end tell


Thanks,

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 3:01 am
by howartp
Have you looked at the Adapter/Device Conversion plugins for this?

There’s a new py3 version that @DaveL17 has written but I don’t think it’s hit the plugin store yet.

It will constantly maintain itself with exactly the wording you’re trying to set in that variable, that I guess you then display on a control page.

No need for a script to tell Indigo to refresh the variable.

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 4:44 am
by DaveL17
There is an "unofficial" fork of the Adapters plugin updated for Python 3 in my GitHub repos. It's a beta release, but seems to be running smoothly. I consider it unofficial because the plugin will be added to the Indigo open source plugin list (as it's been abandoned by its original developer.)

For your original question, here's the Python version of your code (it's better to use ID numbers instead of names):

Code: Select all
# with IDs
var_value = indigo.variables[1928699259].value  # ID of `TimerSpklrDuration`
indigo.variable.updateValue(314742858, var_value + " min remain")  # ID of `TimerSpklrDurationMin`

# with names
var_value = indigo.variables["TimerSpklrDuration"].value
indigo.variable.updateValue("TimerSpklrDurationMin", var_value + " min remain")

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 11:29 am
by ckeyes888
Thanks a bunch!
Will be updating soon but still so many Applescripts to convert. :-(

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 11:59 am
by ckeyes888
Maybe one more?
Code: Select all
tell application "IndigoServer"
   set the value of variable "sprinklerLastRun" to (value of variable "DayShort") & " " & (value of variable "MonthShort") & "," & (value of variable "DateExt")
end tell

I've gotten this far:
Code: Select all
var_value = indigo.variables[1109021660].value  # ID of `sprinklerLastRun `
var_value = indigo.variables[1842520251].value  # ID of `DayShort `
var_value = indigo.variables[1269656511].value  # ID of `MonthShort `
var_value = indigo.variables[1102866719].value  # ID of `DayExt `

indigo.variable.updateValue(1109021660, var_value +


Thanks,

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 12:49 pm
by jay (support)
Code: Select all
last_run = indigo.variables[1109021660].value  # ID of `sprinklerLastRun `
day_short = indigo.variables[1842520251].value  # ID of `DayShort `
month_short = indigo.variables[1269656511].value  # ID of `MonthShort `
day_ext  = indigo.variables[1102866719].value  # ID of `DayExt `

indigo.variable.updateValue(1109021660, f"{day_short} {month_short}, {day_ext}")


Though, you use DateExt in your AppleScript but DayExt in your python script's description of the variable - I assumed the comment in the python script is right but if not you can change it from day_ext to date_ext in both places.

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 2:48 pm
by ckeyes888
Thanks Jay.

Getting syntax error. See attached image.

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 2:57 pm
by DaveL17
Upon a quick review, the code looks right. What version of Indigo are you using?

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 4:08 pm
by ckeyes888
Don’t laugh…7.2.0

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 4:18 pm
by DaveL17
No judgment here, but that explains the syntax error. This code should fix it. Replace the last line with this:

Code: Select all
indigo.variable.updateValue(1109021660, u"{0} {1}, {2}".format(day_short, month_short, date_ext))

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 4:27 pm
by ckeyes888
Different error.

Thanks,

Carl

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 5:45 pm
by howartp
Code: Select all
indigo.variable.updateValue(…….)


Somehow the start of the line has been mistransposed.


Sent from my iPad using Tapatalk Pro

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 6:10 pm
by DaveL17
DAMMIT.

Changed my post above.

Re: Convert to Python

PostPosted: Thu Aug 04, 2022 6:28 pm
by ckeyes888
Perfect. Many thanks!

Carl

Re: Convert to Python

PostPosted: Sat Aug 06, 2022 9:21 am
by ckeyes888
Doh, I found one more I can't get converted.
Code: Select all
tell application "IndigoServer"
   if value of variable "TimerSprinklerStart" as integer is greater than 2000 then
      if value of variable "DayLong" is "Sunday" then
         set value of variable "sprinklerNextRun" to "Tuesday"
      else if value of variable "DayLong" is "Monday" then
         set value of variable "sprinklerNextRun" to "Wednesday"


It's a much longer script but if can finish it if I get this section.

Thanks,

Carl