Wunderground meteoalarm

Hi folks,

first of all, thanks for the Weather Binding, this is definitely great. I’ve just switched 80% of HTTP Binding configuration to this Binding, and the system is overall working better.

Just a missing bit. Wunderground is providing also the alerts from meteoalarm, and this is great to receive information in case of issues with weather.

What about configuring also this part in our Weather Binding?

here the API reference:
http://www.wunderground.com/weather/api/d/docs?d=data/alerts&MR=1

At the moment I’m working with HTTP+XSLT, with a couple of transform as follow:

wu_weather_alerts_level.xsl

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>

<xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />

<xsl:template match="/">
	<xsl:for-each select="//response/alerts/alert">
		<xsl:value-of select="level_meteoalarm"/>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

wu_weather_alerts_type.xsl

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>

<xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />

<xsl:template match="/">
	<xsl:for-each select="//response/alerts/alert">
		<xsl:value-of select="wtype_meteoalarm"/>
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

But I didn’t solve yet how to manage multiple alerts with an array …
Any advice will be appreciated.

Good to raise an issue on the github?

Thank you

Andrea

I haven’t tried it, but could you use something like this “join” XSL transform in order to populate a String item with all values in the array?

<?xml version="1.0"?>
<xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
<xsl:template match="/response/alerts/alert">
        <xsl:call-template name="join">
                <xsl:with-param name="valueList" select="level_meteoalarm"/>
                <xsl:with-param name="separator" select="','"/>
        </xsl:call-template>
</xsl:template>

<xsl:template name="join">
        <xsl:param name="valueList" select="''"/>
        <xsl:param name="separator" select="','"/>
        <xsl:for-each select="$valueList">
                <xsl:choose>
                        <xsl:when test="position() = 1">
                                <xsl:value-of select="."/>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:value-of select="concat($separator, .) "/>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:for-each>
</xsl:template>

I don’t know if I’m understanding correctly.

The situation here is how the data are receiving from wunderground.
example:

2 is Snow/Ice
3 is Thunderstorms
the usual alarms are 12 in total

but when you have two alarms eg. for Snow and Thunder at the same time, the number you receive is 23

I’m using a workaround on my map file, adding all new combinations I’m receiving (eg. 23).

The same also when you manage the level of the alarms:

the usual levels are 4 in total
but for two events at level 3 each you receive 33.

never received two alarms with different level, but can happen (eg. 32)

How to manage that?

Andrea

Me either: :smile:

Are you saying that the numeric values are being concatenated together, so a “2” and a “3” comes back as “23”? You wouldn’t want that! So I would ask which bits in the returned XML you want to populate into items? Do you have an example XML string returned from the API and what you want isolated from it into one or more item states? As you may know, there is no built-in array handling in openHAB, as item types can only be strings, numbers, switches, contacts, percents, etc.

Yes exactly I2 and 3 comes back as 23.

check now:

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

there are 2 alerts for Munich. How to manage it?

cut/paste the json:

{
“response”: {
“version”:“0.1”,
“termsofService”:“http://www.wunderground.com/weather/api/d/terms.html”,
“features”: {
“alerts”: 1
}
}
,“query_zone”: “999”,
“alerts”: [
{
“type”: “FOG”,
“wtype_meteoalarm”: “4”,
“wtype_meteoalarm_name”: “Fog”,
“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”: “\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt verbreitet Nebel mit Sichtweiten unter 150 Metern auf.”,
“date”: “2015-12-27 14:00:00 GMT”,
“date_epoch”: “NA”,
“expires”: “2015-12-28 09:00:00 GMT”,
“expires_epoch”: “NA”,
“message”: “\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt verbreitet Nebel mit Sichtweiten unter 150 Metern auf.)”,
“phenomena”: “NA”,
“significance”: “NA”,
“attribution”: “Information provided by , EUMETNET - MeteoAlarm Note: Time delays between this website and Meteoalarm.eu are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit Meteoalarm. For terms of use of this information, and copyright information, see Meteoalarm Terms of Use.”
}
,
{
“type”: “WIN”,
“wtype_meteoalarm”: “6”,
“wtype_meteoalarm_name”: “Extreme low 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”: “\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt leichter Frost bis -2 °C auf.”,
“date”: “2015-12-27 17:00:00 GMT”,
“date_epoch”: “NA”,
“expires”: “2015-12-28 09:00:00 GMT”,
“expires_epoch”: “NA”,
“message”: “\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt leichter Frost bis -2 °C auf.)”,
“phenomena”: “NA”,
“significance”: “NA”,
“attribution”: “Information provided by , EUMETNET - MeteoAlarm Note: Time delays between this website and Meteoalarm.eu are possible. For the most up-to-date information about alert levels as published by the participating National Meteorological Services, please visit Meteoalarm. For terms of use of this information, and copyright information, see Meteoalarm Terms of Use.”
}
]
}

If you want to use the JSON response instead of the XML response, you can easily traverse it with a small JavaScript transform.
your.items

String WeatherAlerts "Alerts [%s]" { http="<[meteoalarm:3600000:JS(meteoalarm.js)]" }

/etc/openhab/configurations/transform/meteoalarm.js:

(function(json) {
  var response = JSON.parse(json);
  var arr = new Array(response.alerts.length);
  for (var i = 0; i < response.alerts.length; i++) {
    arr[i] = response.alerts[i].type;
  }
  return arr.join(", ");
})(input)

(Side note: If you put the quote between a line ```json and a line ```, it gets formatting.)

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "alerts": 1
  }
	}
		,"query_zone": "999",
	"alerts": [
		{
		"type": "FOG",
		"wtype_meteoalarm": "4",
		"wtype_meteoalarm_name": "Fog",
		"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": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt verbreitet Nebel mit Sichtweiten unter 150 Metern auf.",
		"date": "2015-12-27 14:00:00 GMT",
		"date_epoch": "NA",
		"expires": "2015-12-28 09:00:00 GMT",
		"expires_epoch": "NA",
		"message": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt verbreitet Nebel mit Sichtweiten unter 150 Metern auf.)",
		"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."
		}
		,
		{
		"type": "WIN",
		"wtype_meteoalarm": "6",
		"wtype_meteoalarm_name": "Extreme low 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": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt leichter Frost bis -2 °C auf.",
		"date": "2015-12-27 17:00:00 GMT",
		"date_epoch": "NA",
		"expires": "2015-12-28 09:00:00 GMT",
		"expires_epoch": "NA",
		"message": "\u0009\u0009\u0009\u0009\u0009\u0009\u0009\u0009deutsch: Es tritt leichter Frost bis -2 °C auf.)",
		"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."
		}
	]
}

Thanks for the suggestion.

No way to have one String for first alarm (with a Number specifying the level of that alarm) for each alert?

I am having trouble clearly picturing what you would like your items to be. If you could provide a desired fragment of your desired items file, I can offer suggestions of what would go in the { curly braces } for each item to propagate their states.

Hi watou

first of all, thanks for your effort here :slight_smile: much appreciated.

My config at the moment is:

/*Wunderground Meteoalarm */

Number WuAlarmsCode “meteoalarm [MAP(wu_alarms_code.map):%s]” (Weather, Outdoor) { http="<[WuAlertsCache:10000:XSLT(wu_weather_alerts_type.xsl)]" }
Number WuAlarmsLev “level [%d]”

wu_alarms_code does the match between wtype_meteoalarm and the description (eg. 4 is Fog)

WuAlarmsLev is matching level_meteoalarm … I use this to define the color of the label for WuAlarmsCode:

Text item=WuAlarmsCode icon=“meteoalarm” visibility=[WuAlarmsLev>=2] valuecolor=[WuAlarmsLev==0=“gray”,WuAlarmsLev==1=“green”,WuAlarmsLev==2=“orange”,WuAlarmsLev==3=“red”,WuAlarmsLev==4=“purple”,WuAlarmsLev==33=“red”,WuAlarmsLev==22=“orange”]

As you can see, now I’ve added 33 and 22, because sometimes I’ve received 2 warnings with the same level. But it should be difficult in case of different level, so I’m trying to find a solution to have 2 different WuAlarmsCode in case of 2 warnings, 3 in case of 3 warnings, and so on.

I hope this is clear enough :smile:
thanks

Andrea

@ariela
Looking into your post I wonder if you want to share the necessary files with me?

what do you need exactly?

Andrea