String / Number items Definition HTTP / JSON

I am trying to get alerts from wunderground (forecast and conditions are working well)
However, the rersponse looks different and I am struggling with two things:

  • getting the alerts in german language and
  • putting the result into items

http service looks like this:

http://api.wunderground.com/api/your_key/alerts/q/zmw:00000.1.16172.json

Alternatively I tried also without luck:

http://api.wunderground.com/api/your_key/alerts/lang:DL/units:metric/q/zmw:00000.1.16172.json

Response looks always (regardless of the used string) like this:

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "alerts": 1
  }
	}
		,"query_zone": "999",
	"alerts": [
		{
		"type": "HEA",
		"wtype_meteoalarm": "5",
		"wtype_meteoalarm_name": "Extreme high temperature",
		"level_meteoalarm": "2",
		"level_meteoalarm_name": "Yellow",
		"level_meteoalarm_description": "The weather is potentially dangerous. The weather phenomena that have been forecast are not unusual, but be attentive if you intend to practice activities exposed to meteorological risks. Keep informed about the expected meteorological conditions and do not take any avoidable risk.",
		"description": "Potential disruption due to extreme high temperatures from 12PM CEST THU until 4:30PM CEST THU",
		"date": "2017-06-22 01:00:00 GMT",
		"date_epoch": "NA",
		"expires": "2017-06-22 14:30:00 GMT",
		"expires_epoch": "NA",
		"message": "Potential disruption due to extreme high temperatures from 12PM CEST THU until 4:30PM CEST THU)",
		"phenomena": "NA",
		"significance": "NA",
		"attribution": "Information provided by , <a href='http://meteoalarm.eu/'>EUMETNET - MeteoAlarm</a> Note: Time delays between this website and <a href='http://meteoalarm.eu/'>Meteoalarm.eu</a> are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit <a href='http://meteoalarm.eu/'>Meteoalarm</a>. For terms of use of this information, and copyright information, see <a href='http://meteoalarm.eu/'>Meteoalarm</a> Terms of Use."
		}
	]
}

What I am trying to read is for instance the type, the level or the message (if possible in German :slight_smile: ) so I set up items like:

String vWeather_Type "Unwetterart [MAP(wu_alarms_code.map):%s]"    <typ> (gWeatherH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts.alert.type)]" }

Number vWeather_Meteoalarm "Alarmcode [MAP(wu_alarms_code.map):%s]"  <alarmcode> (gWeatherH)    { http="<[weatherAlerts:420000:JSONPATH($.alert.wtype_meteoalarm)]" }

However, I am failing with the correct items definition, Using the examples above is forcing the server to hang :frowning:
If I take a look at the response I see the -->[ <-- sign which can imho not be parsed correctly wihtin my item definition.

"alerts": [

Someone can give me a hint?

I can’t answer the language problems. But the [ indicates an array in JSON. So, to access type your JSONPATH would be $.alerts[0].type. It is an array because it is possible (and common in my area) to have more than one alert at a time.

1 Like

That did the trick, thank you for clarifying and pointing me into the right direction.
Changed it and values now visible.

Marcus, I didnt know this aspect of Weatherunderground, so ofcourse I had to try myself;
http.cfg

weatherAlerts.url=http://api.wunderground.com/api/e5cxxxxxxxx/alerts/q/zmw:00000.1.16172.json

channels in my items file

{ http="<[weatherAlerts:420000:JSONPATH($.alerts[0].type)]" }
{ http="<[weatherAlerts:420000:JSONPATH($.alert[0].wtype_meteoalarm)]" }

That works for “Unwetterart” or at least I get the message “WRN” there, but does not work for "Alarmcode
Also tried

{ http="<[weatherAlerts:420000:JSONPATH($.alerts[0].wtype_meteoalarm)]" }

but no luck

I wonder if you could help me with the following:

  • How exactly do yr items look like after Rich’s help
  • Would you mind sharing your wu_alarms_code map file (I read german if necessary)? (though I think I may have most of the USA warnings but not the codes)

Thanks a bundle

Sure, here we go. Please note the following config is not finished yet, will continue next week again after vacation.
Items:

String vAlertWeather_Type1 			"Unwetterart [MAP(wu_alarms_code.map):%s]"  <weatherwarnung>		(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].type)]" }
//Number vAlertWeather_Meteoalarm1 	"Warnart [%s]"								<temperature>	(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].wtype_meteoalarm)]" }
String vAlertWeather_Meteoalarm_Name1"Warnung [MAP(wu_alarms_code.map):%s]"		<weather>		(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].wtype_meteoalarm_name)]" }
//Number vAlertWeather_Level1 			"Warnlevel [%s]"							<level>			(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].level_meteoalarm)]" }
String vAlertWeather_Level_Name1 	"Warnstufe [MAP(wu_alarms_code.map):%s]"	<farbe>			(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].level_meteoalarm_name)]" }
DateTime vAlertWeather_date_begin1   "Gültig ab [%1$tY-%1$td-%1$tm %1$tH:%1$tM:%1$tS]"  <clock>    (gUnwetterH)      { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].description.date)]" }
DateTime vAlertWeather_date_end1   	"Gültig bis [%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS]"  <clock>    (gUnwetterH)     { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].description.expires)]" }
Switch	vAlertWeather_switch		(gUnwetterH)
String 	vAlertWeather_NewAlertMsg 	"Neue Warnung [%s]" <neu> (gUnwetterH)
String 	vAlertWeather_OldAlertMsg 	"Alte Warnung [%s]" <alt> (gUnwetterH)
//String vAlertWeather_Level_Desc1 	"Beschreibung [%s]"  										(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].level_meteoalarm_description)]" }
//String vAlertWeather_Level_Message1 	"Nachricht [%s]"											(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[0].message)]" }
String vAlertWeather_Type2 			"Unwetterart [MAP(wu_alarms_code.map):%s]"  <weatherwarnung>		(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].type)]" }
//Number vAlertWeather_Meteoalarm2 	"Warnart [%s]"								<temperature>	(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].wtype_meteoalarm)]" }
String vAlertWeather_Meteoalarm_Name2"Warnung [MAP(wu_alarms_code.map):%s]"		<weather>		(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].wtype_meteoalarm_name)]" }
//Number vAlertWeather_Level1 			"Warnlevel [%s]"							<level>			(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].level_meteoalarm)]" }
String vAlertWeather_Level_Name2 	"Warnstufe [MAP(wu_alarms_code.map):%s]"	<farbe>			(gUnwetterH)    { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].level_meteoalarm_name)]" }
DateTime vAlertWeather_date_begin2   "Gültig ab [%1$tY-%1$td-%1$tm %1$tH:%1$tM:%1$tS]"  <clock>    (gUnwetterH)      { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].description.date)]" }
DateTime vAlertWeather_date_end2   	"Gültig bis [%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS]"  <clock>    (gUnwetterH)     { http="<[weatherAlerts:420000:JSONPATH($.alerts[1].description.expires)]" }

Please note: Alerts may occur multiple times, that’s why I (more or less) doubled the entries.
Date is not working yet, working on that after vacation.
wu_alarms_code.map:

HUR=Hurricane Local Statement
TOR=Tornado Warning
TOW=Tornado Watch
WRN=Severe Thunderstorm Warning
SEW=Severe Thunderstorm Watch
WIN=Winter Weather Advisory
FLO=Flood Warning
WAT=Flood Watch / Statement
WND=High Wind Advisory
SVR=Severe Weather Statement
HEA=Hitzewarnung
FOG=Nebelwarnung
SPE=Special Weather Statement
FIR=Waldbrandwarnung
VOL=Volcanic Activity Statement
HWW=Hurricane Wind Warning
REC=Record Set
REP=Public Reports
PUB=Public Information Statement
Darkgreen=Dunkelgrün
Green=Grün
Yellow=Gelb
Orange=Orange
Red=Rot
Violett=Violett
blowing snow=Schneesturm
blustery=Stürmisch
clear=Klar
chance\ of\ rain=Regen
chance\ of\ snow=Schneefall
cloudy=Bewölkt
cold=Kalt
drizzle=Nieseln
dust=Dunst
Extreme\ high\ temperature=extreme Hitze
fair=schön
fog=Nebel
freezing\ drizzle=Gefrierender Regen
freezing\ rain=Gefrierender Regen
hail=Hagel
haze=Dunst
heavy\ snow=Starke Schneeschauer
hot=Heiß
hurricane=Hurrican
isolated\ thundershowers=Gewitterschauer
isolated\ thunderstorms=Gewitter
light\ rain=Leichter Regen 
light\ rain showers=Leichte Regenschauer 
light\ snow=Leichter Schneefall
light\ snow showers=Leichte Schneeschauer
mist=Leichter Nebel
mixed\ rain\ and\ hail=Regen Hagelmix
mixed\ rain\ and\ sleet=Regen Graupel
mixed\ rain\ and\ snow=Regen Schnee
mixed\ snow\ and\ sleet=Schneegraupel
mostly\ cloudy=überwiegend bewölkt
mostly\ sunny=überwiegend sonnig
overcast=Bedeckt
partly\ cloudy=Teils bewölkt
partly\ sunny=Teils sonnig
patches\ of\ fog=Nebelfelder
rain=Regen
rain\ and\ snow=Regen und Schnee
scattered\ clouds=Vereinzelte Wolken
scattered\ showers=Vereinzelte Schauer
scattered\ snow\ showers=Vereinzelte Schneeschauer
scattered\ thunderstorms=Vereinzelte Gewitter
shallow\ fog=Bodennebel
severe\ thunderstorms=Schweres Gewitter
showers=Schauer
sleet=Graupel
smoky=Rauchig
snow flurries=Schneetreiben
snow showers=Schneeschauer
snow=Schnee
sunny=Sonnig
thundershowers=Gewitterregen
thunderstorms=Gewitter
tornado=Tornado
tropical storm=Tropischer Sturm
windy=Windig

wu_alarms_level.map:

not finished yet

Marcus, I apologize, I never noticed your reply. As in the mean time i had bigger problems with the binding, I now completely went over to parsing the JSON myself, so definitely have use for yr alarmcode. Thank you

Hi

I stopped the work on the binding as well, but I am still interested in a solution.
If you don’t mind please share me your files and let me know how you solved it, I would appreciate it.

Thanks for your effort

Marcus

I used Rich’ set-up that he published here, worked right away