Here's a few examples of how to use weather alerts from the Weather Underground module user 123 created.
The idea is your system can text your phone, make announcements, pause your movie, change to the weather channel, flash lights, etc when an alert of predefined severity is received.
Under Home.Weather.Alerts add this "OnChangeAlertsTotal" script.
if sysevent.newVal > 0 then
' iff an alert was added
if sysevent.oldVal < sysevent.newVal then
system.addTimer 5,"gWeatherAlert",1,"AlertNotification_" & this.ObjectID
end if
end if
The script calls a global script gWeatherAlert.
gWeatherAlert will text my phone, and even announce a warning (if it is severe enough)
gWeatherAlert looks like this:
function gWeatherAlert()
' email alert
dim oAlert
for each oAlert in Home.Weather.Alerts.GetObjectsByType(Schema.Modules.WeatherUnderground.Classes.Alert.Path)
tSubject = oAlert.AlertPhenomena & "--" & oAlert.AlertDescription
iSeverity = gGetWeatherSeverity(oAlert)
tBody = "SEVERITY LEVEL: " & iSeverity & "...EXPIRES: " & oAlert.AlertExpiryDateTime & "..." & oAlert.AlertMessage
if iSeverity >= 0 then
gTextPhones tBody, tSubject
end if
if iSeverity > 3 then
' announce warning
gMuteAndPause ' mute and pause all media zones
Devices.CustomDevices.M1_Panel.Voice.WeatherWarning.Play = true
for each oMediaCenter in devices.CustomDevices.GetObjectsByType(Modules.Microsoft.Classes.MediaCenter.Path,false)
oMediaCenter.Send_Message "Possible Tornado or Hurricane Warning",Now,300
next
end if
next
set oAlert = nothing
end function
You'll have to modify the code under the two "if iSeverity >...then" statements. What is there now will not be compatible with your system.
gGetWeatherSeverity is the global script that correlates a user defined severity to the Weather Underground U.S. alert type. The idea is you tailor the iSeverity variable to meet your needs. For my area, I am most concerned with Tornado and Hurricane warnings, so I wrote code to give these a higher iSeverity than advisories and watches.
gGetWeatherSeverity looks like this:
function gGetWeatherSeverity(oAlert)
iSeverity = 0
bValid = true
sAlertType = trim(lcase(oAlert.AlertType))
sAlertMessage = oAlert.AlertMessage
bWarning = false
bWatch = false
select case sAlertType
case "hur" ' hurricane advisory
iSeverity = 4
case "tor" ' tornado warning
iSeverity = 5
case "tow" ' tornado watch
iSeverity = 4
case "wrn" ' thunderstorm warning
iSeverity = 3
case "sew" ' thunderstorm watch
iSeverity = 1
case "win" ' winter adv
iSeverity = 1
case "flo" ' flood warning
iSeverity = 2
case "wat" ' flood watch
iSeverity = 0
case "wnd" ' high wind advisory
iSeverity = 1
case "svr" ' severe weather statement
iSeverity = 0
case "hea" ' heat adv
iSeverity = 0
case "fog" ' fog
iSeverity = 0
case "spe" ' special weather statement
iSeverity = 0
case "fir" ' fire adv
iSeverity = 4
case "vol" ' volcanic activity
iSeverity = 5
case "hww" ' hurricane wind warning
iSeverity = 5
case "rec" ' record set
iSeverity = 0
case "rep" ' public reports
iSeverity = 0
case "pub" ' public information statement
iSeverity = 0
case else
bValid = false
end select
' if no valid identifier, then use keywords
if bValid = false then
' is there a potential warning
if instr(1,sAlertMessage,"warning",1) then
bWarning = true
elseif instr(1,sAlertMessage,"watch",1) then
bWatch = true
end if
if bWatch then
if instr(1,sAlertMessage,"tornado",1) then
iSeverity = 4
elseif instr(1,sAlertMessage,"hurricane",1) then
iSeverity = 4
elseif instr(1,sAlertMessage,"thunderstorm",1) then
iSeverity = 2
end if
elseif bWarning then
if instr(1,sAlertMessage,"tornado",1) then
iSeverity = 5
elseif instr(1,sAlertMessage,"hurricane",1) then
iSeverity = 5
elseif instr(1,sAlertMessage,"thunderstorm",1) then
iSeverity = 3
end if
end if
end if
gGetWeatherSeverity = iSeverity
end function
A few keywords are searched for if there is an invalid AlertType. This is probably not necessary, but I have seen a WU alert that was missing its AlertType once, so I put the keywords in for the more severe weather warnings just to be safe.
As a disclaimer do not use this as a weather alert radio. Premise will only grab alert updates every 15 minutes and 30 minutes is the default. This may not be enough of a warning for tornados!!!
You can modify sys://Schema/Modules/WeatherUnderground/Classes/Weather/OnChangeUpdateInterval and sys://Schema/Modules/WeatherUnderground/Classes/Weather/StartUpdateTimer to allow more frequent updates. I changed my system to get rid of the 15 minute limit and I am using 5 minutes.
StartUpdateTimer
'
if this.UpdateInterval > 1 then
system.addTimer this.UpdateInterval * 60, "this.Update = true", 1, "Weather_" & this.ObjectID
end if
OnChangeUpdateInterval
The idea is your system can text your phone, make announcements, pause your movie, change to the weather channel, flash lights, etc when an alert of predefined severity is received.
Under Home.Weather.Alerts add this "OnChangeAlertsTotal" script.
if sysevent.newVal > 0 then
' iff an alert was added
if sysevent.oldVal < sysevent.newVal then
system.addTimer 5,"gWeatherAlert",1,"AlertNotification_" & this.ObjectID
end if
end if
The script calls a global script gWeatherAlert.
gWeatherAlert will text my phone, and even announce a warning (if it is severe enough)
gWeatherAlert looks like this:
function gWeatherAlert()
' email alert
dim oAlert
for each oAlert in Home.Weather.Alerts.GetObjectsByType(Schema.Modules.WeatherUnderground.Classes.Alert.Path)
tSubject = oAlert.AlertPhenomena & "--" & oAlert.AlertDescription
iSeverity = gGetWeatherSeverity(oAlert)
tBody = "SEVERITY LEVEL: " & iSeverity & "...EXPIRES: " & oAlert.AlertExpiryDateTime & "..." & oAlert.AlertMessage
if iSeverity >= 0 then
gTextPhones tBody, tSubject
end if
if iSeverity > 3 then
' announce warning
gMuteAndPause ' mute and pause all media zones
Devices.CustomDevices.M1_Panel.Voice.WeatherWarning.Play = true
for each oMediaCenter in devices.CustomDevices.GetObjectsByType(Modules.Microsoft.Classes.MediaCenter.Path,false)
oMediaCenter.Send_Message "Possible Tornado or Hurricane Warning",Now,300
next
end if
next
set oAlert = nothing
end function
You'll have to modify the code under the two "if iSeverity >...then" statements. What is there now will not be compatible with your system.
gGetWeatherSeverity is the global script that correlates a user defined severity to the Weather Underground U.S. alert type. The idea is you tailor the iSeverity variable to meet your needs. For my area, I am most concerned with Tornado and Hurricane warnings, so I wrote code to give these a higher iSeverity than advisories and watches.
gGetWeatherSeverity looks like this:
function gGetWeatherSeverity(oAlert)
iSeverity = 0
bValid = true
sAlertType = trim(lcase(oAlert.AlertType))
sAlertMessage = oAlert.AlertMessage
bWarning = false
bWatch = false
select case sAlertType
case "hur" ' hurricane advisory
iSeverity = 4
case "tor" ' tornado warning
iSeverity = 5
case "tow" ' tornado watch
iSeverity = 4
case "wrn" ' thunderstorm warning
iSeverity = 3
case "sew" ' thunderstorm watch
iSeverity = 1
case "win" ' winter adv
iSeverity = 1
case "flo" ' flood warning
iSeverity = 2
case "wat" ' flood watch
iSeverity = 0
case "wnd" ' high wind advisory
iSeverity = 1
case "svr" ' severe weather statement
iSeverity = 0
case "hea" ' heat adv
iSeverity = 0
case "fog" ' fog
iSeverity = 0
case "spe" ' special weather statement
iSeverity = 0
case "fir" ' fire adv
iSeverity = 4
case "vol" ' volcanic activity
iSeverity = 5
case "hww" ' hurricane wind warning
iSeverity = 5
case "rec" ' record set
iSeverity = 0
case "rep" ' public reports
iSeverity = 0
case "pub" ' public information statement
iSeverity = 0
case else
bValid = false
end select
' if no valid identifier, then use keywords
if bValid = false then
' is there a potential warning
if instr(1,sAlertMessage,"warning",1) then
bWarning = true
elseif instr(1,sAlertMessage,"watch",1) then
bWatch = true
end if
if bWatch then
if instr(1,sAlertMessage,"tornado",1) then
iSeverity = 4
elseif instr(1,sAlertMessage,"hurricane",1) then
iSeverity = 4
elseif instr(1,sAlertMessage,"thunderstorm",1) then
iSeverity = 2
end if
elseif bWarning then
if instr(1,sAlertMessage,"tornado",1) then
iSeverity = 5
elseif instr(1,sAlertMessage,"hurricane",1) then
iSeverity = 5
elseif instr(1,sAlertMessage,"thunderstorm",1) then
iSeverity = 3
end if
end if
end if
gGetWeatherSeverity = iSeverity
end function
A few keywords are searched for if there is an invalid AlertType. This is probably not necessary, but I have seen a WU alert that was missing its AlertType once, so I put the keywords in for the more severe weather warnings just to be safe.
As a disclaimer do not use this as a weather alert radio. Premise will only grab alert updates every 15 minutes and 30 minutes is the default. This may not be enough of a warning for tornados!!!
You can modify sys://Schema/Modules/WeatherUnderground/Classes/Weather/OnChangeUpdateInterval and sys://Schema/Modules/WeatherUnderground/Classes/Weather/StartUpdateTimer to allow more frequent updates. I changed my system to get rid of the 15 minute limit and I am using 5 minutes.
StartUpdateTimer
'
if this.UpdateInterval > 1 then
system.addTimer this.UpdateInterval * 60, "this.Update = true", 1, "Weather_" & this.ObjectID
end if
OnChangeUpdateInterval
Code:
'
' Validate UpdateInterval
if sysevent.newVal > 0 and sysevent.newVal < 1 then
this.UpdateInterval = 30
else
if sysevent.newVal > 1 then
this.StartUpdateTimer()
else
this.RemoveUpdateTimer()
end if
end if