Alarm woes

Hi
I’m trying to tidy this up - this works but there must be an easier way!
7 day alarm clock code using this

var Timer timerPerson1Alarm = null

rule "Person1 preset load"
	when
		Item Person1_Alarm_Presets received command
then
    	var int sollMinute
        var int sollHour
        var int RunTime
        
	switch (Person1_Alarm_Presets.state){
		//early shift
		case 1:{
				sollHour=6
    			sollMinute=30
           		RunTime=60
		}
		//late shift
		case 2:{
				sollHour=8
    		    sollMinute=30
    		    RunTime=60			
		}
	}
	//set hour,Minute,runtime items for each day
	var i = 0
	var TheDay= "NA"
        //don't change saturday/sunday. set i max=7 and uncomment cases if you have to work weekends, you unlucky soul
	while ((i=i+1) <= 7) {
    	switch i{
        	case 1: TheDay = "Mo"
        	case 2: TheDay = "Tu"
        	case 3: TheDay= "We"
        	case 4: TheDay= "Th"
        	case 5: TheDay= "Fr"
        	case 6: TheDay= "Sa"
        	case 7: TheDay= "Su"
    	}
    	//set all hours
    	gPerson1Alarm.members.filter(s|s.name == "Person1_Alarm_"+TheDay+"_H").forEach[s | s.postUpdate(sollHour)]
    	//set all Minutes
    	gPerson1Alarm.members.filter(s|s.name == "Person1_Alarm_"+TheDay+"_M").forEach[s | s.postUpdate(sollMinute)]
    	//set runtimes
    	gPerson1Alarm.members.filter(s|s.name == "Person1_Alarm_"+TheDay+"_RUN").forEach[s | s.postUpdate(RunTime)]
	}
end

Trying to conotate the time into a single string to display - and ultimately display tomorrow’s time on alarm clock openhab panel

rule "update Mo Alarm"
when
    Item Person1_Alarm_Mo_H changed or
    Item Person1_Alarm_Mo_M changed
then
    Person1_Alarm_Mo_T.postUpdate((Person1_Alarm_Mo_H.state.toString) + ":" + (String.format("%02d", (Person1_Alarm_Mo_M.state as Number).intValue)))
end

x7 ie 1 for each day of the week!
I’ve tried simply putting the conotated expression into a separate expression

gPerson1Alarm.members.filter(s|s.name == "Person1_Alarm_"+TheDay+"_T").forEach[s | s.postUpdate((Person1_Alarm_Mo_H.state.toString) + ":" + (String.format("%02d", (Person1_Alarm_Mo_M.state as Number).intValue)))]

I’ve also tried making each part a variav=ble and doing - but it doesnt work
Help appreciated

I assume this first Rule gets executed when you need to change the shift

Since there are only two options, a switch statement is probable overkill here. Also, avoid the use of primitives. The only difference is the solHour so let’s use the trinary operator just on that variable.

    val solMinute = 30
    val solHour = if(Person1_Alarm_Presents.state == 1) 6 else 8
    val RunTime = 60

A for loop would be better than a while loop. You appear to set the hour, minute, and run to the same values for every day of the week, so we probably don’t need the switch statement or for loop at all.

    gPerson1Alarm.members.filter[ s | s.name.contains("_H") ].forEach[ s | s.postUpdate(solHour) ]
    gPerson1Alarm.members.filter[ s | s.name.contains("_M") ].forEach[ s | s.postUpdate(solMinute) ]
    gPerson1Alarm.members.filter[ s | s.name.contains("_RUN") ].forEach[ s | s.postUpdate(RunTime) ]

This makes the first Rule become:

Now you want to concatenate the hours and minutes to a String. So why not do that in the original Rule? I’m assuming that the Person1_Alarm_X_T Items are in the gPerson1Alarm Group. We already know what the hours and minutes are in the original Rule.

    gPerson1Alarm.members.filter[ s | s.name.contains("_T")].forEach[ s | s.postUpdate(solHours + ":" + solMinutes) ]

The total Rules would become

rule "Person1 preset load"
	when
		Item Person1_Alarm_Presets received command
then
    val solMinute = 30
    val solHour = if(Person1_Alarm_Presents.state == 1) 6 else 8
    val RunTime = 60

    gPerson1Alarm.members.filter[ s | s.name.contains("_H") ].forEach[ s | s.postUpdate(solHour) ]
    gPerson1Alarm.members.filter[ s | s.name.contains("_M") ].forEach[ s | s.postUpdate(solMinute) ]
    gPerson1Alarm.members.filter[ s | s.name.contains("_RUN") ].forEach[ s | s.postUpdate(RunTime) ]
    gPerson1Alarm.members.filter[ s | s.name.contains("_T")].forEach[ s | s.postUpdate(solHours + ":" + solMinutes) ]
end

Shift change or change the time on the UI
Code that I used was a 5 day alarm clock - but 7 day suits me better
I tried doing it in the original rule…but I couldnt get it to work (hence creating a separate rule to trial it) - I was probably over complicating it as the solution seems so simple!
Thanks - will try once at home