[SOLVED] BBC weather RSS Latest Title split to <64 characters for Velbus OLED (AKA Splitting Strings)

??? the value isn’t used but you can’t solve the problem without using it? Then aren’t you using it?

I’m usually one to not recommend going out of our way to change code for efficiency purposes, but in this case it also avoids some duplicated code.

    // val weather0 = BBCWeatherRSS_LatestTitle.state.toString.split(',').get(0) let's try to not have this line since you say you don't use it.

    val parts = BBCWeatherRSS_LatestTitle.state.toString.split(':').get(1)
    val weather1 = parts.get(1)
    val weather2 = parts.get(2)
    val weather3 = parts.get(3)

For the second part of the Rule, I like to apply Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL. You essentially have the same code in both if statements. I prefer to calculate the message and only call the sendCommands once.

     var message = if(OLED_Weather.state == ON) "Weather = "+condition+" , Min = "+minT+"°C , Max = "+maxT+"°C" else ""
     var logMsg = if(OLED_Weather.state == ON) "Weather string sent to OLEDs" else "Blank Msg sent to OLEDs"

    TVRoomGPO_OledDisplay_Memo.sendCommand(message)
    BackBedroomGPO_OledDisplay_Memo.sendCommand(message)
    Cabin_Memo_Text.sendCommand(message)
    LoungeGPO_OledDisplay_Memo.sendCommand(message)
    logInfo("OLED MEMO",logMsg)

Now there is one more improvement we can make here. Instead of applying the DRY DP we use a Group. Put all of your Memo Items into the same Group, let’s call it Group:String Memos.

Then the bottom part of your Rule becomes

    Memos.sendCommand(message)
    logInfo("OLED MEMO",logMsg)

And we can even merge these lines with the lines above it:

    Memos.sendCommand(if(OLED_Weather.state == ON) "Weather = "+condition+" , Min = "+minT+"°C , Max = "+maxT+"°C" else "")
    logInfo("OLED MEMO", if(OLED_Weather.state == ON) "Weather string sent to OLEDs" else "Blank Msg sent to OLEDs")

Resulting in:

rule "BBC Weather RSS to Velbus Memo text"
when
    Item BBCWeatherRSS_LatestTitle received update or Item OLED_Weather changed
then 
    //		logInfo("BBC Weather Info", "BBC weather RSS update = "+BBCWeatherRSS_LatestTitle.state)


    val parts = BBCWeatherRSS_LatestTitle.state.toString.split(':').get(1)
    val weather1 = parts.get(1)
    val weather2 = parts.get(2)
    val weather3 = parts.get(3)

    val condition = weather1.toString.split(',').get(0)
		
    val minT = weather2.toString.split('°').get(0)
	
    val maxT = weather3.toString.split('°').get(0)

    Memos.sendCommand(if(OLED_Weather.state == ON) "Weather = "+condition+" , Min = "+minT+"°C , Max = "+maxT+"°C" else "")
    logInfo("OLED MEMO", if(OLED_Weather.state == ON) "Weather string sent to OLEDs" else "Blank Msg sent to OLEDs")
end