Convert to Python

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

Convert to Python

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

Posted on
Thu Aug 04, 2022 3:01 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert to Python

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.

Posted on
Thu Aug 04, 2022 4:44 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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

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

[My Plugins] - [My Forums]

Posted on
Thu Aug 04, 2022 11:29 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Thanks a bunch!
Will be updating soon but still so many Applescripts to convert. :-(

Carl

Posted on
Thu Aug 04, 2022 11:59 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

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

Posted on
Thu Aug 04, 2022 12:49 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Convert to Python

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Aug 04, 2022 2:48 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Thanks Jay.

Getting syntax error. See attached image.

Carl
Attachments
CB2EE2D1-A94C-4C4D-9E9E-1B9A6C80E7CA.jpeg
CB2EE2D1-A94C-4C4D-9E9E-1B9A6C80E7CA.jpeg (208.25 KiB) Viewed 1828 times

Posted on
Thu Aug 04, 2022 2:57 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

Upon a quick review, the code looks right. What version of Indigo are you using?

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

[My Plugins] - [My Forums]

Posted on
Thu Aug 04, 2022 4:08 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Don’t laugh…7.2.0

Carl

Posted on
Thu Aug 04, 2022 4:18 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

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))
Last edited by DaveL17 on Thu Aug 04, 2022 6:10 pm, edited 1 time in total.

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

[My Plugins] - [My Forums]

Posted on
Thu Aug 04, 2022 4:27 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Different error.

Thanks,

Carl
Attachments
03AEA3BE-655B-455E-9C68-A3DDE0B4E27C.jpeg
03AEA3BE-655B-455E-9C68-A3DDE0B4E27C.jpeg (243.5 KiB) Viewed 1813 times

Posted on
Thu Aug 04, 2022 5:45 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Convert to Python

Code: Select all
indigo.variable.updateValue(…….)


Somehow the start of the line has been mistransposed.


Sent from my iPad using Tapatalk Pro

Posted on
Thu Aug 04, 2022 6:10 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Convert to Python

DAMMIT.

Changed my post above.

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

[My Plugins] - [My Forums]

Posted on
Thu Aug 04, 2022 6:28 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

Perfect. Many thanks!

Carl

Posted on
Sat Aug 06, 2022 9:21 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Convert to Python

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

Who is online

Users browsing this forum: No registered users and 1 guest