Question on severe weather alert text

Posted on
Wed May 09, 2018 7:08 am
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Question on severe weather alert text

Hi Dave, could you tell me if it is possible to capture the full text of a severe weather alert. I know when we get one I see it in the log but I can't figure out where it is held in indigo. I would like to use it to paste into a Alexa notify me message but not sure how to go about getting the severe weather alert text into the script.

Jay provided some examples of how to use the notify me skill here

viewtopic.php?f=123&t=20641#p159895

_______
Norm

Posted on
Wed May 09, 2018 7:15 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Question on severe weather alert text

It's in the alertMessage1 (alertMessage2, etc) state value. I use the following script to email me any alert messages.

Code: Select all
wsStates = indigo.devices[665073353].states #

def sendAlertEmail(alert, message, expires):
   theSubject = "Cape Coral Weather Alert: %s" % alert
   theBody = "%s\n\nThis weather alert is valid until %s" % (message, expires)

   bePlugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.betteremail")
   if bePlugin.isEnabled():
      bePlugin.executeAction("sendEmail", deviceId=1422637605,
      props={'emailTo':'joe@foo.bar, 'emailSubject': theSubject, 'emailMessage': theBody})
      
   return

if wsStates[u'alertDescription1'] != ' ':
   sendAlertEmail(wsStates[u'alertDescription1'], wsStates[u'alertMessage1'], wsStates[u'alertExpires1'])

if wsStates[u'alertDescription2'] != ' ':
   sendAlertEmail(wsStates[u'alertDescription2'], wsStates[u'alertMessage2'], wsStates[u'alertExpires2'])

if wsStates[u'alertDescription3'] != ' ':
   sendAlertEmail(wsStates[u'alertDescription3'], wsStates[u'alertMessage3'], wsStates[u'alertExpires3'])

if wsStates[u'alertDescription4'] != ' ':
   sendAlertEmail(wsStates[u'alertDescription4'], wsStates[u'alertMessage4'], wsStates[u'alertExpires4'])


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

Posted on
Wed May 09, 2018 7:37 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Question on severe weather alert text

Joe's right. You can add a bit of extra efficiency too, by keying on the state 'alertStatus'. That state will be 'false' if there are no severe alerts reported. Note that it's stored as a string so you'd have to:

Code: Select all
if wsStates[u'alertStatus'] == 'true':

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

[My Plugins] - [My Forums]

Posted on
Wed May 09, 2018 7:54 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Question on severe weather alert text

DaveL17 wrote:
Joe's right. You can add a bit of extra efficiency too, by keying on the state 'alertStatus'. That state will be 'false' if there are no severe alerts reported. Note that it's stored as a string so you'd have to:

Code: Select all
if wsStates[u'alertStatus'] == 'true':


That's actually the trigger for the above script. ;)

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

Posted on
Wed May 09, 2018 8:01 am
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Re: Question on severe weather alert text

BIG, BIG thank you to the both of you for the help - this will be really cool if I can get it working. Seems like with the right code you guys can get Indigo to do almost anything - control your flying cars, verify the transport target date for your time machines.... :lol:

_______
Norm

Posted on
Wed May 09, 2018 8:41 am
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Re: Question on severe weather alert text

Since I don't have anyway to test this -- wondering if one of you could look and let me know if any syntax issues or logic problems... :?:

Code: Select all
import json, requests

# Get the access code from an Indigo variable - you could also just
# paste in the string, but this is much more reusable. Just create
# a new Indigo variable (name doesn't matter) and paste in the
# access code you got in the email from notifymyecho.com and
# use that varible's ID here

access_code = indigo.variables[1731541178].value # ID of variable with access code
wsStates = indigo.devices[95266216].states #Weather Underground Alert device states

#if wsStates[u'alertStatus'] == 'true': #Assuming this is in a separate external trigger

  if wsStates[u'alertDescription1'] != ' ':
  notification_string = wsStates[u'alertDescription1'] + wsStates[u'alertMessage1’] + “ Expires ” + wsStates[u'alertExpires1']

  if wsStates[u'alertDescription2'] != ' ':
  notification_string = wsStates[u'alertDescription2’] + wsStates[u'alertMessage2’] + “ Expires ” + wsStates[u'alertExpires2’]

  if wsStates[u'alertDescription3'] != ' ':
  notification_string = wsStates[u'alertDescription3’] + wsStates[u'alertMessage3’] + “ Expires ” + wsStates[u'alertExpires3’]

  if wsStates[u'alertDescription4'] != ' ':
  notification_string = wsStates[u'alertDescription4’] + wsStates[u'alertMessage4’] + “ Expires ” + wsStates[u'alertExpires4’]

body = json.dumps({
    "notification": notification_string,
    "accessCode": access_code,
})
requests.post(url="https://api.notifymyecho.com/v1/NotifyMe", data=body)

_______
Norm

Posted on
Wed May 09, 2018 8:43 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Question on severe weather alert text

Be very careful, though. If you tell Indigo to do something in the past, it *WILL* do it.

When a light turns on and I can't figure out why, I usually chalk it up to Future Me doing something to mess with Past Me.

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

[My Plugins] - [My Forums]

Posted on
Wed May 09, 2018 8:47 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Question on severe weather alert text

You've got indentation issues which will cause Python to choke.

Also, if there's more than one Alert set, you're only going to get the last one. That's why mine has the notification in a function that can be called for any of the alert messages.

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

Posted on
Wed May 09, 2018 8:49 am
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Re: Question on severe weather alert text

Knowing me - I'm pretty sure, future me, would be too lazy to bother with present me - he (me) is more likely to be taking a nap on a floating futuristic bed (with built in refrigerator).

_______
Norm

Posted on
Wed May 09, 2018 8:51 am
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Re: Question on severe weather alert text

Thanks Joe - time for me to get my wife to help me - she has a CS degree but does not share my love of HA :-)

_______
Norm

Posted on
Wed May 09, 2018 10:44 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Question on severe weather alert text

I would also suggest that you might not want to send the entire alert message to the echo for an announcement. They can be exceedingly long and, if there are two or three alerts, I could see that becoming exceptionally annoying--especially give that there is often shorthand and codes in body of the message. I'd suggest not using the alert message and limiting the announcement to just the description and expiration.

Thought being: echo announces "thunderstorm warning" and then that would prompt you to look at the description.

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

[My Plugins] - [My Forums]

Posted on
Wed May 09, 2018 12:08 pm
norcoscia offline
User avatar
Posts: 1206
Joined: Sep 09, 2015

Re: Question on severe weather alert text

Good point Dave, maybe I'm over doing it. Simpler is sometimes better. Thanks again for your great Indigo plug-in work :D

PS. But I still want a robot :D

_______
Norm

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 16 guests