OpenWeatherMap condition icon

In the old days, the 1.x weather binding provided a “common ID” numeric value. This was in the 1 to 50 range, and encoded a general description where “25 = stormy” etc.
The great advantage of this was that you could set up a Weather Number Item to put on the sitemap. The numeric value selecting from a preloaded set of simple weather icons, and a MAP transformation producing a text description in the language of choice.
A one-line weather forecast with dynamic icon + text.

With Yahoo weather becoming unavailable, I’ve moved to OpenWeatherMap - very nice thankyou :wink:
OWM allows us to retrieve an icon for a forecast, but that is difficult to use in a sitemap line.
OWM provides a numeric condition, but these can be value “523” and so on, which are not suitable for openHAB dynamic icons (limited to 1-99)
OWM provides a textual description, but it would be really nice to have a matching icon with that.

It should be possible to use some transform map to convert incoming OWM ID numbers into Common ID numbers.
Perhaps someones already done that, and would share?

Alternatively, if the “Common ID” idea is still something of use with other 2.x weather services, perhaps the OWM binding could be enhanced to provide a suitable channel?

Thoughts welcome.

Hi @rossko57,

I am not aware of any existing solution for your request but I like the idea behind it. If you need it quickly I would suggest to implement the transformation (MAP?) approach. Here you can find a list of the common ID mappings of the 1.x weather binding.

For the long run I would suggest to implement it in the weather bindings itself. But it does not make sense that every weather binding implements the mapping on its own - it is hard to maintain. Thus a global place for it should be preferred.

IIRC an experimental binding for weather calculations is available via the Eclipse Marketplace. Maybe that is an idea.

My 2ct. Wdyt?

Not so sure. Each weather service likely has its own condition codes, so the “source” coding logically sits with the binding.
It seems to me the weather calculations binding would best be fed with an already standardized code. Whose standard though? I haven’t found one yet, but will dig some more I think.
Nuisance to maintain is certainly the general case, I reckon :slight_smile:

The old 1.x XML conversion table is a very good find, I’d missed that. I might have a play and see if some kind of common transform external to any bindings is viable.

Following a different path, and setting aside any “common” code with other weather services for now.
shows the limited Icon set that OWM already ‘decodes’ from its larger, more detailed, weather condition ID set.
The OWM data JSON feed supplies that in the form “10n” or "02d’ etc. and I suppose the binding already uses that to construct the “Image” ready icon channel.

I wonder if that icon code (rather than the actual image) were also made available to a text channel ? That should offer a good route to making a sitemap compatible icon.
I’ve tried but failed to extract url from the existing Image channel.

Should be possible in this way:

val url = localCurrentConditionIcon.state.toFullString

Maybe I have another interesting information for you: The OWM binding downloads all the icons and stores them on your local file system in the folder userdata/cache/org.eclipse.smarthome.binding.openweathermap/.

1 Like

This sounds interesting. Any idea how these icons could be used with the OWM binding / ones sitemap?

Unfortunately gives me a hex dump of the png, cannot get the url/code

EDIT- rummaging in old posts, I think this was implemented as string channel #icon-id at one time, but has since been dropped? If you think it wise, I could open a formal issue for reinstating.

I’m using the icons in my sitemap, but not those from cache… I’m converting the Image item provided by channel icon into PNGs.


Group OpenWeatherMap
Group OpenWeatherMap_Icon
String owmCondition "Current Condition [JS(uppercase.js):%s]" <forecastHours00> (OpenWeatherMap) {channel="openweathermap:weather-and-forecast:api:local:current#condition"}
Image owmCondition_forecastHours00_Icon (OpenWeatherMap, OpenWeatherMap_Icon) {channel="openweathermap:weather-and-forecast:api:local:current#icon"}
String owmCondition_forecastHours03 "Condition [JS(uppercase.js):%s]" <forecasthours03> (OpenWeatherMap) {channel="openweathermap:weather-and-forecast:api:local:forecastHours03#condition"}
Image owmCondition_forecastHours03_Icon (OpenWeatherMap, OpenWeatherMap_Icon) {channel="openweathermap:weather-and-forecast:api:local:forecastHours03#icon"}
String owmCondition_forecastHours06 "Condition [JS(uppercase.js):%s]" <forecasthours06> (OpenWeatherMap) {channel="openweathermap:weather-and-forecast:api:local:forecastHours06#condition"}
Image owmCondition_forecastHours06_Icon (OpenWeatherMap, OpenWeatherMap_Icon) {channel="openweathermap:weather-and-forecast:api:local:forecastHours06#icon"}


rule "Weather Condition Icons"
	Member of OpenWeatherMap_Icon changed
	if(triggeringItem.state != NULL) {
		val cmd = "/etc/openhab2/scripts/my_scripts/ " +"_Icon","").replace("owmCondition_","").toLowerCase + " \"" + triggeringItem.state.toFullString.replace("data:image/png;base64,","") + "\""


/bin/echo "$2" | base64 -d > /etc/openhab2/icons/classic/$1.png

Every time the one of the icons changes, it write the base64 encoded image to a file, with a name derived from the item name.
The downside is that the’re PNG, not SVG - that obliged me to use PNG all over - and, of course, you have to disable caching of images in browser or app.
One other minor thing is that the images are quite small. Maybe I’ll find something to “zoom” them… Hmm… That’s a thought… :slightly_smiling_face:

1 Like

My fault. Sry for spreading wrong information.

That is true. The channel was rejected and dropped during initial code review. I can imagine to readd it then but maybe providing a full url would be the better option as this can be processed directly.

Not so sure,more inclined to have the binding present the data as it comes from OWM and not try to be helpful, without knowing if the user intends something else (own icons, etc.)

I’ve raised an issue so others can have a say.

EDIT - revised issue

I have made a dirty fix to my original need, one-line forecast with icon. This does not include any day/night niceties.

As I previously used Yahoo weather in OH1, I chose to re-use the same icons. These can be found on the web and old OH1 tutorials.
So, in my conf/icons/classic/ folder I now have yweather-0.png, yweather-2.png, and so on. Don’t forget to provide a default yweather.png - perhaps a question mark, suitable for undefined.

I assign two Items to be bound to the OpenWeatherMap channels for condition (long text) and condition-id (numeric) to get the forecast data that I’m interested in.
I have another Number item to accept the new combination.

String ForecastCondition "Forecast condition [%s]"  { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#condition" }
String ForecastConditionID "Forecast condition ID [%s]"  { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#condition-id" }
Number ForecastCombo "Forecast" <yweather>

Now for a magic part. I use a SCALE transformation to convert OWM condition ID codes into Yahoo compatible codes. This file ges into conf/transform


#freezing rain
#light cloud
#broken cloud

A rule is needed to make at all happen, converting OWM ID to a Yahoo number, and updating the combo item with the long text description

rule "Weather summary"
	System started or
	Item ForecastConditionID changed
	if (ForecastConditionID.state == NULL || ForecastConditionID.state == UNDEF) {
		ForecastCombo.label = "Awaiting forecast"
	} else {
		val id = transform("SCALE", "owm.scale", ForecastConditionID.state.toString)
		ForecastCombo.label = "6hr Forecast - " + ForecastCondition.state  // description
		ForecastCombo.postUpdate(id) // numeric for icon

And at last, ready for a sitemap entry

	Text item=ForecastCombo



This is a great approach! The only thing that bothers me a bit is that the icons on the sitemap are a bit too small. But most probably we have to live with that :roll_eyes:

Small icons is what I actually wanted.
The old 1.x weather binding could work with an HTML snippet that could be inserted in sitemaps for a whizzy display.

I have no idea how/if that can be adapted for OH2. Some clues here

I solved that also:

I installed ImageMagick package (sudo apt-get install imagemagick) and I added changed


/bin/echo "$2" | base64 -d > /etc/openhab2/icons/classic/$1.png
/usr/bin/mogrify -adaptive-resize 80x80 -trim +repage /etc/openhab2/icons/classic/$1.png

So, the PNG gets resized and trimmed…
I looks quite alright…

1 Like

Hello all,

I also implement switching the weather icon. Script works quite well, the pic references are always updated when the status changes. I can confirm this when looking into /icons/classic/

But when looking into Basic UI there are no changes updated. This is due to icon caching, which I can check via deleting the browser cache. Then when I restart Basic UI it shows the correct images. After it is running a while and some updates where performed, the images in Basic UI do not represent what is in the folder anymore.

I can confirm this behaviour on Browser (Firefox + Chrome) and as well in the iPhone and iPad App. Clearing image cache in the App does not have an impact and it is still showing the wrong icon. Only complete deletion of the App works.

Do you have such problems as well and were you able to solve it somehow?

Setup: openHAB 2.4.0 Release Build running on Raspberry Pi 4 with 4GB Ram, installed manually (no openhabian was existing)

Which icon method are you using?

I am using the icon tag <icon_wo_extension> in the item definition