Template Example: Weather Binding

Tags: #<Tag:0x00007f1826a24190>

(E. Gerland) #145

Oh, that’s great!
Thanks Thomas.
It’s not available in PaperUI as a channel though.

Is this true for forecast as well - like:

I will give it a try.

(Peter Dahinden) #146

Yes, it is available:

Open the Local Weather binding in PaperUI and click on the Show More link on the upper right half of the page.

(E. Gerland) #147

Damn it!
You’re right.

Now I remember that I have used “Show more” many months ago, but somehow forgot about it.
Thanks a lot for the reminder.
Have a great Christmas Season. :slight_smile:

(E. Gerland) #148

I have read all posts here, but die not find a solution for my use case:
Wunderground 2.0 (included in OH 2.2)
German localization.

As you mentioned the image files do not match, which is my problem.
I would like to use these icons:

ConditionID (not provided by Wunderground!?)
Renaming manually - this is the actual issue.

Currently the weather forcast today here is chancerain which is Regen möglich.
I tried:
regen möglich.svg

bedeckt.svg (cloudy) works.

So the main issue are the Umlaute (special characters in German)

My widget code:
<img src="{{ServerPath}}/{{IconSet}}/{{itemValue('Weather_Forecast_0').split(' ').join('-') | lowercase }}.svg"/>

Another Option I could think of (but don’t know how to realize it) would be a transform in the widget code (translate the german condition back into englisch in the background).
<img src="{{ServerPath}}/{{IconSet}}/{{MAP(weather.map):%sitemValue('Weather_Forecast_0').split(' ').join('-') | lowercase }}.svg"/>

(E. Gerland) #149

Why is the current condition translated (Regen) into German, but not the weekdays?

Even with this adjustment, I still get Monday, Tuesday etc.
<div ng-init="ServerPath=''; IconSet='white'; daysnames={'Sunday': 'So', 'Monday': 'Mo', 'Tuesday': 'Di', 'Wednesday': 'Mi', 'Thursday': 'Do', 'Friday': 'Fr', 'Saturday': 'Sa'}">

(Thomas Binder) #150

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”.?

(E. Gerland) #151

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

(Thomas Binder) #152

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)

(E. Gerland) #153

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:

(E. Gerland) #154

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.

(Thomas Binder) #155

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:

(E. Gerland) #156

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:

(Thomas Binder) #157

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

(Jürgen Baginski) #158

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

(E. Gerland) #159

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

(Jürgen Baginski) #160

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>

(E. Gerland) #161

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

(Andy Wolff) #162

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…

(E. Gerland) #163

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

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

(Veagau) #164

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