Variable Use

Posted on
Sat Aug 20, 2016 6:16 am
cramer offline
Posts: 33
Joined: Feb 03, 2015

Variable Use

I have defined a Virtual on/off device which assigns the onOffState to a variable - 'homeActive'. A Python script file is actioned in an action group assigned to the device

Is the variable automatically created as a result of this assignment?

How should the variable be referenced within the script file?

A newbie Python question, how is the entry point into the Python script declared at which the script will start when called by the server?

Thanks,

Posted on
Sat Aug 20, 2016 6:25 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variable Use

You can create an Indigo variable (which is not the same as a Python variable) in a script, but it's not done by default. Do it manually before you run the script.

To change the value of the Indigo variable, you would do something like:

Code: Select all
indigo.variable.updateValue(1766478875, str(datetime.datetime.now()))


Python scripts called from Indigo start at the beginning of the script. There's no defined entry point.

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

Posted on
Sat Aug 20, 2016 6:31 am
cramer offline
Posts: 33
Joined: Feb 03, 2015

Re: Variable Use

How / where do I create the Indigo variable so that it exists before the action group associated with the on/off device that references the variable is actioned?

Posted on
Sat Aug 20, 2016 6:33 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variable Use

cramer wrote:
How / where do I create the Indigo variable so that it exists before the action group associated with the on/off device that references the variable is actioned?


In the Variable List window. cmd-9 in Indigo.

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

Posted on
Sat Aug 20, 2016 6:38 am
cramer offline
Posts: 33
Joined: Feb 03, 2015

Re: Variable Use

Got it. Thanks.

Posted on
Sat Aug 20, 2016 11:32 am
DaveL17 offline
User avatar
Posts: 6757
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Variable Use

I prefer to create most variables and variable folders programmatically so that in the outside chance that one gets deleted, my scripts will still work. Here's a snippet which shows the syntax:

Code: Select all
# Create folders or variables if they have been somehow deleted.
if 'folder_name' not in indigo.variables.folders:
    indigo.variables.folder.create('folder_name')

if 'var_name' not in indigo.variables:
    indigo.variable.create('var_name', 'var_value', folder=folder_name)

Replace folder_name, var_name, and var_value with the appropriate values. Note that var_value must be a string because Indigo stores all variable values as strings.

http://wiki.indigodomo.com/doku.php?id=indigo_6_documentation:plugin_scripting_tutorial#variable_examples

Dave

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

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests