Variables - copying a single value into a new variable

Posted on
Sat Apr 14, 2018 9:17 am
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Variables - copying a single value into a new variable

Hi...

Thought I had this sorted out but, ran into a snag...

I am using ghostxml to provide a value to a variable (this works as below)

name value id
pump2 184,1295,15,0,0 414840212

I then want to split this variable into 4 other separate variables each containing a single number
ie
watts 184
rpm 1295
gpm 15
filter 0

I have created the 4 variables above

I am then using python via an action group to do the following....

Code: Select all
indigo.variable.updateValue(indigo.variables[142699920], indigo.variables[414840212].value.split(',')[3])


142699920 corresponds to my indigo variable for GPM


Initially, I thought this was working, however, I can NOT get the single variables to update from the parent variable.

At this time, I am just trying to force the update using the execute all on the python script associate with the individual variable in the action group. Once I can get the process correct, I will set up a schedule to execute the specific action group on a regular basis.

What am I missing???
Code: Select all
indigo.variable.updateValue(indigo.variables[142699920], indigo.variables[414840212].value.split(',')[3])


the above should take the 3rd value (15) from the parent pump 2 variable and copy it to my GPM variable should it not?

Thanx in advance for the help!

dave

Posted on
Sat Apr 14, 2018 9:40 am
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variables - copying a single value into a new variable

I'm unclear on the exact contents of the source variable - can you put just the raw variable value in quotes so we can understand it more clearly?

[EDIT] after reading the post a few more times, I think I've got it - if the raw contents of the source variable are "184,1295,15,0,0", then this rationalized script should work:

Code: Select all
raw_value = indigo.variables[414840212].value
watts, gpm, rpm, filter, the_rest = raw_value.split(",")
indigo.variable.updateValue(ID_OF_WATTS, value=watts)
indigo.variable.updateValue(142699920, value=gpm)
indigo.variable.updateValue(ID_OF_RPM, value=rpm)
indigo.variable.updateValue(ID_OF_FILTER, value=filter)


Your script may work (though it does some things that are unnecessary and will impact performance), but I think maybe your problem is that Python array's are 0-based - so the first element is 0, second element is 1, etc.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Apr 14, 2018 12:03 pm
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Re: Variables - copying a single value into a new variable

Thanx Jay!!!

Below is what I get from the xml file. currently the values are 0's, but correspond to the following,

Watts, RPM, GPM, Filter, pump status

I don't believe the identifiers are associated with the xml that's why I was trying to grab the comma separated values individualy from within this variable and insert them into separate variables that I can use. (indigo shows the pump2 variable = 0,0,0,0,0)

i.e. value 0, value 1, value 2, value 3 and I don't need the last one.

Code: Select all
<response>
<pumps>
<pump1>0,0,0,0,32768</pump1>
<pump2>0,0,0,0,0</pump2>
<pump3/>
<pump4/>
<pump5/>
<pump6/>
<pump7/>
<pump8/>
</pumps>
</response>

Posted on
Sat Apr 14, 2018 12:06 pm
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Re: Variables - copying a single value into a new variable

oops...one more question

so using your script, that would create NEW variables named

WATTS
RPM
FILTER

or I would use the actual indigo variable id's for the ones I already created as you did for gym

d

Posted on
Sat Apr 14, 2018 2:56 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Variables - copying a single value into a new variable

Swap in the variable IDs like Jay did... :-)


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 15, 2018 10:10 am
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Re: Variables - copying a single value into a new variable

ok, I created an action group to execute a python script using the following, based on your example.

Code: Select all
raw_value = indigo.variables[414840212]
watts, gpm, rpm, filter, status = raw_value.split(",")
indigo.variable.updateValue(1037421068, value=watts)
indigo.variable.updateValue(142699920, value=gpm)
indigo.variable.updateValue(461007693, value=rpm)
indigo.variable.updateValue(1980819764, value=filter)
indigo.variable.updateValue(698724379, value=status)


to test, I compile the code, then hit run.

It then stops on line 2 and I get the following error message:
embedded script: 'Variable' object has no attribute 'split'
Attachments
Screen Shot 2018-04-15 at 9.08.48 AM.png
Screen Shot 2018-04-15 at 9.08.48 AM.png (52.52 KiB) Viewed 3911 times

Posted on
Sun Apr 15, 2018 10:17 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Variables - copying a single value into a new variable

Add “.value” to the first line, so its:

raw_value = indigo.variables[414840212].value


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 15, 2018 10:23 am
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variables - copying a single value into a new variable

howartp wrote:
Add “.value” to the first line, so its:

raw_value = indigo.variables[414840212].value


Yep - I've updated the script above so that it's correct.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Apr 15, 2018 10:26 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Variables - copying a single value into a new variable

Jay, could you tweak the docs as well?

They’re not wrong, but could be clearer getting a string value - alongside the other int/bool/float examples.

http://wiki.indigodomo.com/doku.php?id= ... able_class

Peter


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 15, 2018 10:50 am
jay (support) offline
Site Admin
User avatar
Posts: 18201
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variables - copying a single value into a new variable

howartp wrote:
Jay, could you tweak the docs as well?

They’re not wrong, but could be clearer getting a string value - alongside the other int/bool/float examples.

http://wiki.indigodomo.com/doku.php?id= ... able_class

Peter


Done, though the sentence just above the table says it... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Apr 15, 2018 10:53 am
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Re: Variables - copying a single value into a new variable

Problem solved!!!

Thanx for the help guys...

Last question... I have another variable created via ghost xml called iChem. This one has 41 values.

I only want to use 3 or 4 values of these 41. Using the logic in the script created for pump2, would I NEED to create a line like this
Code: Select all
watts, gpm, rpm, filter, status=raw_value.split(",")

with 41 comma separated values to correspond to the raw variable?

or is there a way to just pull the ones at positions 3,12,and 20? That is what I was trying to do in my original version. Can I still use a position indicator (i.e. [3] or could I define and assign multiple positions [3,12,20] something like this...

Code: Select all
raw_value=indigo.variables[414840212].value
SI, Ph, ORP=raw_value.split(",")[3,12,20]

Posted on
Sun Apr 15, 2018 10:53 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Variables - copying a single value into a new variable

I know but I’m using an iTinyScreen* so just scrolled to the (other) indented code samples. :-)


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 15, 2018 11:01 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Variables - copying a single value into a new variable

values = raw_values.split(“,”)

values[2] is then the 3rd value (remember 0 is the 1st).


Sent from my iPhone using Tapatalk Pro

Posted on
Mon Apr 16, 2018 9:24 am
bsp9493 offline
Posts: 153
Joined: Nov 30, 2017
Location: Kelowna, BC

Re: Variables - copying a single value into a new variable

Awesome!!!

Thanx guys!!!

ended up using the following:)

Code: Select all
raw_value=indigo.variables[157312634].value
pH = raw_value.split(",")[11]
ORP = raw_value.split(",")[15]
SI = raw_value.split(",")[17]

indigo.variable.updateValue(40213453, value=pH)
indigo.variable.updateValue(1494718390, value=ORP)
indigo.variable.updateValue(412117496, value=SI)


Yay...
communication with my pool is complete (autelis device)!!!!

Now just need the weather to warm up:)

Thanx again for the help!

dave

Posted on
Mon Apr 16, 2018 9:31 am
FlyingDiver offline
User avatar
Posts: 7192
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variables - copying a single value into a new variable

If you care, this is a more efficient implementation:

Code: Select all
raw_value=indigo.variables[157312634].value
valueArray = raw_value.split(",")

indigo.variable.updateValue(40213453, value= valueArray[11])
indigo.variable.updateValue(1494718390, value= valueArray[15])
indigo.variable.updateValue(412117496, value= valueArray[17])

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

Who is online

Users browsing this forum: No registered users and 1 guest