How to get text representation from channel in a script

I have been looking though both the documentation and searched the forum, but can’t find anything describing this issue I have…so here it goes…

  • Issue of the topic: So I want to send a weather forecast to Telegram (with the SMHI addon). The addon works fine, Channel is linked (through GUI though) to the item. Telegram link works fine too(use it for other things).

So I have no trouble getting the state value from SMHI_Weather Condition in the addon to Telegram. But I get it in the number value. Everywhere else on the UI it is represented by the text for the value. Eg. I get 18 back, which means Light Rain.

And I can’t figure out, or find any information that makes it any more clear, how I can get Telegram to send me the text “Light rain” instead of 18. What am I not getting or not doing?

The script is pretty simple, and it triggers as it should, it’s just sending me numbers instead of text.

val telegramAction = getActions("telegram","telegram:telegramBot:Botzon") 
telegramAction.sendTelegram(-xxxxxxxxL,"Forecast: "+ SMHIWeatherForecast_WeatherCondition.state" )

What I get is Forecast: 18

I am sure this is just a simple fix, but I can’t find it… :unamused:
I haven’t been able to find anything telling me how I get the text the linked channel maps for the value 18.

Thank you for helping this confused n00b take a step forward. :pray:

If you use API Explorer to look at the JSON version of your Item, you’ll probably find it has ‘options’ forming a look-up table.
The UI uses those, but you cannot get at them from DSL rules.
Simplest is to make your own look-up using a MAP transformation, the codes are in the binding docs.

Ah, alright! Thank you! I started to suspect I might have to map the data myself. I will give that a go then.

Thank you @rossko57 :pray: