OpenWeatherMap condition icon

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.

weather.items

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"}
.....................................................................

weather.rules

rule "Weather Condition Icons"
when
	Member of OpenWeatherMap_Icon changed
then
	if(triggeringItem.state != NULL) {
		val cmd = "/etc/openhab2/scripts/my_scripts/base642png.sh " + triggeringItem.name.replace("_Icon","").replace("owmCondition_","").toLowerCase + " \"" + triggeringItem.state.toFullString.replace("data:image/png;base64,","") + "\""
		//logWarn("DEBUG",cmd)
		executeCommandLine(cmd,2000)
	}
end

base642png.sh

#!/bin/sh

/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