Template Example: Weather Binding

Hi @opus,

The section of code that displays the image files is:

<img src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('Condition0').replace(' ','-') | lowercase }}.png"/>

It essentially points to the file location + path + file name of the image file. In addition any spaces in the condition value are replaced by hyphen (-) characters and the string is converted to lowercase so that it matches the icon names that are used in the original openHAB v1 solution.

For example, if the weather condition is Partly Cloudy Day then the img src string generated at runtime would be:

<img src="http://192.168.4.34:8080/static/images/flat_white/partly-cloudy-day.png"/>

Because you are using German, the condition name will no longer match the name of the image file when it is “inserted” into the img src string at runtime.

I think you have two choices:
Method1:
Rename the image files to match the German condition values. Remember to substitute spaces with hyphens and remove any brackets ( and ). There does not appear to be a way to get a definitive list of these values in any language and be aware that some of the lists you will find on the internet do not seem to be accurate / reflect the values coming back from the API today!

Method 2:
Rename the image files to use the condition ID numbers. These are listed in English at https://developer.yahoo.com/weather/documentation.html#codes.

In addition you would need to add three new items:

String   Condition_ID0  "Condition id [%s]"  {weather="locationId=[your location], forecast=0, type=condition, property=id"}
String   Condition_ID1  "Condition id [%s]"  {weather="locationId=[your location], forecast=1, type=condition, property=id"}
String   Condition_ID2  "Condition id [%s]"  {weather="locationId=[your location], forecast=2, type=condition, property=id"}

and change the four **img src ** code lines:

from:
<img src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('Condition0').replace(' ','-') | lowercase }}.png"/>

to:
<img src="{{ServerPath}}/images/{{IconSet}}/{{itemValue('Condition_ID0').replace(' ','-') | lowercase }}.png"/>

The second method works well (tested on my set-up) and would provide a solution for any language, just needs some time to go through all the icon files to rename them. If I get a chance I will try and get this done.

Sorry that neither of these solutions is very elegant. Some of the limitations come from the original approach of converting the original v1 code for use in HABpanel re-using as much of the original work as possible. I was and am still learning how to do these things better.

Regards, Andy

1 Like