Weather Underground Web Smartapp: the "poor guy" weather station with event based switches automation [Deprecated. See Weather Company version below]

Ok, will give a try then!

Thanks for the hint

I found this in the ST DTH and kinda copied it and modified for my own use. Seems to work fine. Since I only want notifications for certain alerts. I still need to modify the state.prevalert to make it an array in case there are multiple alerts at the same time. If someone could suggest a good way to do that, would be appreciated.

def params = getWeatherFeature(“alerts”)?.alerts

params.each {alert ->
	log.debug "${alert.description} from ${alert.date} until ${alert.expires}"
	if (alert.type != "" && alert.type != state.prevalert) {
		sendNotificationEvent("Type ${alert.type} is ${alert.description} from ${alert.date} till ${alert.expires}")
			if (alert.type == "TOR" || alert.type == "TOW" || alert.type == "WRN" || alert.type == "SEW" || alert.type == "SVR") {
		        sendNotificationToContacts("${alert.description} from ${alert.date} till ${alert.expires}", recipients)  
			}
	}
	state.prevalert = alert.type
}

Regarding the above post. Since I am still in the learning curve on this type of programming. Could anyone explain to me what the ‘?.alerts’ does.

Also how does the params.each etc. work.

Just a general explanation. At my age it has to be simple too…:slight_smile:

Just for my reference, are you coming from other types of programming or are you fairly new to the world of programming? That helps with the type of response for these questions :slight_smile:.

?.alerts -> https://stackoverflow.com/questions/24186387/what-is-the-purpose-of-question-mark-after-a-variable-in-groovy

params.each iterates of each item in params. In this case, params is an array of alerts.

Years ago I did programming starting with machine language, even hand assembling some when I didn’t have an assembler. Graduated to Basic when it came out. Did some C and C++ after that. Then for over 25 years about all I did was PLC ladder logic programming. So I’m familiar with programming principles but not necessarily the current languages. Now that I’m sorta retired and have so much time on my hands, NOT, I enjoy getting back into it just for my own use. And the brain not being what it used to be…

This doesn’t seem to work. All I get is [] even tho there is an alert present.

def params = getWeatherFeature(“alerts”)?.alerts
log.debug params[‘alerts’][‘type’]

Figured it out. My trial and error method didn’t fail. I had to put the array element on params instead of type.

params[0][‘type’]

You might not want to go that way. WU interface specifies an array of alert meaning more than one can be issued at a time, so you certainly want to iterate over them like in the snippet you posted earlier. I believe you anyway use that snippet code for your smartpp.

From the data I’m getting it appears that the latest alert is always in the first array subscript. Since I’m only interested it a few of the alerts only it is not a problem. I just do a comparison for the alerts I’m looking for and send myself a push message if one of them occurs. The odds are very slim that any 2 of what I am looking for will occur at the same time.

Last summer, I got Fire alerts as well as wind advisory alert in CA at the same time. So if I have to trigger something on wind advisory for instance, I would always loop all the alerts in the array to search for it.

I’m not actually doing any automation with it, just sending me an alert. Kinda a backup for my weather radio.

Updated my code to use your interface. Works fine!

Thanks again

1 Like

I followed the instructions above, but I cannot get the WU information to show up anywhere. any help out there would be appreciated.

Hi there, you used the code posted on GitHub - philippeportesppo/WeatherUndergroundWeb_SmartThings: Smartapp and device to automate things based on webbased WeatherUnderground API services ?

Only steps are:

  • Import in your IDE the Smartapp and devicehandlers and publish the 2 for yourselves
    In the SmartApp menu of the Automation section in the mobile app, add Weather Underground Web Smartapp
  • Setup the threshold and alerts you want to monitor
  • Select the switches you want to turn on or off upon the alert trigger
  • Enjoy localized weather alerts and automation!

Has the getWeatherFeature not working anymore. I have been using that in this app for some time with no problem. Now I modified the app to take out the contacts notification. But now I get an error saying Can’t get property type for the following code snippet. I have checked to make sure I didn’t delete or add a () or something and no problem there.

def params = getWeatherFeature(“alerts”)?.alerts

def alerttype = params[0]['type']
def alertdescription = params[0]['description']
def alertdate = params[0]['date']
def alertexpires = params[0]['expires']

Works fine on my end.

Since I don’t use your code I am not sure. I remember from above that this code you snipet is your code adaptation to filter specific alerts, right?
It seems your getWeatherAlert function is no longer returning anything.

if you share your entire code/github, I can have a try.

Not sure how to do the github thing. I guess one of these days I will have to figure it out. In any case, here is the complete code. As I said it was working fine until I removed the contacts and changed the notification.

/**

  • My Weather Alerts
  • Copyright 2018 Jim White
  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.

*/
definition(
name: “My Weather Alerts”,
namespace: “jwwhite001”,
author: “Jim White”,
description: “Checks Weather Underground For Alerts and Sends Notification”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

import groovy.json.JsonSlurper

preferences {
section(“Weather Check Time”) {
input “chktime”, “number”, required: true, title: “Time Interval To Check Weather (minutes)”
}

}

def installed() {
log.debug “Installed with settings: ${settings}”

initialize()

}

def updated() {
log.debug “Updated with settings: ${settings}”

unsubscribe()
initialize()

}

def initialize() {
state.prevalert = “”
state.prevalerts = ["","","",""]
alerts()
runEvery15Minutes(alerts)

}

// handle commands
def alerts() {
log.debug “Executing alerts”

Map options = [:]

def params = getWeatherFeature(“alerts”)?.alerts

def alerttype = params[0]['type']
def alertdescription = params[0]['description']
def alertdate = params[0]['date']
def alertexpires = params[0]['expires']

log.debug "Type=$alerttype, Description=$alertdescription, Date =$alertdate, Expires=$alertexpires" 

if (alerttype != "" && alerttype != state.prevalert) {
	sendNotificationEvent("Type $alerttype is $alertdescription from $alertdate till $alertexpires")
		if (alerttype == "TOR" || alerttype == "TOW" || alerttype == "WRN" || alerttype == "SEW" || alerttype == "SVR") {
	        sendSms("***","$alertdescription from $alertdate till $alertexpires")  
		}
}
state.prevalert = alerttype
log.debug "$alerttype, $state.prevalert"            

}

Alright, just remove the [0] after your params and it will work.

Seems WU changed their interface if this was working before as a list.

OK, that worked. Or at least I don’t get an error now. Have to wait for some weather to see if it shows up.

I seem to remember when I first did this i didn’t have the [0] and had to add it to make it work. So something must have changed.

@Philippe_Portes I have it installed, and only have one toggle on storm alert. I set the switch to go on and click save and receive an error. Any idea why?