[SOLVED] Elegant rule for select based on MQTT output

Hi

i have integrated a broadlink sensor with MQTT

the item:

String mqtt_sensor_door 		"S1-Door Sensor" {mqtt="<[mosquitto:broadlink/mqtt_S1_1/door:state:default]"}

The sitemap

Default item=mqtt_sensor_door

the rule



//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#https://community.openhab.org/t/design-pattern-motion-sensor-timer/14954/55
var Timer sensor_door_Timer = null
val int timeoutMinutes = 2


//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#https://community.openhab.org/t/design-pattern-motion-sensor-timer/14954/55
rule "sensor_door OFF by Timer"
when
    Item mqtt_sensor_door changed 
then
    val stateAsString = mqtt_sensor_door.state.toString
    logInfo("INFO","----" + stateAsString + "---")   
	if (stateAsString.contains("opened")){
            logInfo("INFO","MQTTLOG DOOR OPENED 1" +"--" + stateAsString )
  		    if(sensor_door_Timer === null){
     			//motion_LastUpdate.postUpdate(new DateTimeType())
      			 sensor_door_Timer = createTimer(now.plusMinutes(1)) [
		        val stateAsStringafter = mqtt_sensor_door.state.toString
                     logInfo("INFO","MQTTLOG 2" +"--" + stateAsString+"--" )

				if (stateAsStringafter.contains("closed")){
                     	  logInfo("INFO","MQTTLOG DOOR CLOSED 3" +"--" + stateAsString+"--" )
                      	  sensor_door_Timer=null }
                            else 
                    	  logInfo("INFO","MQTTLOG DOOR opened 4" +"--" + stateAsString+"--" )
                            sensor_door_Timer.reschedule(now.plusMinutes(1))]}
              
    //else{logInfo("INFO","MQTTLOG DOOR closed 5" +"--" + stateAsString+"--" )}
	
    }              
end




is there not a more simple way ?

Not really, if you remove all the logInfos you only have 7 lines of code.
Tidy up your indents it will look simpler than it looks now