Need to parse numbers from a variable

Posted on
Tue Oct 15, 2019 4:37 pm
billorav offline
Posts: 24
Joined: Jun 24, 2015

Need to parse numbers from a variable

Sorry my knowledge and time with python programing is very limited. In order to switch to 7.4, I need to convert an embedded key AppleScript set of commands. I have an old (still operational HA controller) that has temp sensors and other input/output devices connected that when anything changes it sends a number string to Indigo through an RS-232 connection and Cynical Network grabbing the number string. In AppleScript I simply parse either 1 or 2 numbers and put those in a new variable.

My V string usually looks like this: Variable "Vnetworkstring1" =!70736965706861

In the first AppleScript group below it takes the 70 out and puts it in the the new variable (so that can be used in Indigo Control pages)..
The second group takes characters 4 & 5, etc, etc.

Code: Select all
set Bedrmtemp2 to value of variable "Vnetworkstring1"
set myTempbed to (characters 2 thru 3 of Bedrmtemp2) as string
set value of variable "V1tempbed2" to myTempbed

set Livetemp2 to value of variable "Vnetworkstring1"
set myTempLiv to (characters 4 thru 5 of Livetemp2) as string
set value of variable "V1tempLive2" to myTempLiv

set basementtemp to value of variable "Vnetworkstring1"
set myTempbasement to (characters 6 thru 7 of basementtemp) as string
set value of variable "V1tempdown2" to myTempbasement

Any help on writing a command in python to accomplish this will get my triggers back operational in 7.4, and will be much appreciated.

Thank you.

Posted on
Tue Oct 15, 2019 6:50 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Need to parse numbers from a variable

billorav wrote:
Sorry my knowledge and time with python programing is very limited. In order to switch to 7.4, I need to convert an embedded key AppleScript set of commands. I have an old (still operational HA controller) that has temp sensors and other input/output devices connected that when anything changes it sends a number string to Indigo through an RS-232 connection and Cynical Network grabbing the number string. In AppleScript I simply parse either 1 or 2 numbers and put those in a new variable.

My V string usually looks like this: Variable "Vnetworkstring1" =!70736965706861

In the first AppleScript group below it takes the 70 out and puts it in the the new variable (so that can be used in Indigo Control pages)..
The second group takes characters 4 & 5, etc, etc.

set Bedrmtemp2 to value of variable "Vnetworkstring1"
set myTempbed to (characters 2 thru 3 of Bedrmtemp2) as string
set value of variable "V1tempbed2" to myTempbed

set Livetemp2 to value of variable "Vnetworkstring1"
set myTempLiv to (characters 4 thru 5 of Livetemp2) as string
set value of variable "V1tempLive2" to myTempLiv

set basementtemp to value of variable "Vnetworkstring1"
set myTempbasement to (characters 6 thru 7 of basementtemp) as string
set value of variable "V1tempdown2" to myTempbasement

Any help on writing a command in python to accomplish this will get my triggers back operational in 7.4, and will be much appreciated.

Thank you.


This is very easy to do in Python. I assume that the equals sign is not part of the actual string but that the bang (!) is.
Code: Select all
# set Bedrmtemp2 to value of variable "Vnetworkstring1"
# set myTempbed to (characters 2 thru 3 of Bedrmtemp2) as string
# set value of variable "V1tempbed2" to myTempbed

# Becomes:

Bedrmtemp2 = indigo.variables["Vnetworkstring1"].value
myTempbed = Bedrmtemp2[1:3]
indigo.variable.updateValue("V1tempbed2", myTempbed)

# Which can be simplified a bit to:
Bedrmtemp2 = indigo.variables["Vnetworkstring1"].value
indigo.variable.updateValue("V1tempbed2", Bedrmtemp2[1:3])

Obviously untested, but should be pretty close. Note that the bit [1:3] is called Python indexing. Indexing in this instance is saying to grab character 1 to (but not including) 3 (Python considers the first character to be character zero).

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

[My Plugins] - [My Forums]

Posted on
Wed Oct 16, 2019 2:09 pm
billorav offline
Posts: 24
Joined: Jun 24, 2015

Re: Need to parse numbers from a variable

I figured it was easy to replicate in Python. Thank you very much. And testing works great with the shorter version. I'm glad you explained the leading character in python indexing being a 0 since I was somewhat confused with 4:6 would return 2 characters.

Thanks again, and on to 7.4! Also I'll try to learn the language in my spare time.

Posted on
Wed Oct 16, 2019 3:29 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Need to parse numbers from a variable

Glad to hear that worked for you. Good luck with your transition!


Sent from my iPhone using Tapatalk Pro

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 3 guests