[SOLVED]Make A Python List From An Indigo Variable

Posted on
Sun Apr 13, 2014 9:50 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

[SOLVED]Make A Python List From An Indigo Variable

I'm trying to get this code to run by feeding data from Indigo that I would like to turn from a list. Basically, I have downloaded polygon data from the NOAA Alerts site and I want to see if my lat / lon is inside the alert area. Data is returned looking like this:
Code: Select all
30.72,-97.27 30.86,-97.6 30.98,-97.56 31.01,-97.46 30.98,-97.07 30.89,-96.9 30.66,-96.76 30.46,-97.16 30.72,-97.27
and I have parsed it, so that the variable (noaaAlertCapPolygon) looks like this:
Code: Select all
[(35.44,-90.28),(35.65,-90.29),(35.82,-89.89),(35.4,-90),(35.31,-90.4),(35.44,-90.28)]


The code fails with "Script Error embedded script: need more than 1 value to unpack" If I replace the line: polygon = noaaAlertCapPolygon with the formatted list above, it works. I assume there's a way to parse the variable back into Python. What am I missing?

Code: Select all
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This function
# returns True or False.  The algorithm is called
# the "Ray Casting Method".

def point_in_poly(x,y,poly):

    n = len(poly)
    inside = False

    p1x,p1y = poly[0]
    for i in range(n+1):
        p2x,p2y = poly[i % n]
        if y > min(p1y,p2y):
            if y <= max(p1y,p2y):
                if x <= max(p1x,p2x):
                    if p1y != p2y:
                        xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
                    if p1x == p2x or x <= xints:
                        inside = not inside
        p1x,p1y = p2x,p2y

    return inside

## Test

noaaAlertCapPolygon = list(indigo.variables[1823083030].value) # "noaaAlert1CapPolygon"
lat = float(indigo.variables[201899193].value) # "homeLatitude"
lon = float(indigo.variables[1966208654].value) # "homeLongitude"

polygon = noaaAlertCapPolygon

point_x = lat
point_y = lon

## Call the function with the points and the polygon

polygonInside = point_in_poly(point_x,point_y, polygon)

# indigo.variable.updateValue(104702043, value=str(polygonInside)) # "noaaAlertPolygonInside1"

indigo.server.log("Polygon Inside: " + str(polygonInside))

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Mon Apr 14, 2014 12:08 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Make A Python List From An Indigo Variable

I believe when you do list(indigo.variables[1823083030].value) from indigo you get a string and not a list

the list function produces: ['[', '(','3','5','.','4','4', ....
you want [(34.5,-90.28)...

first drop the [] in the variable
second make it look like e.g. (use ; to separate the tuples)
35.44,-90.28;35.65,-90.29;35.82,-89.89;35.4,-90;35.31,-90.4;35.44,-90.28

then
yy = indigo.variables[1823083030].value.split(";")
gets you to
['35.44,-90.28', '35.65,-90.29', '35.82,-89.89', '35.4,-90', '35.31,-90.4', '35.44,-90.28']
then
xx=[]
for ii in range( len( yy)):
xx.append(yy[ii].split(","))

gets you
xx= [['35.44', '-90.28'], ['35.44', '-90.28'], ['35.65', '-90.29'], ['35.82', '-89.89'], ['35.4', '-90'], ['35.31', '-90.4'], ['35.44', '-90.28']]
then you have to do a map str to int

seehttp://stackoverflow.com/questions/10145347/convert-string-to-integer-using-map
how to do that.
or you do a float(xx[0][0]) to get 35.44 and float(xx[0][1]) to get -90.28
there might be a more elegant way, but this is how I would do it.

Karl

Posted on
Mon Apr 14, 2014 7:36 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Make A Python List From An Indigo Variable

Thanks Karl,

I wound up with a strange problem -- maybe unicode related. I pushed all of the variables to the log so we could see:
Code: Select all
  Script                          Raw From Indigo:                 32.05,-90.72;32.23,-90.73;32.3,-90.7;32.34,-90.7;32.34,-90.63;32.5,-90.58;32.51,-90.53;32.57,-90.44;32.49,-90.44;32.49,-90.25;32.4,-90.24;32.4,-89.99;32.42,-89.75;32.36,-89.73;32.04,-89.73;32.05,-90.72

  Script                          Imported using value.split (yy): [u'32.05,-90.72', u'32.23,-90.73', u'32.3,-90.7', u'32.34,-90.7', u'32.34,-90.63', u'32.5,-90.58', u'32.51,-90.53', u'32.57,-90.44', u'32.49,-90.44', u'32.49,-90.25', u'32.4,-90.24', u'32.4,-89.99', u'32.42,-89.75', u'32.36,-89.73', u'32.04,-89.73', u'32.05,-90.72']

  Script                          Then split                 (xx): [[u'32.05', u'-90.72'], [u'32.23', u'-90.73'], [u'32.3', u'-90.7'], [u'32.34', u'-90.7'], [u'32.34', u'-90.63'], [u'32.5', u'-90.58'], [u'32.51', u'-90.53'], [u'32.57', u'-90.44'], [u'32.49', u'-90.44'], [u'32.49', u'-90.25'], [u'32.4', u'-90.24'], [u'32.4', u'-89.99'], [u'32.42', u'-89.75'], [u'32.36', u'-89.73'], [u'32.04', u'-89.73'], [u'32.05', u'-90.72']]


When I try to run the map function, I get this error: embedded script: int() argument must be a string or a number, not 'list'

Here's the current code:
Code: Select all
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This function
# returns True or False.  The algorithm is called
# the "Ray Casting Method".

def point_in_poly(x,y,poly):

    n = len(poly)
    inside = False

    p1x,p1y = poly[0]
    for i in range(n+1):
        p2x,p2y = poly[i % n]
        if y > min(p1y,p2y):
            if y <= max(p1y,p2y):
                if x <= max(p1x,p2x):
                    if p1y != p2y:
                        xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
                    if p1x == p2x or x <= xints:
                        inside = not inside
        p1x,p1y = p2x,p2y

    return inside

## Test

yy = indigo.variables[1823083030].value.split(';') # "noaaAlert1CapPolygon"
zz = indigo.variables[1823083030].value # "noaaAlert1CapPolygon"

xx=[]
for ii in range( len( yy)):
   xx.append(yy[ii].split(","))

noaaAlert1CapPolygon = map(int,xx)

lat = float(indigo.variables[201899193].value) # "homeLatitude"
lon = float(indigo.variables[1966208654].value) # "homeLongitude"

polygon = xx

point_x = 32.2989
point_y = -90.1847

## Call the function with the points and the polygon

polygonInside = point_in_poly(point_x,point_y, polygon)

indigo.variable.updateValue(104702043, value=str(polygonInside)) # "noaaAlertPolygonInside1"

indigo.server.log("Raw From Indigo:                 " + str(zz))
indigo.server.log("Imported using value.split (yy): " + str(yy))
indigo.server.log("Then split                 (xx): " + str(xx))

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Mon Apr 14, 2014 7:44 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Make A Python List From An Indigo Variable

As a follow on, it does seem that float(xx[0][0]) yields the correct results. I just need to remember how to iterate that! ;)

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Mon Apr 14, 2014 8:06 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Make A Python List From An Indigo Variable

If you can alter the data inserted into the variable slightly by substituting the parenthesis with brackets they you'll have valid JSON which can be decoded via simplejson (which we include with Indigo):

Code: Select all
import simplejson as json
json.loads("[[35.44,-90.28],[35.65,-90.29],[35.82,-89.89],[35.4,-90],[35.31,-90.4],[35.44,-90.28]]")


Which results in a native Python list of floats.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Apr 14, 2014 9:46 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Make A Python List From An Indigo Variable

Thanks Karl & Jay!

I know how the JSON loader works, so I implemented that way. The load is okay, but the method is expecting [(x1,y1),(x2,y2)] not [[x1,y1],[x2,y2]].

Can you point me towards a way to either change the method, or massage the list to work?

Code: Select all
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This function
# returns True or False.  The algorithm is called
# the "Ray Casting Method".  Adapted from:
# http://geospatialpython.com/2011/01/point-in-polygon.html

import simplejson as json

def point_in_poly(x,y,poly):

   # check if point is a vertex
   if (x,y) in poly: return "IN"

   # check if point is on a boundary
   for i in range(len(poly)):
      p1 = None
      p2 = None
      if i==0:
         p1 = poly[0]
         p2 = poly[1]
      else:
         p1 = poly[i-1]
         p2 = poly[i]
      if p1[1] == p2[1] and p1[1] == y and x > min(p1[0], p2[0]) and x < max(p1[0], p2[0]):
         return "IN"
     
   n = len(poly)
   inside = False

   p1x,p1y = poly[0]
   for i in range(n+1):
      p2x,p2y = poly[i % n]
      if y > min(p1y,p2y):
         if y <= max(p1y,p2y):
            if x <= max(p1x,p2x):
               if p1y != p2y:
                  xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
               if p1x == p2x or x <= xints:
                  inside = not inside
      p1x,p1y = p2x,p2y

   if inside: return "IN"
   else: return "OUT"
## Test

noaaAlertCapPolygon = indigo.variables[1823083030].value # "noaaAlert1CapPolygon"

lat = float(indigo.variables[201899193].value) # "homeLatitude"
lon = float(indigo.variables[1966208654].value) # "homeLongitude"

# polygon = json.loads(noaaAlertCapPolygon)
polygon = [[-33.416032,-70.593016],[-33.415370,-70.589604],[-33.417340,-70.589046],[-33.417949,-70.592351],[-33.416032,-70.593016]]
# polygon = [(-33.416032,-70.593016), (-33.415370,-70.589604),(-33.417340,-70.589046), (-33.417949,-70.592351),(-33.416032,-70.593016)]

point_x = -33.416032
point_y = -70.593016

p1x,p1y = polygon[1]

## Call the function with the points and the polygon

polygonInside = point_in_poly(point_x,point_y, polygon)

indigo.variable.updateValue(104702043, value=str(polygonInside)) # "noaaAlertPolygonInside1"

indigo.server.log("Test float                       " + str(polygon))
indigo.server.log("Raw From Indigo:                 " + str(polygon[1][0]) + str(polygon[1][1]) )
indigo.server.log("Raw From Indigo:                 " + str(p1x) + str(p1y) )

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Mon Apr 14, 2014 10:51 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Make A Python List From An Indigo Variable

Ah, may be some sort of rounding thing. Will investigate further this evening.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Mon Apr 14, 2014 11:12 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Make A Python List From An Indigo Variable

just play around with a python terminal - open terminal enter python, then try this out:
Code: Select all
import json
>>>p="[[-33.416032,-70.593016],[-33.415370,-70.589604],[-33.417340,-70.589046],[-33.417949,-70.592351],[-33.416032,-70.593016]]"
>>> xx=json.loads(p)
>>> xx
[[-33.416032, -70.593016], [-33.41537, -70.589604], [-33.41734, -70.589046], [-33.417949, -70.592351], [-33.416032, -70.593016]]
>>> -33.416032, -70.593016 in xx
(-33.416032, False)
>>> [-33.416032, -70.593016] in xx
True
>>> (-33.416032, -70.593016) in xx
False

Posted on
Mon Apr 14, 2014 11:16 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Make A Python List From An Indigo Variable

I suspect you're right - if you add a log line inside the method that prints each pair that's being compared:

Code: Select all
  Script                          poly pair being checked: [-33.416032000000001, -70.593016000000006] and [-33.415370000000003, -70.589603999999994]
  Script                          poly pair being checked: [-33.416032000000001, -70.593016000000006] and [-33.415370000000003, -70.589603999999994]
  Script                          poly pair being checked: [-33.415370000000003, -70.589603999999994] and [-33.417340000000003, -70.589045999999996]
  Script                          poly pair being checked: [-33.417340000000003, -70.589045999999996] and [-33.417949, -70.592350999999994]
  Script                          poly pair being checked: [-33.417949, -70.592350999999994] and [-33.416032000000001, -70.593016000000006]


Using floats is the problem with your test I suspect. The method is fine with the data in the format create by the JSON decode.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Apr 14, 2014 5:16 pm
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Make A Python List From An Indigo Variable

Okay, thanks again to you both. Rounding was a problem as was the sign of the coordinates. I found that if I used the absolute value it worked.

So, this is cool. Combined with the NOAA Alerts script I wrote in the other thread, I can use this to determine if an immediate weather emergency impacts us and have Indigo alert us. We'll hopefully minimize the false alarms due to tornado touchdowns at the other end of the county and can fire the house's fire alarm/voice and flip on the lights.

Here's the current version -- note the lat/lon is hard coded to a current event in Mississippi. You can test by finding a NOAA alert with a polygon (I use Radar Scope to see this), updating the county code from alerts.weather.gov and entering a lat/lon of a town in the alert area.

Code: Select all
# Determine if a point is inside a given polygon or not
# Polygon is a list of (x,y) pairs. This function
# returns True or False.  The algorithm is called
# the "Ray Casting Method".  Adapted from:
# http://geospatialpython.com/2011/01/point-in-polygon.html

import simplejson as json
import math
import sys

def point_in_poly(x,y,poly):

   # check if point is a vertex
   if (x,y) in poly: return "IN"

   # check if point is on a boundary
   for i in range(len(poly)):
      p1 = None
      p2 = None
      if i==0:
         p1 = poly[0]
         p2 = poly[1]
      else:
         p1 = poly[i-1]
         p2 = poly[i]
      if p1[1] == p2[1] and p1[1] == y and x > min(p1[0], p2[0]) and x < max(p1[0], p2[0]):
         return "IN"
     
   n = len(poly)
   inside = False

   p1xa,p1ya = poly[0]
   p1x = math.fabs(p1xa)
   p1y = math.fabs(p1ya)      
   for i in range(n+1):
      p2xa,p2ya = poly[i % n]
      p2x = math.fabs(p2xa)
      p2y = math.fabs(p2ya)
      if y > min(p1y,p2y):
         if y <= max(p1y,p2y):
            if x <= max(p1x,p2x):
               if p1y != p2y:
                  xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
               if p1x == p2x or x <= xints:
                  inside = not inside
      p1x,p1y = p2x,p2y

   if inside: return "IN"
   else: return "OUT"
## Test

noaaAlertCapPolygon = indigo.variables[1823083030].value # "noaaAlert1CapPolygon"

lat = float(indigo.variables[201899193].value) # "homeLatitude"
lon = float(indigo.variables[1966208654].value) # "homeLongitude"

try:
   polygon = json.loads(noaaAlertCapPolygon)
except ValueError:
   # Decoding Failed
   indigo.variable.updateValue(104702043, value=str("")) # "noaaAlertPolygonInside1"
   sys.exit()

# point_x = math.fabs(lat) # 32.29
# point_y = math.fabs(lon) # 90.18

point_x = 32.29
point_y = 90.18

p1x,p1y = polygon[1]

## Call the function with the points and the polygon

polygonInside = point_in_poly(point_x,point_y, polygon)

indigo.variable.updateValue(104702043, value=str(polygonInside)) # "noaaAlertPolygonInside1"
Code: Select all
import urllib2
from xml.dom.minidom import parseString


# download the file
# theUrl = 'http://alerts.weather.gov/cap/wwaatmget.php?x=TXC439&y=1'
theUrl = 'http://alerts.weather.gov/cap/wwaatmget.php?x=MSC049&y=1'


f = urllib2.urlopen(theUrl)

theXml = f.read()

theDocTree = parseString(theXml)

# HEADER
noaaAlertID0 = theDocTree.getElementsByTagName("id")[0].firstChild.data
noaaAlertGenerator0 = theDocTree.getElementsByTagName("generator")[0].firstChild.data
noaaAlertUpdated0 = theDocTree.getElementsByTagName("updated")[0].firstChild.data
noaaAlertAuthor0 = theDocTree.getElementsByTagName("name")[0].firstChild.data
noaaAlertTitle0 = theDocTree.getElementsByTagName("title")[0].firstChild.data

# ALERT 1
try:
   noaaAlertID1 = theDocTree.getElementsByTagName("id")[1].firstChild.data
   noaaAlertUpdated1 = theDocTree.getElementsByTagName("updated")[1].firstChild.data
   noaaAlertPublished1 = theDocTree.getElementsByTagName("published")[0].firstChild.data
   noaaAlertAuthor1 = theDocTree.getElementsByTagName("name")[1].firstChild.data
   noaaAlertTitle1 = theDocTree.getElementsByTagName("title")[1].firstChild.data
   noaaAlertSummary1 = theDocTree.getElementsByTagName("summary")[0].firstChild.data
   noaaAlertCapEvent1 = theDocTree.getElementsByTagName("cap:event")[0].firstChild.data
   noaaAlertCapEffective1 = theDocTree.getElementsByTagName("cap:effective")[0].firstChild.data
   noaaAlertCapExpires1 = theDocTree.getElementsByTagName("cap:expires")[0].firstChild.data
   noaaAlertCapStatus1 = theDocTree.getElementsByTagName("cap:status")[0].firstChild.data
   noaaAlertCapMsgType1 = theDocTree.getElementsByTagName("cap:msgType")[0].firstChild.data
   noaaAlertCapCategory1 = theDocTree.getElementsByTagName("cap:category")[0].firstChild.data
   noaaAlertCapUrgency1 = theDocTree.getElementsByTagName("cap:urgency")[0].firstChild.data
   noaaAlertCapSeverity1 = theDocTree.getElementsByTagName("cap:severity")[0].firstChild.data
   noaaAlertCapCertainly1 = theDocTree.getElementsByTagName("cap:certainty")[0].firstChild.data
   noaaAlertCapAreaDesc1 = theDocTree.getElementsByTagName("cap:areaDesc")[0].firstChild.data
   noaaAlertPolygon1Temp = theDocTree.getElementsByTagName("cap:polygon")[0].firstChild.data
   noaaAlertPolygon1 = '[[' + noaaAlertPolygon1Temp.replace(' ', '],[') + ']]'

except IndexError, e:
   noaaAlertID1 = ""
   noaaAlertUpdated1 = ""
   noaaAlertPublished1 = ""
   noaaAlertAuthor1 = ""
   noaaAlertTitle1 = ""
   noaaAlertSummary1 = ""
   noaaAlertCapEvent1 = ""
   noaaAlertCapEffective1 = ""
   noaaAlertCapExpires1 = ""
   noaaAlertCapStatus1 = ""
   noaaAlertCapMsgType1 = ""
   noaaAlertCapCategory1 = ""
   noaaAlertCapUrgency1 = ""
   noaaAlertCapSeverity1 = ""
   noaaAlertCapCertainly1 = ""
   noaaAlertCapAreaDesc1 = ""
   noaaAlertPolygon1 = ""

except AttributeError, e: # Needed because cap:polygon is sometimes missing
   noaaAlertPolygon1 = ""


# ALERT 2
try:
   noaaAlertID2 = theDocTree.getElementsByTagName("id")[2].firstChild.data
   noaaAlertUpdated2 = theDocTree.getElementsByTagName("updated")[2].firstChild.data
   noaaAlertPublished2 = theDocTree.getElementsByTagName("published")[1].firstChild.data
   noaaAlertAuthor2 = theDocTree.getElementsByTagName("name")[2].firstChild.data
   noaaAlertTitle2 = theDocTree.getElementsByTagName("title")[2].firstChild.data
   noaaAlertSummary2 = theDocTree.getElementsByTagName("summary")[1].firstChild.data
   noaaAlertCapEvent2 = theDocTree.getElementsByTagName("cap:event")[1].firstChild.data
   noaaAlertCapEffective2 = theDocTree.getElementsByTagName("cap:effective")[1].firstChild.data
   noaaAlertCapExpires2 = theDocTree.getElementsByTagName("cap:expires")[1].firstChild.data
   noaaAlertCapStatus2 = theDocTree.getElementsByTagName("cap:status")[1].firstChild.data
   noaaAlertCapMsgType2 = theDocTree.getElementsByTagName("cap:msgType")[1].firstChild.data
   noaaAlertCapCategory2 = theDocTree.getElementsByTagName("cap:category")[1].firstChild.data
   noaaAlertCapUrgency2 = theDocTree.getElementsByTagName("cap:urgency")[1].firstChild.data
   noaaAlertCapSeverity2 = theDocTree.getElementsByTagName("cap:severity")[1].firstChild.data
   noaaAlertCapCertainly2 = theDocTree.getElementsByTagName("cap:certainty")[1].firstChild.data
   noaaAlertCapAreaDesc2 = theDocTree.getElementsByTagName("cap:areaDesc")[1].firstChild.data
   noaaAlertPolygon2Temp = theDocTree.getElementsByTagName("cap:polygon")[1].firstChild.data
   noaaAlertPolygon2 = '[[' + noaaAlertPolygon2Temp.replace(' ', '],[') + ']]'

except IndexError, e:
   noaaAlertID2 = ""
   noaaAlertUpdated2 = ""
   noaaAlertPublished2 = ""
   noaaAlertAuthor2 = ""
   noaaAlertTitle2 = ""
   noaaAlertSummary2 = ""
   noaaAlertCapEvent2 = ""
   noaaAlertCapEffective2 = ""
   noaaAlertCapExpires2 = ""
   noaaAlertCapStatus2 = ""
   noaaAlertCapMsgType2 = ""
   noaaAlertCapCategory2 = ""
   noaaAlertCapUrgency2 = ""
   noaaAlertCapSeverity2 = ""
   noaaAlertCapCertainly2 = ""
   noaaAlertCapAreaDesc2 = ""
   noaaAlertPolygon2 = ""

except AttributeError, e: # Needed because cap:polygon is sometimes missing
   noaaAlertPolygon2 = ""

# ALERT 3
try:
   noaaAlertID3 = theDocTree.getElementsByTagName("id")[3].firstChild.data
   noaaAlertUpdated3 = theDocTree.getElementsByTagName("updated")[3].firstChild.data
   noaaAlertPublished3 = theDocTree.getElementsByTagName("published")[2].firstChild.data
   noaaAlertAuthor3 = theDocTree.getElementsByTagName("name")[3].firstChild.data
   noaaAlertTitle3 = theDocTree.getElementsByTagName("title")[3].firstChild.data
   noaaAlertSummary3 = theDocTree.getElementsByTagName("summary")[2].firstChild.data
   noaaAlertCapEvent3 = theDocTree.getElementsByTagName("cap:event")[2].firstChild.data
   noaaAlertCapEffective3 = theDocTree.getElementsByTagName("cap:effective")[2].firstChild.data
   noaaAlertCapExpires3 = theDocTree.getElementsByTagName("cap:expires")[2].firstChild.data
   noaaAlertCapStatus3 = theDocTree.getElementsByTagName("cap:status")[2].firstChild.data
   noaaAlertCapMsgType3 = theDocTree.getElementsByTagName("cap:msgType")[2].firstChild.data
   noaaAlertCapCategory3 = theDocTree.getElementsByTagName("cap:category")[2].firstChild.data
   noaaAlertCapUrgency3 = theDocTree.getElementsByTagName("cap:urgency")[2].firstChild.data
   noaaAlertCapSeverity3 = theDocTree.getElementsByTagName("cap:severity")[2].firstChild.data
   noaaAlertCapCertainly3 = theDocTree.getElementsByTagName("cap:certainty")[2].firstChild.data
   noaaAlertCapAreaDesc3 = theDocTree.getElementsByTagName("cap:areaDesc")[2].firstChild.data
   noaaAlertPolygon3Temp = theDocTree.getElementsByTagName("cap:polygon")[2].firstChild.data
   noaaAlertPolygon3 = '[[' + noaaAlertPolygon3Temp.replace(' ', '],[') + ']]'

except IndexError, e:
   noaaAlertID3 = ""
   noaaAlertUpdated3 = ""
   noaaAlertPublished3 = ""
   noaaAlertAuthor3 = ""
   noaaAlertTitle3 = ""
   noaaAlertSummary3 = ""
   noaaAlertCapEvent3 = ""
   noaaAlertCapEffective3 = ""
   noaaAlertCapExpires3 = ""
   noaaAlertCapStatus3 = ""
   noaaAlertCapMsgType3 = ""
   noaaAlertCapCategory3 = ""
   noaaAlertCapUrgency3 = ""
   noaaAlertCapSeverity3 = ""
   noaaAlertCapCertainly3 = ""
   noaaAlertCapAreaDesc3 = ""
   noaaAlertPolygon3 = ""

except AttributeError, e: # Needed because cap:polygon is sometimes missing
   noaaAlertPolygon3 = ""

# ALERT 4
try:
   noaaAlertID4 = theDocTree.getElementsByTagName("id")[4].firstChild.data
   noaaAlertUpdated4 = theDocTree.getElementsByTagName("updated")[4].firstChild.data
   noaaAlertPublished4 = theDocTree.getElementsByTagName("published")[3].firstChild.data
   noaaAlertAuthor4 = theDocTree.getElementsByTagName("name")[4].firstChild.data
   noaaAlertTitle4 = theDocTree.getElementsByTagName("title")[4].firstChild.data
   noaaAlertSummary4 = theDocTree.getElementsByTagName("summary")[3].firstChild.data
   noaaAlertCapEvent4 = theDocTree.getElementsByTagName("cap:event")[3].firstChild.data
   noaaAlertCapEffective4 = theDocTree.getElementsByTagName("cap:effective")[3].firstChild.data
   noaaAlertCapExpires4 = theDocTree.getElementsByTagName("cap:expires")[3].firstChild.data
   noaaAlertCapStatus4 = theDocTree.getElementsByTagName("cap:status")[3].firstChild.data
   noaaAlertCapMsgType4 = theDocTree.getElementsByTagName("cap:msgType")[3].firstChild.data
   noaaAlertCapCategory4 = theDocTree.getElementsByTagName("cap:category")[3].firstChild.data
   noaaAlertCapUrgency4 = theDocTree.getElementsByTagName("cap:urgency")[3].firstChild.data
   noaaAlertCapSeverity4 = theDocTree.getElementsByTagName("cap:severity")[3].firstChild.data
   noaaAlertCapCertainly4 = theDocTree.getElementsByTagName("cap:certainty")[3].firstChild.data
   noaaAlertCapAreaDesc4 = theDocTree.getElementsByTagName("cap:areaDesc")[3].firstChild.data
   noaaAlertPolygon4Temp = theDocTree.getElementsByTagName("cap:polygon")[3].firstChild.data
   noaaAlertPolygon4 = '[[' + noaaAlertPolygon4Temp.replace(' ', '],[') + ']]'

except IndexError, e:
   noaaAlertID4 = ""
   noaaAlertUpdated4 = ""
   noaaAlertPublished4 = ""
   noaaAlertAuthor4 = ""
   noaaAlertTitle4 = ""
   noaaAlertSummary4 = ""
   noaaAlertCapEvent4 = ""
   noaaAlertCapEffective4 = ""
   noaaAlertCapExpires4 = ""
   noaaAlertCapStatus4 = ""
   noaaAlertCapMsgType4 = ""
   noaaAlertCapCategory4 = ""
   noaaAlertCapUrgency4 = ""
   noaaAlertCapSeverity4 = ""
   noaaAlertCapCertainly4 = ""
   noaaAlertCapAreaDesc4 = ""
   noaaAlertPolygon4 = ""

except AttributeError, e: # Needed because cap:polygon is sometimes missing
   noaaAlertPolygon4 = ""

# WRITE HEADER TO INDIGO
indigo.variable.updateValue(251912902, value=str(noaaAlertID0)) # "noaaAlert0ID"
indigo.variable.updateValue(488888730, value=str(noaaAlertGenerator0)) # "noaaAlert0Generator"
indigo.variable.updateValue(1041636278, value=str(noaaAlertUpdated0)) # "noaaAlert0Updated"
indigo.variable.updateValue(851481444, value=str(noaaAlertAuthor0)) # "noaaAlert0Author"
indigo.variable.updateValue(414199120, value=str(noaaAlertTitle0)) # "noaaAlert0Title"

# WRITE ALERT 1 TO INDIGO
indigo.variable.updateValue(970579805, value=str(noaaAlertID1)) # "noaaAlertID1"
indigo.variable.updateValue(451934914, value=str(noaaAlertUpdated1)) # "noaaAlertUpdated1"
indigo.variable.updateValue(45734687, value=str(noaaAlertPublished1)) # "noaaAlertPublished1"
indigo.variable.updateValue(530210630, value=str(noaaAlertAuthor1)) # "noaaAlertAuthor1"
indigo.variable.updateValue(1508190911, value=str(noaaAlertTitle1)) # "noaaAlertTitle1"
indigo.variable.updateValue(27131104, value=str(noaaAlertSummary1)) # "noaaAlertSummary1"
indigo.variable.updateValue(507770105, value=str(noaaAlertCapEvent1)) # "noaaAlertCapEvent1"
indigo.variable.updateValue(1350045247, value=str(noaaAlertCapEffective1)) # "noaaAlertCapEffective1"
indigo.variable.updateValue(1045605899, value=str(noaaAlertCapExpires1)) # "noaaAlertCapExpires1"
indigo.variable.updateValue(1694945345, value=str(noaaAlertCapStatus1)) # "noaaAlertCapStatus1" Actual, Excercise, System, Test, Draft
indigo.variable.updateValue(361396269, value=str(noaaAlertCapMsgType1)) # "noaaAlertCapMsgType1" Alert, Update, Cancel, Ack, Error
indigo.variable.updateValue(636093119, value=str(noaaAlertCapCategory1)) # "noaaAlertCapCategory1" Geo, Met, Safety, Security, Rescue, Fire, Health, Env, Transport, Infra, CBRNE, Other
indigo.variable.updateValue(101309718, value=str(noaaAlertCapUrgency1)) # "noaaAlertCapUrgency1" Immediate, Expected, Future, Past Unknown
indigo.variable.updateValue(431261270, value=str(noaaAlertCapSeverity1)) # "noaaAlertCapSeverity1" Extreme, Severe, Moderate, Minor, Unknown
indigo.variable.updateValue(6635718, value=str(noaaAlertCapCertainly1)) # "noaaAlertCapCertainty1" Observed, Likely, Possible, Unlikely, Unknown
indigo.variable.updateValue(1574026820, value=str(noaaAlertCapAreaDesc1)) # "noaaAlertCapAreaDesc1"
indigo.variable.updateValue(1823083030, value=str(noaaAlertPolygon1)) # "noaaAlertPolygon1"

# WRITE ALERT 2 TO INDIGO
indigo.variable.updateValue(1818783764, value=str(noaaAlertID2)) # "noaaAlertID2"
indigo.variable.updateValue(1676631089, value=str(noaaAlertUpdated2)) # "noaaAlertUpdated2"
indigo.variable.updateValue(318906496, value=str(noaaAlertPublished2)) # "noaaAlertPublished2"
indigo.variable.updateValue(367560147, value=str(noaaAlertAuthor2)) # "noaaAlertAuthor2"
indigo.variable.updateValue(1084941128, value=str(noaaAlertTitle2)) # "noaaAlertTitle2"
indigo.variable.updateValue(958812312, value=str(noaaAlertSummary2)) # "noaaAlertSummary2"
indigo.variable.updateValue(1429059287, value=str(noaaAlertCapEvent2)) # "noaaAlertCapEvent2"
indigo.variable.updateValue(146835994, value=str(noaaAlertCapEffective2)) # "noaaAlertCapEffective2"
indigo.variable.updateValue(657166470, value=str(noaaAlertCapExpires2)) # "noaaAlertCapExpires2"
indigo.variable.updateValue(34992235, value=str(noaaAlertCapStatus2)) # "noaaAlertCapStatus2" Actual, Excercise, System, Test, Draft
indigo.variable.updateValue(520328817, value=str(noaaAlertCapMsgType2)) # "noaaAlertCapMsgType2" Alert, Update, Cancel, Ack, Error
indigo.variable.updateValue(1721937615, value=str(noaaAlertCapCategory2)) # "noaaAlertCapCategory2" Geo, Met, Safety, Security, Rescue, Fire, Health, Env, Transport, Infra, CBRNE, Other
indigo.variable.updateValue(1674307807, value=str(noaaAlertCapUrgency2)) # "noaaAlertCapUrgency2" Immediate, Expected, Future, Past Unknown
indigo.variable.updateValue(1381376882, value=str(noaaAlertCapSeverity2)) # "noaaAlertCapSeverity2" Extreme, Severe, Moderate, Minor, Unknown
indigo.variable.updateValue(78500200, value=str(noaaAlertCapCertainly2)) # "noaaAlertCapCertainty2" Observed, Likely, Possible, Unlikely, Unknown
indigo.variable.updateValue(653615352, value=str(noaaAlertCapAreaDesc2)) # "noaaAlertCapAreaDesc2"
indigo.variable.updateValue(856990534, value=str(noaaAlertPolygon2)) # "noaaAlertPolygon2"

# WRITE ALERT 3 TO INDIGO
indigo.variable.updateValue(250611685, value=str(noaaAlertID3)) # "noaaAlertID3"
indigo.variable.updateValue(660531607, value=str(noaaAlertUpdated3)) # "noaaAlertUpdated3"
indigo.variable.updateValue(1866465128, value=str(noaaAlertPublished3)) # "noaaAlertPublished3"
indigo.variable.updateValue(1601846800, value=str(noaaAlertAuthor3)) # "noaaAlertAuthor3"
indigo.variable.updateValue(1576616853, value=str(noaaAlertTitle3)) # "noaaAlertTitle3"
indigo.variable.updateValue(51231625, value=str(noaaAlertSummary3)) # "noaaAlertSummary3"
indigo.variable.updateValue(1019018204, value=str(noaaAlertCapEvent3)) # "noaaAlertCapEvent3"
indigo.variable.updateValue(1318897258, value=str(noaaAlertCapEffective3)) # "noaaAlertCapEffective3"
indigo.variable.updateValue(1593320108, value=str(noaaAlertCapExpires3)) # "noaaAlertCapExpires3"
indigo.variable.updateValue(1380632583, value=str(noaaAlertCapStatus3)) # "noaaAlertCapStatus3" Actual, Excercise, System, Test, Draft
indigo.variable.updateValue(1709855541, value=str(noaaAlertCapMsgType3)) # "noaaAlertCapMsgType3" Alert, Update, Cancel, Ack, Error
indigo.variable.updateValue(473568572, value=str(noaaAlertCapCategory3)) # "noaaAlertCapCategory3" Geo, Met, Safety, Security, Rescue, Fire, Health, Env, Transport, Infra, CBRNE, Other
indigo.variable.updateValue(372339663, value=str(noaaAlertCapUrgency3)) # "noaaAlertCapUrgency3" Immediate, Expected, Future, Past Unknown
indigo.variable.updateValue(1676970597, value=str(noaaAlertCapSeverity3)) # "noaaAlertCapSeverity3" Extreme, Severe, Moderate, Minor, Unknown
indigo.variable.updateValue(1139743337, value=str(noaaAlertCapCertainly3)) # "noaaAlertCapCertainty3" Observed, Likely, Possible, Unlikely, Unknown
indigo.variable.updateValue(487568757, value=str(noaaAlertCapAreaDesc3)) # "noaaAlertCapAreaDesc1"
indigo.variable.updateValue(667083469, value=str(noaaAlertPolygon3)) # "noaaAlertPolygon3"

# WRITE ALERT 4 TO INDIGO
indigo.variable.updateValue(1399660509, value=str(noaaAlertID4)) # "noaaAlertID4"
indigo.variable.updateValue(1661417371, value=str(noaaAlertUpdated4)) # "noaaAlertUpdated4"
indigo.variable.updateValue(450104477, value=str(noaaAlertPublished4)) # "noaaAlertPublished4"
indigo.variable.updateValue(1237945019, value=str(noaaAlertAuthor4)) # "noaaAlertAuthor4"
indigo.variable.updateValue(547657858, value=str(noaaAlertTitle4)) # "noaaAlertTitle4"
indigo.variable.updateValue(326675971, value=str(noaaAlertSummary4)) # "noaaAlertSummary4"
indigo.variable.updateValue(1499896221, value=str(noaaAlertCapEvent4)) # "noaaAlertCapEvent4"
indigo.variable.updateValue(56670747, value=str(noaaAlertCapEffective4)) # "noaaAlertCapEffective4"
indigo.variable.updateValue(232105237, value=str(noaaAlertCapExpires4)) # "noaaAlertCapExpires4"
indigo.variable.updateValue(1249037109, value=str(noaaAlertCapStatus4)) # "noaaAlertCapStatus4" Actual, Excercise, System, Test, Draft
indigo.variable.updateValue(1610819848, value=str(noaaAlertCapMsgType4)) # "noaaAlertCapMsgType4" Alert, Update, Cancel, Ack, Error
indigo.variable.updateValue(1954312401, value=str(noaaAlertCapCategory4)) # "noaaAlertCapCategory4" Geo, Met, Safety, Security, Rescue, Fire, Health, Env, Transport, Infra, CBRNE, Other
indigo.variable.updateValue(1035974472, value=str(noaaAlertCapUrgency4)) # "noaaAlertCapUrgency4" Immediate, Expected, Future, Past Unknown
indigo.variable.updateValue(1701840599, value=str(noaaAlertCapSeverity4)) # "noaaAlertCapSeverity4" Extreme, Severe, Moderate, Minor, Unknown
indigo.variable.updateValue(393185168, value=str(noaaAlertCapCertainly4)) # "noaaAlertCapCertainty4" Observed, Likely, Possible, Unlikely, Unknown
indigo.variable.updateValue(341984009, value=str(noaaAlertCapAreaDesc4)) # "noaaAlertCapAreaDesc4"
indigo.variable.updateValue(804386241, value=str(noaaAlertPolygon4)) # "noaaAlertPolygon4"

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Tue Apr 15, 2014 9:13 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Make A Python List From An Indigo Variable

Nice contribution. Ever thought about making it a plugin? You're probably already like 70% there. I could see a couple of things that could be fairly easily done:

  • Fire events whenever a new alert comes in - this wouldn't require creating devices, just specify the lat/lon somewhere (either in the plugin config for just a single location or in the event config for multiple) then the plugin will just monitor that lat/lon for alerts. Then users could just use the UI as with all other events.
  • Create an alert device that contains all the relevant states (what you have stored in variables now) and just update those as they change. This one is a bit more tricky because there are 4 different alerts - but since they seem to have a unique ID from NOAA it's manageable. You'd want to handle expired alerts of course in some way such that a user could know the difference between a new alert and an expiration. If it always has exactly 4 possible alerts you could create 4 dependent devices or something. Anyway, it's a bit more tricky.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 22, 2014 11:36 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: [SOLVED]Make A Python List From An Indigo Variable

Yeah, that would be a fun project, but the reality is that I'm only one step above a monkey typing Shakespeare. The remaining 20-30% would probably take 10x the time the first 70% took because we're entering territory that I don't claim to understand.

I'm particularly concerned about the database issues -- I wrote for four alerts, but there could be anywhere between 0 and 26 alerts. I figured that if you're already about to be imminently hit by a tornado, the flood warning for later in the day is less of a concern. The alerts change as issued, so the most recent appears to be alert 1. As I watched the storms pass, I saw the alerts move between places 1-3 as they were updated. I'm sure this could be managed through a database, especially since each alert has a unique identifier.

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests