In my previous Wunderground based setup I would download the current conditions icon and save it in my icons/classic folder so it can be displayed on my sitemap. Now that Wunderground is ending their free API I’ve switched over to the OpenWeatherMap binding. To minimize the changes necessary I need to do the same thing with the icons from this service and luckily there is an Icon Channel.
As far as I can tell there is no way to use an Image type Item as the icon for another Item. But I did notice that if I link a String to the Icon Channel instead of an Image I will get the URL to the Icon.
So I rewrote my Rule that downloads Wunderground icons to work with this Channel. Here it is:
vWeather_Conditions_Icon is a String Item linked to the Icon Channel of the OpenWeatherMap Thing.
rule "Copy the conditions icon" when Item vWeather_Conditions_Icon changed then // Were to save the downloaded file val file = "/openhab/conf/icons/classic/weather.gif" // Download it using wget executeCommandLine("/usr/bin/wget -q -O " + file + " " + vWeather_Conditions_Icon.state.toString, 5000) // Convert from gif to png val input = new File(file) val output = new File(file.replace("gif", "png")) ImageIO::write( ImageIO::read(input), "png", output) // Remove the gif executeCommandLine("rm " + file) end
Set the icon on whatever Item you have linked to the Current Conditions Channel to
<weather> and it will use the icon downloaded from OpenWeatherMap.
The above will work on Docker and any system with wget installed. You may need to change the path to wget though.
But the above will not work if you need SVG icons. For that you will probably need to install gif2png or convert on your machine and replace the ImageIO stuff with an executeCommandLine call to that utility. I run in Docker and don’t want to deviate from the stock image so those were not an option for me. But I was already using PNG icons so that’s no big deal.
Hope this helps someone.