Using the API to create a new variable

Posted on
Sun Mar 21, 2021 2:09 pm
dstrickler offline
User avatar
Posts: 330
Joined: Oct 08, 2010
Location: Boston, MA

Using the API to create a new variable

I've recently starting using WeatherCat to poll my weather station. Since WeatherCat has a CGI output call, it's pretty easy for it to make WeatherCat call out to a tiny PHP script that parses out the variables and updates Indigo variables using the Indigo RESTful API.

Except that I don't know the API call to create a variable. I only know how to read, and update an existing variable's value.

Can anyone point me to the docs on this, or give me an example?

Thanks,

Dave

Posted on
Sun Mar 21, 2021 2:52 pm
matt (support) offline
Site Admin
User avatar
Posts: 20568
Joined: Jan 27, 2003
Location: Texas

Re: Using the API to create a new variable

It isn't possible (currently) from the RESTful API to create a new variable. You can do it from an Indigo python script (which has to be executed by Indigo or the Indigo Plugin Host process) or by a plugin via:

Code: Select all
newVar = indigo.variable.create("someVarName", "default value")
indigo.variable.updateValue(newVar, "new value 1")
indigo.variable.updateValue(newVar, "new value 2")
indigo.variable.updateValue(newVar, "new value 3")

Image

Posted on
Sun Mar 21, 2021 3:57 pm
dstrickler offline
User avatar
Posts: 330
Joined: Oct 08, 2010
Location: Boston, MA

Re: Using the API to create a new variable

Bummer, but thanks for the Python code. With it, I think I have a work-around.

Dave

Posted on
Sun Mar 21, 2021 9:42 pm
kw123 offline
User avatar
Posts: 7695
Joined: May 12, 2013
Location: Dallas, TX

Re: Using the API to create a new variable

You can have a fixed variable eg httpupdate that you update with restful.
Then that triggers your python script “any change of httpupdate variable”.
That python script reads the httpupdate variable and creates the new variable with the contents of the httpupdate variable.
That should do it.
Karl


Sent from my iPhone using Tapatalk

Posted on
Mon Mar 22, 2021 10:16 am
jay (support) offline
Site Admin
User avatar
Posts: 16815
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Using the API to create a new variable

kw123 wrote:
You can have a fixed variable eg httpupdate that you update with restful.
Then that triggers your python script “any change of httpupdate variable”.
That python script reads the httpupdate variable and creates the new variable with the contents of the httpupdate variable.
That should do it.


Clever solution. You could even do all of your updates/creations through one variable update, just update it with a JSON payload - maybe something like this:

Code: Select all
[
   {"var_name_1": "var 1 value"},
   {"var_name_2": "var 2 value"}
]


Then a script that parses the json, creates the variable if necessary or update it if it already exists.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Mar 25, 2021 7:59 am
dstrickler offline
User avatar
Posts: 330
Joined: Oct 08, 2010
Location: Boston, MA

Re: Using the API to create a new variable

Thanks to both of you on this one - that's exactly what I had planned. A little hackey, but worked like a champ. The only thing that made me move on from this was the long list of updates in log window. Once a min (I'm reading in WeatherCat live weather data) was too much.

So I've moved onto a Python based solution, and will post when it's ready.

Dave

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest