Template Example: Weather Binding

Could you please post your config for weatherunderground? (Things and Items) I’m thinking there’s something mixed.

for German Translation you have to:

  • Change it in weatherunterground Profile
  • use “DL” instead of “DE” in the config

the WU-API returns the JSON like this:

		"txt_forecast": {
		"date":"13:39 CET",
		"forecastday": [
		"fcttext":"Meistens klar. Höchsttemperatur 36F. Wind aus S und wechselhaft.",
		"fcttext_metric":"Meistens klar. Höchsttemperatur 4C. Wind aus S und wechselhaft.",

as I see it, the “icon”-Attribute is of course english (as should the filenames), and the texts are translated. I don’t use the WU-binding at the moment, but I can imagine, you using some kind of Transformation for you icon-item? and perhaps the language given in the API isn’t “DL”.?

Good Morning Thomas and Merry Christmas!

With WU Profile you mean the Thing settings in Paper UI? I have set it to “German” from the dropdown menu.

I am currently using the WU binding in OH 2.2, which does not require an additional config.
(previously I used the weather binding with weather.cfg - back than I had set DL - but with OH2 the file is obsolete - right?

My thing in PaperUI:

My items look for instance like this (no transform):

// Current Weather
String 		Weather_Current         "Wetter [%s]"	            <weather>		(G_jdbc)		{channel="weatherunderground:weather:local:current#conditions"}
Image       Weather_Curr_Icon       "Wetter Icon"                               (G_jdbc)		{channel="weatherunderground:weather:local:current#icon"}
DateTime    Weather_ObsTime         "Zeitpunkt [%s]"                            (G_jdbc)        {channel="weatherunderground:weather:local:current#observationTime"}
Number      Weather_Temperature     "Temperatur [%.1f °C]"      <temperature>   (G_Numbers)		{channel="weatherunderground:weather:local:current#temperature"}
Number      Weather_Temp_Feel       "Gef. Temperatur [%.1f °C]" <temperature>   (G_Numbers)		{channel="weatherunderground:weather:local:current#feelingTemperature"}
Number		Weather_Prec_Amnt_1h    "Regenmenge 1h [%.0f mm]"   <rain>			(G_Numbers)		{channel="weatherunderground:weather:local:current#precipitationHour"}
Number		Weather_Prec_Amnt_24h   "Regenmenge 24h [%.0f mm]"  <rain>			(G_Numbers)		{channel="weatherunderground:weather:local:current#precipitationDay"}
Number      Weather_Humidity        "Luftfeuchte [%d %%]"       <humidity>	   	(G_Numbers)		{channel="weatherunderground:weather:local:current#relativeHumidity"}
Number      Weather_Pressure        "Luftdruck [%.0f mb]"       <pressure>		(G_Numbers)		{channel="weatherunderground:weather:local:current#pressure"}
Number		Weather_Wind_Speed      "Wind [%.1f km/h]"          <line>			(G_Numbers)		{channel="weatherunderground:weather:local:current#windSpeed" }
String		Weather_Wind_Dir        "Wind Dir [%s]"             <line>			(G_jdbc)		{channel="weatherunderground:weather:local:current#windDirection" }

Can I check the WU-API response with my current settings somewhere?

I guess the “icon” channel in the WU 2.0 binding is the url - so how to get the bare name of the icon (“icon”:“clear”) in your response above.
This would enable me to use this in the template to link to the proper local file.

Thanks for your help

Hi there,

at first, I’m sorry, I tend to forget about configuring OH2 with PaperUI (I solely use files… :wink: #oldfashioned).
So let’s do this:
Weather Underground delivers an API with a pretty good JSON response. The WeatherUnderground binding takes the JSON, makes some channels and throws is back in for using.
I don’t use the binding (I’ll tell you, what I do later on), so I don’t know exactly, whether all JSON-Attributes are taken 1:1 as channels (but my bet is it should do).

  1. at first you can define in your WU-Profile (Member Settings - Page Preferences) your units (metric) and language (german)
  2. if you configure “German” in PaperUI I guess it already sets the right Country Code (http://api.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1)
  3. I don’t know, what else the WU-Binding has as channel, but if current#icon has the whole URL to the icon, you can either strip the sole icon name. i would have expected current:icon and current:icon_url as channels.
  4. you can now make your items with the use of the WU-channels

So, you asked on how you can see the JSON-response. that’s pretty straightforward. As you already know your API-key, just klick on this (of Course using your credentials :wink: ):

  "response": {
  "features": {
  "conditions": 1
  "forecast": 1
  ,	"current_observation": {

As you can also see, there are a lot more attributes here like “precip_today_in” and “precip_today_metric” - so, the binding makes it easier for you to use those in your units.
And that’s basically, what I do: taking the JSON and parsing it for my wanted items.

My experience is, with the configuration in the WU-Profile to metric and german plus the “DL” argument in the API-URL you get metric units in texts ("fcttext_metric":"Teilweise bedeckt. Tiefsttemperatur 3C. Wind aus SSW mit 15 bis 25 km/h."). The Binding can only use the “DL” argument, so it could be, that there’s only imperial units in german texts. AFAIR that was what I got before changing the values in the profile.

next thing you need to know using weather-underground: take a closer look to the JSON, you will see, that you get a bunch of information with $current_observation, that’s the current#... channels in the binding. Then you get two periods for today in the forecast, which represent day and night for today, thats forecastToday:... channels. I don’t know, where the night-attributes go… but then you get the rest like forecastTomorrow forecastDay2 … forecastDay9 - again, I don’t know where the night-attributes of the next days go (they’re present in the JSON):

		"fcttext":"Teilweise bedeckt. Höchsttemperatur 50F. Wind aus SW mit 15 bis 25 mph.",
		"fcttext_metric":"Teilweise bedeckt. Höchsttemperatur 10C. Wind aus SW mit 25 bis 40 km/h.",
		"title":"Dienstag Nacht",
		"fcttext":"Meistens klar. Tiefsttemperatur 35F. Wind aus SSW mit 10 bis 20 mph.",
		"fcttext_metric":"Meistens klar. Tiefsttemperatur 2C. Wind aus SSW mit 15 bis 30 km/h.",

So, I hope, that clears it - have fun! :wink: and merry christmas (watching my son playing around with the PS4 and Star Wars Battlefront II)

Thanks, Thomas for this outstanding support.
I will check out your suggestions for my use case.

By the way - I just recognized, that the icon channel just returns the image itself (image item).
So I guess my first try is to extract the name of the icon from the JSON response and generate the link to my local file.

Battlefront II - nice.
My sons are still too young for it though :wink:
But it might be a good reason to buy the (someday upcoming) PS5 :smiley:

That was really helpful, Thomas.
Again, thanks for your help.

It took a while, but I figured it out to generate the right icon names out of the json response:

For others, who might struggle with the icon stuff and the German language as well:
API request:

The first icon name you get by JSONPATH like

val String current_tmp = transform("JSONPATH", "$.current_observation.icon", json)

the others by:

val String icon_0_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[0]icon", json)
val String icon_1_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[2]icon", json)

(forcastday.[1]icon would be the night between day 0 and 2)

I just create the icon name to the local file by:
(whereas my Icon_Path is

In my weather widget I refer to the icon files by:
<img src="{{itemState('Weather_Icon_0')}}"/>

Hope it helps others.

Hey, that’s great!
But, I would think, there’s already an Icon-channel in the wu-binding?
if not - or just for the sake of learning, here’s a bit more insight in how to organize Data from weather-APIs:

Yes, there is an icon channel, but it’s not the right way for me.
The reason is, that the icon channel returns a hardcoded image (the image itself).
And because I don’t like its look, I have chosen to go with my local ones (svg from here: https://peter.build/weather-underground-icons/)

So I just extract the english name of the weather condition (file) and create a link to the local file.
The only thing I did not solve yet is the english Mon, Tue, …
Maybe I will solve it through the API directly as well… :slight_smile:

that looks nice! If there’s no channel for the item name, then that would be the way to go - but then you can easily get all your weather items by the API… or you could file a issue on github to add an simple icon name

I’ve had that problem on a “normal” sitemap and it was causesd by the OS which hadn’t been set to my language.

Thanks for this idea.
I actually checked that already (running openhabian 1.4 with OH 2.2 on a Raspi 3).

On habpanel, I use:

<div ng-init="daysnames={'Sunday': 'Sonntag', 'Monday': 'Montag', 'Tuesday': 'Dienstag', 'Wednesday': 'Mittwoch', 'Thursday': 'Donnerstag', 'Friday': 'Freitag', 'Saturday': 'Samstag'}">
		<td>{{daysnames[(itemValue('ObservationTime1') | date:'EEEE')]}}</td>
		<td>{{daysnames[(itemValue('ObservationTime2') | date:'EEEE')]}}</td>

That’s it!
Thanks a lot, Jürgen. :slight_smile:

Hi, sorry @NCO i was not online in the last days, but @opus has written the answer…

@NCO: How can i save the icons as svg from https://peter.build/weather-underground-icons/ to my icons folder? Update: I have found the svg on Github…

Don’t worry - Christmas is for spendingtime worhthe family and friends :slight_smile:

So you found the icons? Great. I really like them.

Which weather data provider do you choose? ForecastIo or Openweathermap?

i would like to use these items as well (white flat).
how do you extract the english name of the weather condition? is there a distinction between night/day?
i tried with “condition” (wunderground), but there’s only “Mostly Cloudy” - and now i’m seeing a sun icon in the middle of the night/evening…


Hi @narf27,

I just extract it using a API request to wunderground directly.
All information can be found in ma post above (post 150).

hmm… most probably i just don’t get the JSON thing.
i don’t even get WHAT should be transformed…
i have an (JSON) url and then there’s items. but i don’t see where there’s a connection between url and items…

Alright, let’s see…

I have some items:


Which are set by my rule. You just need to set your wunderground API Key and the location for the weather forecast.
I guess with this it should be manageable :wink:

rule "Retrieve weather icon names"
 	Time cron "10 0/30 * * * ?" or //every 30 Minutes at Second 10
	Item Weather_Current changed or
	Item Weather_Nighttime changed
	val String json = executeCommandLine("curl -s http://api.wunderground.com/api/YOUR_API_KEY_HERE/conditions/forecast10day/lang:DL/q/Germany/YOUR_PREFERRED_LOCATION_HERE.json", 5000)
	var String current_tmp = ""
	var String icon_0_tmp = ""
	var String icon_1_tmp = ""
	var String icon_2_tmp = ""
	var String icon_3_tmp = ""
	var String icon_4_tmp = ""
	var String icon_5_tmp = ""
	var String icon_6_tmp = ""
//	check day or night to choose the right icons for now and forecast 0
	if(Weather_Nighttime.state == ON) {
		icon_0_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[1]icon", json)
		logInfo("weather.rules", "Weather Icon_0 updated (Night).")
	if(Weather_Nighttime.state == OFF) {
		icon_0_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[0]icon", json)
		logInfo("weather.rules", "Weather Icon_0 updated (Day).")
	current_tmp = transform("JSONPATH", "$.current_observation.icon", json)
	// Forecast icon 0 is checked for day / night mode (see above)
	icon_1_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[2]icon", json)
	icon_2_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[4]icon", json)
	icon_3_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[6]icon", json)
	icon_4_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[8]icon", json)
	icon_5_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[10]icon", json)
	icon_6_tmp = transform("JSONPATH", "$.forecast.txt_forecast.forecastday.[12]icon", json)

//	sendTelegram("weather.rules", "Weather_Curr_Icon updated: " + Weather_Curr_Icon.state.toString)

I just finished putting together a Widget. This is my first try but it works for me. The text will automatically adjust to fill the space which hopefully will spark that addition the all the widgets. Unzip and drop the files into your html folder. I use this with the WeatherUnderground binding in Openhab 2.2. When you edit the widget you will see the names of my items that are the default. Thank to everyone’s code to help put this together.

html.7z.xml (160.9 KB)

1 Like