Not scalable icons with openweathermap

openhab2
Tags: #<Tag:0x00007f1e5b4c2310>
(Jacek) #1

Raspberry Pi v.3+
Openhab 2.4
myOpenHub Cloud connection with:
iphone 6 - iOS 12.2
Samsung G8 - Android 8.0.0

I use openweathermap account. This API works quite OK with one problem.
The icon of the current weather condition on Android device is not scalable (big pixels are awful) and on iPhone not visible at all :frowning: . I do not know where these icons are located, how to influence their visibility on mobile devices?
Does someone knows how can i fix this or mitigate it?
Appreciate support.

Thanks

weather.items

String localStationId "ID [%s]" { channel="openweathermap:weather-and-forecast:api:local:station#id" }
String localStationName "City [%s]" <my_city> { channel="openweathermap:weather-and-forecast:api:local:station#name" }
Location localStationLocation "Location [%2$s°N %3$s°E]" <location> { channel="openweathermap:weather-and-forecast:api:local:station#location" }

//DateTime localLastMeasurement "Timestamp of last measurement [%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS]" <time> { channel="openweathermap:weather-and-forecast:api:local:current#time-stamp" }
DateTime localLastMeasurement "Timestamp of last measurement [%1$tH:%1$tM]" <time> { channel="openweathermap:weather-and-forecast:api:local:current#time-stamp" }
String localCurrentCondition "Current condition [%s]" <sun_clouds> { channel="openweathermap:weather-and-forecast:api:local:current#condition" }
Image localCurrentConditionIcon "Icon" { channel="openweathermap:weather-and-forecast:api:local:current#icon" }
Number:Temperature localCurrentTemperature "Outside temperature [%.1f %unit%]" <temperature> { channel="openweathermap:weather-and-forecast:api:local:current#temperature" }
Number:Pressure localCurrentPressure "Current barometric pressure [%.1f %unit%]" <pressure> { channel="openweathermap:weather-and-forecast:api:local:current#pressure" }
Number:Dimensionless localCurrentHumidity "Outside humidity [%d %unit%]" <my_humidity> { channel="openweathermap:weather-and-forecast:api:local:current#humidity" }
Number:Speed localCurrentWindSpeed "Current wind speed [%.1f km/h]" <wind> { channel="openweathermap:weather-and-forecast:api:local:current#wind-speed" }
//Number:Angle localCurrentWindDirection "Current wind direction [%d %unit%]" <wind> { channel="openweathermap:weather-and-forecast:api:local:current#wind-direction" }
Number:Dimensionless localCurrentCloudiness "Current cloudiness [%d %unit%]" <my_clouds> { channel="openweathermap:weather-and-forecast:api:local:current#cloudiness" }
Number:Length localCurrentRainVolume "Current rain volume [%.1f %unit%]" <rain> { channel="openweathermap:weather-and-forecast:api:local:current#rain" }
Number:Length localCurrentSnowVolume "Current snow volume [%.1f %unit%]" <snow> { channel="openweathermap:weather-and-forecast:api:local:current#snow" }

openweather.things

Bridge openweathermap:weather-api:api "OpenWeatherMap Account" [apikey="xxxxx", refreshInterval=30, language="de"] {
    Thing weather-and-forecast local "Local Weather And Forecast" [location="xxx,yyy", forecastHours=3, forecastDays=0]
    //Thing uvindex local "Local UV Index" [location="xxx,yyy", forecastDays=1]
    //Thing weather-and-forecast miami "Weather And Forecast In Miami" [location="25.782403,-80.264563", forecastHours=24, forecastDays=0]
}

basic.ui

https://192.168.1.114:8443
0 Likes

(Rich Koshak) #2

The image is created and provided by the OpenWeathermap service. OH has no control over them. It is explicitly labeled as an icon so a high resolution version of the image should not be expected.

If you want a way to apply that icon to the Current Conditions String Item, see OpenWeatherMap Use Icon Channel as icon on Sitemap.

0 Likes

(Jacek) #3

Thank you Rich for the answer. Appreciate your time on probably trivial questions. I am ok to use the icon. I do not expect high quality pictures. I just expect them to work.
Is there really not possible to scale received icons withing openhab/myopenhabian? Nobody really complained on that?

Coming back to your workaround. Can you confirm I do understand your approach properly:

  1. Existing contrition icon is being downloaded to weather.gif file
  2. Converted to string
  3. Converted/replaced to png
  4. Output back again
  5. Downloaded icon deleted

Strange procedure and I do not understand it well. Could you explain again why string? Why to png? What if the icon will not be .gif some day?

Appreciate your answer.
Thank you

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
0 Likes

(Rossko57) #4

The purpose of this procedure is to fetch the image from OpenWeatherMap and then use it as though it were one of the standard openHAB icons, like the temperature or humidity icons.
Those are png (or svg).

0 Likes

(Rich Koshak) #5

No. openHAB doesn’t create these image files. openHAB isn’t an image file processor or creator. openHAB isn’t able to magically create out of thin air details that do not exist in the original image so it scales nicer. And because the image is an icon it is appropriately sized for the the purpose for which it is intended.

You are attempting to use the icon image file in a way that it was not intended. I suppose no one has complained before because no one else is trying to use the icon image in this way.

Not quite.

  1. The weather binding sets the URL to the image file vWeather_Conditions_Icon Item which triggers the Rule.

  2. I execute wget using the executeCommandLine Action to download the file at that URL to a file to the path I saved to the file varaible: /openhab/conf/icons/classic/weather.gif

  3. I create two Objects that represents a File, input and output.

  4. I use the built in ImageIO library to read in the file at input and write out that image file in png format.

  5. I delete the gif.

I don’t know where you are getting this. There is no conversion to String anywhere. I saved the path to where I want to write the git file to a variable so I don’t have to keep retyping it. You will notice that file is used four times in that short Rule.

Because openHAB only supports png and svg formatted images to be used as icons in sitemaps.

Then the Rule would have to be rewritten if it is changed to a format that ImageIO doesn’t support.

0 Likes

(Jacek) #6

Thank you very much for explanations. No let me try. I will come back if this gonna work :wink:

0 Likes