Weather binding

The example supplied with the SD card uses the Weather Underground free services to get weather forecasts and the related binding to link them with OpenHAB.

Note! This example uses a Weather Underground demo API key that can stop working at any moment. Please get and install your own API key to have a stable service.

Create a free account on Weather underground, get an API key and past it to the binding configuration page together with your coordinates.

That’s all, when the binding status becomes  ONLINE  the things are published and they can be linked to OH2 items in items/weather.items. To change the language, displayed items and so on, edit this file and sitemaps/cm3home.sitemap.

A more complete information panel is designed in the example supplied using also the informations coming from Astro binding.

This binding too requires the editing of the configuration inserting your coordinates.

to customize the items names, edit the items/astro.items file.


Weather binding configuration example

Read carefully the official Weather Binding documentation.

This is an OpenHAB 1 binding, it works but requires some workarounds.

With OpenWeatherMap service the forecasts do not work anymore.

On OpenWeatherMap web site they declare that with the free plan there are also the 5 days forecasts but after the registration they are set to 0.

Reading on forum you can discover that the forecasts (day by day selectable) are only the 16 days one. Switching from beta to final version the 1 day forecast is no more included in free plan.

The OpenHAB binding still uses the old APIs that are no more included.

5gg{city ID}

16gg{city name},{country code}&cnt={cnt}

It’s no more possible to specify a single day but only the full 5-day period.

After some tests with OpenWeatherMap service I switched to Wundergound service. It’s easy. After creating a new account on another service provider you can find/change the new name on all items configured or comment the old one and use the same name on the new configuration without changing anything else.

In services/weather.cfg


Using the HTML panel example on the Weather Binding documentation requires some tricks, learned on the OpenHAB community, because in OH2 the folder used to publish web pages changed from the one of OH1.

The weather-data example explained on the example must be moved on /etc/openhab2/html (the old html content folder) and a symbolic link must be created in /var/lib/openhab2/webapps (the new path):

cd /var/lib/openhab2/webapps/
ln -s /etc/openhab2/html/weather-data/ weather-data

Some icons contained in images must be copied:

sunny.png -> clear.png
mostly-cloudy-day.png -> mostly-cloudy.png
partly-cloudy-day.png -> partly-cloudy.png

in order to be compatible with all the weather services that also provide the icon names in forecast. Some services supplies a link to their own icons instead.

To modify the log level by hand you can edit the file:


To show in a single string two values, for example wind speed and direction, a rule is needed:

in weather.items

Number	Wind_Speed	" [%.2f km/h]"		(Weather)	{weather="locationId=roma, type=wind, property=speed"}
String	Wind_Direction	" [%s]"			(Weather)	{weather="locationId=roma, type=wind, property=direction"}
String	Wind	"Vento [%s]"	

A new Wind item has been created with no references. It’s used to concat the two strings in a single one:

rule "concat"
  Item Wind_Speed received update or
  Item Wind_Direction received update
  Wind.postUpdate(Wind_Speed.state.toString + " km/h  " + Wind_Direction.state.toString)

In sitemap

Text item=Wind

Recently a new, OH2.2 compatible WeatherUnderground Binding is available. It uses the new things system and is easier to config.

Instead of using the text file editing example shown in the documentation, it’s much better to leave the paper UI creating the things and use those to declare the items

ONLY when the service is  ONLINE  you can use the things, linking them to your items. The service is  ONLINE  when configured with the correct API WeatherUnderground key

After linking the channels to the item as explained on the binding documentation:

String	 Station			"Stazione [%s]"									&lthome&gt			(Weather)	{channel="weatherunderground:weather:Roma:current#location"}
Number   Temperature   		"Temperatura Esterna [%.1f °C]" 				&lttemperature&gt 	(Weather)	{channel="weatherunderground:weather:Roma:current#temperature"}
Number   Temp_Min      		"Temperatura min [%.1f °C]" 					&lttemperature&gt 	(Weather)	{channel="weatherunderground:weather:Roma:current#minTemperature"}
Number   Temp_Max      		"Temperatura max [%.1f °C]" 					&lttemperature&gt 	(Weather)  	{channel="weatherunderground:weather:Roma:current#maxTemperature"}

Number   Temp_Feel     		"Temperatura Percepita [%.1f °C]"  				&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:current#feelingTemperature"}
Number   Temp_Dewpoint  	"Punto di rugiada [%.1f °C]"        			&ltwater&gt 		(Weather)	{channel="weatherunderground:weather:Roma:current#dewPoint"}

Number   Humidity   		"Umidità [%d %%]"       						&lthumidity&gt 		(Weather) 	{channel="weatherunderground:weather:Roma:current#relativeHumidity"}
Number   Pressure      		"Pressione [%d mBar]"    						&ltpressure&gt 		(Weather) 	{channel="weatherunderground:weather:Roma:current#pressure"}
Number   Visibility    		"Visibilità [%.2f km]" 							&ltzoom&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:current#visibility"}
Number   UV_Index       	"Indice UV"             						&ltsun&gt			(Weather) 	{channel="weatherunderground:weather:Roma:current#UVIndex"}
Number   SolarRadiation   	"Irradiazione [%.1f W/m2]"             			&ltsun&gt			(Weather) 	{channel="weatherunderground:weather:Roma:current#solarRadiation"}

String   Condition      	"Condizioni [%s]"   							&ltsun_clouds&gt 	(Weather)   {channel="weatherunderground:weather:Roma:current#conditions"}
String   Condition_ID   	"Condition id [%s]" 							&ltsun_clouds&gt 	(Weather)  	{channel="weatherunderground:weather:Roma:current#conditions"}
DateTime ObservationTime 	"Obs [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"   		&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:current#observationTime"}
Number   Rain          		"Pioggia [%.2f mm/h]"   						&ltrain&gt 			(Weather)	{channel="weatherunderground:weather:Roma:current#precipitationHour"}
Number   Precip_Probability "Precip % [%d %%]"  							&ltrain&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastToday#probaPrecipitation"}
Number   Precip_Total    	"Precip totali [%d mm]"   						&ltrain&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastToday#precipitationDay"}
Number   Wind_Speed      	"Velocità del vento [%.2f km/h]" 				&ltwind&gt 			(Weather)   {channel="weatherunderground:weather:Roma:current#windSpeed"}
String	 Wind_Direction  	"Direzione del vento [%s]"     					&ltwind&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:current#windDirection"}
String   Wind				"Vento [%s]"									&ltwind&gt
Image    Weather_Icon       		               											(Weather)  	{channel="weatherunderground:weather:Roma:current#icon"}

DateTime ObservationTime0 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastToday#forecastTime"}
Number   Temp_Min0      	"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastToday#minTemperature"}
Number   Temp_Max0      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastToday#maxTemperature"}
String   Condition0     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastToday#conditions"}
String   Condition_ID0  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastToday#conditions"}

DateTime ObservationTime1 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastTomorrow#forecastTime"}
Number   Temp_Min1			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastTomorrow#minTemperature"}
Number   Temp_Max1      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastTomorrow#maxTemperature"}
String   Condition1     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastTomorrow#conditions"}
String   Condition_ID1  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastTomorrow#conditions"}

DateTime ObservationTime2 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay2#forecastTime"}
Number   Temp_Min2			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay2#minTemperature"}
Number   Temp_Max2      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay2#maxTemperature"}
String   Condition2     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay2#conditions"}
String   Condition_ID2  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay2#conditions"}

DateTime ObservationTime3 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay3#forecastTime"}
Number   Temp_Min3			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay3#minTemperature"}
Number   Temp_Max3      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay3#maxTemperature"}
String   Condition3     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay3#conditions"}
String   Condition_ID3  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay3#conditions"}

DateTime ObservationTime4 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay4#forecastTime"}
Number   Temp_Min4			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay4#minTemperature"}
Number   Temp_Max4      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay4#maxTemperature"}
String   Condition4     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay4#conditions"}
String   Condition_ID4  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay4#conditions"}

DateTime ObservationTime5 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay5#forecastTime"}
Number   Temp_Min5			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay5#minTemperature"}
Number   Temp_Max5      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay5#maxTemperature"}
String   Condition5     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay5#conditions"}
String   Condition_ID5  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay5#conditions"}

DateTime ObservationTime6 	"Previsioni [(%1$tA)]"  						&lttime&gt 			(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay6#forecastTime"}
Number   Temp_Min6			"Temperatura min [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay6#minTemperature"}
Number   Temp_Max6      	"Temperatura max [%.2f °C]"   					&lttemperature&gt 	(Weather) 	{channel="weatherunderground:weather:Roma:forecastDay6#maxTemperature"}
String   Condition6     	"Condizioni [%s]"     							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay6#conditions"}
String   Condition_ID6  	"Condizioni id [%s]"  							&ltsun_clouds&gt 	(Weather)	{channel="weatherunderground:weather:Roma:forecastDay6#conditions"}

You can use the items defining them in sitemap to be displayed on a Basic UI:

or Classic UI, as well on the mobile app:

The data can of course be integrated with local measurement, and displayed together on an habpanel.