Weather underground binding: Translation using lambda

Tags: #<Tag:0x00007f61700b1868> #<Tag:0x00007f61700b1638>

I successfully run the WU binding, which I have configured to return the WU information in German.

I want to use my own icons with English names. In order to access the icons, I want to translate the Weather Conditions from German. As I am not a programmer, I need some help.

Here’s my rule. Unfortunately, I get the following error - although the state of the item LocalWeather_Current_CurrentConditions equals “Nebel”

2018-01-29 19:33:02.948 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'React on testSwitch': Cannot assign a value in null context.
var String iconName

val Functions$Function1<String, String> translate = [
	String inputValue |
		switch inputValue {
			case "Bedeckt":
				iconName = "cloudy"
			case "Böen":
				iconName = "flurries"
			case "Böen möglich":
				iconName = "chanceflurries"
			case "Dunstig":
				iconName = "hazy"
			case "Gewitter":
				iconName = "tstorms"
			case "Gewitter möglich":
				iconName = "chancetstorms"
			case "Graupel":
				iconName = "sleet"
			case "Graupel möglich":
				iconName = "chancesleet"
			case "Heiter":
				iconName = "clear"
			case "Meist sonnig":
				iconName = "mostlysunny"
			case "Nebel":
				iconName = "fog"
			case "Regen":
				iconName = "rain"
			case "Regen möglich":
				iconName = "chancerain"
			case "Schnee möglich":
				iconName = "chancesnow"
			case "Schneefall":
				iconName = "snow"
			case "Schneeschauer":
				iconName = "snow"
			case "Sonnig":
				iconName = "sunny"
			case "Teils sonnig":
				iconName = "partlysunny"
			case "Teils wolkig":
				iconName = "partlycloudy"
			case "Wolkig":
				iconName = "mostlycloudy"
			default:
				iconName = "unknown"
		}	
]

rule "React on testSwitch"
when
	Item testSwitch changed
then
	// your logic here
	imgWeatherDay1.postUpdate(translate.apply(LocalWeather_Current_CurrentConditions.state.toString))
end

This will be easier to maintain and manage if you use the Map transformation.

Put your mappings into transform/weather.map

Bedeckt=cloudy
Böen=flurries
...

and in your Rule

rule "React on testSwitch"
when
	Item testSwitch changed
then
    var english = transform("MAP", "weather.map", LocalWeather_Current_CurrentConditions.state.toString)
    if(english === null) english = "unknown"
    imgWeatherDay1.postUpdate(english)
end

The error you are receiving doesn’t make much sense to me. All I can guess is that the function is returning null for some reason.

Thx, Rick.

Now, I’m aware that one can use map files in rules, too - and that I could have seen that in the documentation.

G.