OpenWeatherMap Icon - use as image in rule?

just switched from discontinued WeatherUnderground to the new OpenWeatherMap 2.4 binding.
Running OH2 stable 2.4.

In my rule, I send an Email with the condition icon. With WU I got the URL of that icon and cached this locally, then sent it. Worked finally.
Now I got the “Image”-item from the binding and want to do the same. How can I achieve this?


 String WeatherRB_TdyConditions       "heute Wetterlage [%s]"      { channel="openweathermap:weather-and-forecast:api:rossbuehel:forecastToday#condition" } 
 String WeatherRB_TdyConditionsId     "heute Wetterlage ID [%s]"   { channel="openweathermap:weather-and-forecast:api:rossbuehel:forecastToday#condition-id" } 
 Image  WeatherRB_TdyConditionsIcon   "heute Wetter Icon"          { channel="openweathermap:weather-and-forecast:api:rossbuehel:forecastToday#icon" } 

so: how can I use the “Image” item in a rule?

I just did this myself. It isn’t super straight forward and there may be easier ways to do it if you are not running in Docker.

First of all, at least with 2.5 M1 you can link the Icon Channel to a String and that String will be the URL path to the icon. However, the icon will be a gif. So this Rule downloads it using wget, then converts it to a png so it can be used on my sitemap. Unfortunately ImageIO cannot convert to svg so you are on your own if you need that format.

Since you are just emailing the image, you can probably just keep it as a gif.

rule "Copy the conditions icon"
  Item vWeather_Conditions_Icon received update or
  Item Test received command
    // 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)

    // Set the icon for what ever Item is linked to the Conditions to <weather>

I tried to do the same and neither your nor @rlkoshak’s approach seemed to work on my openHAB 2.5. After fiddling around with the rule’s code, the following works for me:


rule "Wettericon"
when Item Wetter_Current_Icon changed
  val raw = Wetter_Current_Icon.state as RawType
  val file = new FileOutputStream("/etc/openhab2/icons/classic/weather.png")

where Wetter_Current_Icon is the item, which is bound to the OWM’s weather icon. It is saved as icon weather. In the sitemap I added the following line:

Text          item=Wetter_Current_Wetterlage icon="weather"

Works fine in OpenHAB 3 also,