Applescript Conversion to Python

Posted on
Tue Apr 27, 2021 2:26 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Applescript Conversion to Python

Hey,

Lil help converting this:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)

to python?

Thanks,

Carl

Posted on
Tue Apr 27, 2021 9:07 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Applescript Conversion to Python

ckeyes888 wrote:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)


I think....

Code: Select all
wsTempOut = indigo.variables[123456]

# Getting the integer value
intValue = wsTempOut.getValue(int)   # 0 if it can't be converted
intValue = wsTempOut.getValue(int, default=10) # 10 if it can't be converted

indigo.variable.updateValue(123456, value=intValue)


However, I think a variable is always a string. You can convert it to a integer to use somewhere else in a phthon code, but I don't think you can save it back as an indigo variable that way.... but not sure.

Also... take a look at this... It goes into way more detail... https://wiki.indigodomo.com/doku.php?id=indigo_5_documentation:variable_class

Bill
My Plugin: My People

Posted on
Wed Apr 28, 2021 7:15 am
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Applescript Conversion to Python

That script returns: "Python argument types in"

I'll have a look at your link.

Thanks,

Carl

Posted on
Wed Apr 28, 2021 10:26 am
jay (support) offline
Site Admin
User avatar
Posts: 16797
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Applescript Conversion to Python

whmoorejr wrote:
However, I think a variable is always a string. You can convert it to a integer to use somewhere else in a phthon code, but I don't think you can save it back as an indigo variable that way.... but not sure.


You need to cast it to a string when setting the value:

Code: Select all
indigo.variable.updateValue(123456, value=str(intValue))

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 28, 2021 10:27 am
jay (support) offline
Site Admin
User avatar
Posts: 16797
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Applescript Conversion to Python

ckeyes888 wrote:
Hey,

Lil help converting this:
Code: Select all
set value of variable "wsTemp_Out" to (value of variable "wsTemp_Out" as integer)

to python?


What are you trying to do with this script? It doesn't appear to do anything because variable values are always strings. So, basically, you're just setting it to exactly what it was (unless it wasn't something that can be converted to an integer in which case the script will fail).

[EDIT] - ok, so maybe if something else sets it and it's a float value, then this AppleScript would convert it to an integer. If that's the case, then the posted script (with the string cast) would work.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jun 07, 2021 1:19 pm
rszmetro offline
Posts: 104
Joined: Sep 10, 2009
Location: East Hills, NY

Re: Applescript Conversion to Python

Hi,

I'm upgrading from 7.1 to the latest version and need to convert Applescripts to Python scripts. I've never done this before and an example would help me understand. Hers is an AppleScript I need to convert.
----------
-- Update Upstairs Temperature

tell application "IndigoServer"
set myThermoDev to device "Thermostat - A/C"
set tempList to temperatures of myThermoDev
set TempUpStairs to first item of tempList as real
set value of variable "tempUpstairs" to first item of tempList as real
end tell
----------

Thanks!
Rob Z

Rob Z

Posted on
Mon Jun 07, 2021 2:14 pm
FlyingDiver online
User avatar
Posts: 5328
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Applescript Conversion to Python

rszmetro wrote:
Hi,

I'm upgrading from 7.1 to the latest version and need to convert Applescripts to Python scripts. I've never done this before and an example would help me understand. Hers is an AppleScript I need to convert.
----------
-- Update Upstairs Temperature

tell application "IndigoServer"
set myThermoDev to device "Thermostat - A/C"
set tempList to temperatures of myThermoDev
set TempUpStairs to first item of tempList as real
set value of variable "tempUpstairs" to first item of tempList as real
end tell
----------

Thanks!
Rob Z


Where are you running this script? Inside Indigo? If so, is there some reason you can't use the built-in Indigo action to copy the temperature from the device to a variable?

And what's the point of set TempUpStairs to first item of tempList as real? You never use the variable you just set.

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

Posted on
Mon Jun 14, 2021 4:11 pm
rszmetro offline
Posts: 104
Joined: Sep 10, 2009
Location: East Hills, NY

Re: Applescript Conversion to Python

I have two thermostats. The downstairs is connected to and controls the heating system. The upstairs master bedroom thermostat is connected to and controls the air conditioning system. Both are Insteon thermostats. I set up Applescripts that determine which thermostat to read and set. I have a variable called TempSet that holds the actual temperature I want to maintain. And, I have a Balancing script that determines which thermostat is read for the actual temperature. When using air-conditioning during the day, I read the temp off the downstairs thermostat and set the upstairs ac thermostat to maintain the temp downstairs according to TempSet. During the night, it reads the temperature off the upstairs thermostat and sets it to maintain the TempSet upstairs.
Attachments
Screen Shot 2021-06-14 at 5.51.29 PM.png
Screen Shot 2021-06-14 at 5.51.29 PM.png (48.58 KiB) Viewed 181 times
Screen Shot 2021-06-14 at 6.07.31 PM.png
Screen Shot 2021-06-14 at 6.07.31 PM.png (21.92 KiB) Viewed 181 times

Rob Z

Posted on
Mon Jun 14, 2021 4:14 pm
rszmetro offline
Posts: 104
Joined: Sep 10, 2009
Location: East Hills, NY

Re: Applescript Conversion to Python

The scripts are run in a scheduled Action Group


Code: Select all
-- Update Upstairs Temperature

tell application "IndigoServer"
   set myThermoDev to device "Thermostat - A/C"
   set tempList to temperatures of myThermoDev
   set TempUpStairs to first item of tempList as real
   set value of variable "tempUpstairs" to first item of tempList as real
end tell


-- Update Downstairs Temperature

tell application "IndigoServer"
   set myThermoDev to device "Thermostat - HEAT"
   set tempList to temperatures of myThermoDev
   set TempDownStairs to first item of tempList as real
   set value of variable "tempDownstairs" to first item of tempList as real
end tell


-- Calculate tempSetDif

tell application "IndigoServer"
   if value of variable "runClimateControl" = "Cool" then
      set value of variable "tempSetDif" to ((value of variable "tempSet") - (value of variable "tempDownstairs"))
   else if value of variable "runClimateControl" = "Heat" then
      set value of variable "tempSetDif" to ((value of variable "tempSet") - (value of variable "tempUpstairs"))
   end if
end tell



-- Calculate tempSetBal NEW 3/11/13

tell application "IndigoServer"
   if value of variable "runClimateControl" = "Cool" then
      if value of variable "tempDownstairs" is less than value of variable "tempSet" then
         set value of variable "tempSetBal" to ((value of variable "tempUpstairs") + (5))
      else if value of variable "tempDownstairs" is greater than value of variable "tempSet" then
         set value of variable "tempSetBal" to ((value of variable "tempSet") - (5))
      else if value of variable "tempDownstairs" is equal to value of variable "tempSet" then
         set value of variable "tempSetBal" to value of variable "tempSet"
      end if
   else if value of variable "runClimateControl" = "Heat" then
      if value of variable "tempUpstairs" is less than value of variable "tempSet" then
         set value of variable "tempSetBal" to ((value of variable "tempUpstairs") + 5)
      else if value of variable "tempUpstairs" is greater than value of variable "tempSet" then
         set value of variable "tempSetBal" to ((value of variable "tempSet") + 1)
      else if value of variable "tempUpstairs" is equal to value of variable "tempSet" then
         set value of variable "tempSetBal" to value of variable "tempSet"
      end if
   end if
end tell

Rob Z

Posted on
Mon Jun 14, 2021 9:35 pm
kw123 offline
User avatar
Posts: 7695
Joined: May 12, 2013
Location: Dallas, TX

Re: Applescript Conversion to Python

try this. it compiles, but I have not executed it. put it into action/execute script/embedded python
Code: Select all
# Update Upstairs Temperature
myThermoDev = indigo.devices["Thermostat - A/C"]
temp = float(dev.states["Temperature"])
indigo.variable.updateValue("tempUpstairs", str(temp))
## or
indigo.variable.updateValue("tempUpstairs", str(indigo.devices["Thermostat - A/C"].states["Temperature"]))


# Update Downstairs Temperature
myThermoDev = indigo.devices["Thermostat - HEAT"]
temp = float(dev.states["Temperature"])
indigo.variable.updateValue("tempDownstairs", str(temp))

#  Calculate tempSetDif
if indigo.variable["runClimateControl"].value == "Cool":
    indigo.variable.updateValue( "tempSetDif", str( float(indigo.variable["tempSet"].value) - float(indigo.variable["tempDownstairs"].value)) )
elif indigo.variable["runClimateControl"].value == "Heat":
    indigo.variable.updateValue( "tempSetDif", str( float(indigo.variable["tempSet"].value) - float(indigo.variable["tempUpstairs"].value)) )

#   Calculate tempSetBal NEW 3/11/13
if indigo.variable["runClimateControl"].value == "Cool":
    if float(indigo.variable["tempDownstairs"].value) < float(indigo.variable["tempSet"].value):
        indigo.variable.updateValue( "tempSetBal", str( float(indigo.variable["tempUpstairs"].value) + 5 ) )
    elif float(indigo.variable["tempDownstairs"].value) > float(indigo.variable["tempSet"].value):
        indigo.variable.updateValue( "tempSetBal", str( float(indigo.variable["tempSet"].value) - 5 ) )
    else:
        indigo.variable.updateValue( "tempSetBal", indigo.variable["tempSet"].value )

elif indigo.variable["runClimateControl"].value == "Heat":
    if float(indigo.variable["tempUpstairs"].value) < float(indigo.variable["tempSet"].value):
        indigo.variable.updateValue( "tempSetBal", str( float(indigo.variable["tempUpstairs"].value) + 5 ) )
    elif float(indigo.variable["tempUpstairs"].value) > float(indigo.variable["tempSet"].value):
        indigo.variable.updateValue( "tempSetBal", str( float(indigo.variable["tempSet"].value) +1 ) )
    else:
        indigo.variable.updateValue( "tempSetBal", indigo.variable["tempSet"].value )

you could replace "name of device" with devNumber w/o quotes
Karl

Posted on
Tue Jun 15, 2021 10:15 am
rszmetro offline
Posts: 104
Joined: Sep 10, 2009
Location: East Hills, NY

Re: Applescript Conversion to Python

Thanks! I think the right side of the scripts are cut off?

Rob

Rob Z

Posted on
Tue Jun 15, 2021 10:20 am
FlyingDiver online
User avatar
Posts: 5328
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Applescript Conversion to Python

rszmetro wrote:
Thanks! I think the right side of the scripts are cut off?

Rob


There's a horizontal scroll bar below the code block. Or just use the Select All button to copy and paste.

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

Posted on
Tue Jun 15, 2021 2:55 pm
kw123 offline
User avatar
Posts: 7695
Joined: May 12, 2013
Location: Dallas, TX

Re: Applescript Conversion to Python

And please note. The the first section is converted into 2 options.
One several lines and the second a one liner.
Only use one of the options.. just delete one of them

Karl.


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron