[SOLVED] An error occurred during the script execution: null

Hi,

i have seen already other issues on this error but it do not help

i have a long rule which can get inputs from telegram, voicecommand, or google calendar.

i am getting this error :
An error occurred during the script execution: null

Please find below the logs:

114 [INFO ] [script.Rule File: voicecontrol.rules] - Rule:TelegramInput
129 [INFO ] [smarthome.model.script.voice control] - 2 TelegramInput received----@ifttt éteindre télé----
140 [INFO ] [smarthome.model.script.voice control] - 2 TelegramInput received----éteindre télé----
==> /var/log/openhab2/events.log <==
165 [ome.event.ItemCommandEvent] - Item 'GlobalScene' received command éteindre télé
179 [vent.ItemStateChangedEvent] - TriggerGlobalScene changed from VoiceCommand to Telegram
184 [vent.ItemStateChangedEvent] - GlobalScene changed from éteindre clim salon to éteindre télé
2018-08-05 22:06:24.107 [vent.ItemStateChangedEvent] - Sun_Elevation changed from -26.88 to -27.63
2018-08-05 22:06:24.428 [vent.ItemStateChangedEvent] - Moon_Elevation changed from -30.69 to -29.96

==> /var/log/openhab2/openhab.log <==
311 [INFO ] [script.RULE : Scenario -GlobalScene=] - receivedCommand :éteindre télé
316 [INFO ] [ipse.smarthome.model.script.Scenario] - 1-newscene :éteindre télé
332 [INFO ] [ipse.smarthome.model.script.Scenario] - 2-newscene :eteindre tele
==> /var/log/openhab2/events.log <==
352 [vent.ItemStateChangedEvent] - GlobalScene_LastUpdate changed from 2018-08-05T22:03:44.404+0300 to 2018-08-05T22:06:26.335+0300
==> /var/log/openhab2/openhab.log <==
354 [INFO ] [ipse.smarthome.model.script.Scenario] - -----------------------------------------------------------------------
360 [INFO ] [pse.smarthome.model.script.Scenario ] - --END OF CLOSED OPTIONS---VarFoundScenario= NULL
==> /var/log/openhab2/events.log <==
366 [vent.ItemStateChangedEvent] - FoundScenario changed from eteindre clim salon to NULL
==> /var/log/openhab2/openhab.log <==
368 [INFO ] [.eclipse.smarthome.model.script.cmd ] - OFF
409 [INFO ] [.eclipse.smarthome.model.script.cmd ] - tele: current state ON
417 [INFO ] [ipse.smarthome.model.script.Scenario] - -----------------------------------------------------------------------
423 [INFO ] [pse.smarthome.model.script.Scenario ] - VarFoundScenario= NULL
429 [INFO ] [pse.smarthome.model.script.Scenario ] - -----END OF OPENED OPTIONS----VarFoundScenario= NULL
435 [INFO ] [pse.smarthome.model.script.Scenario ] - -----NOT FOUND----eteindre tele_ISSUE
==> /var/log/openhab2/events.log <==
448 [vent.ItemStateChangedEvent] - FoundScenario changed from NULL to eteindre tele_ISSUE
==> /var/log/openhab2/openhab.log <==
462 [INFO ] [pse.smarthome.model.script.ifttt_url] - https://maker.ifttt.com/trigger/GlobalScene/with/key/d-gfo0Ob3sjc-zAuwcQJ6F
475 [INFO ] [me.model.script.notification_json = ] - {"value1":"Telegram","value2":"eteindre_tele_ISSUE-Opened","value3":"10:06m on Sunday, August 5, 2018"}
483 [INFO ] [se.smarthome.model.script.myquery = ] - curl@@-X@@POST@@-H@@Content-Type: application/json@@-d@@{"value1":"Telegram","value2":"eteindre_tele_ISSUE-Opened","value3":"10:06pm on Sunday, August 5, 2018"}@@https://maker.ifttt.com/trigger/GlobalScene/with/key/d-gfo0Ob3sjc-zAuwcQJ6F
035 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'scenario.rules'
536 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'scenario': An error occurred during the script execution: null
==> /var/log/openhab2/events.log <==
680 [vent.ItemStateChangedEvent] - logreaderLastError changed from 2018-08-05 22:03:49.680 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'scenario': An error occurred during the script execution: null to 2018-08-05 22:06:31.536 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'scenario': An error occurred during the script execution: null

Please find below the rules (the remarks for optimization are more than welcome)

The performance are not stable

var Timer ToasterTimer = null
val int timeoutMinutes = 8 // choose an appropriate value

rule "scenario"
when
    Item GlobalScene received command
then
//Block 1 start String formatting////////
 //if(GlobalScene.previousState == NULL) return;
	//var String newscene= GlobalScene.state.toString.toLowerCase
		
	var String newscene=receivedCommand.toString.toLowerCase
	var String cmd
	
	logInfo("RULE : Scenario -GlobalScene=", "receivedCommand :" +newscene  )	
	logInfo("Scenario", "1-newscene :"  + newscene)	
	newscene =newscene.replace("@ifttt ","")
	newscene =newscene.replace("ifttt","")
	newscene =newscene.replace("lili ","")
 	newscene =newscene.replace("lili","")

	newscene =newscene.replace("é","e")
	newscene =newscene.replace("é","e")
	newscene =newscene.replace("î","i")
	newscene =newscene.replace("allen","allume")
	newscene =newscene.replace("eteins","eteindre")
	newscene =newscene.replace("allumer","allume")
	newscene =newscene.replace("stop","eteindre")
	newscene =newscene.replace(" ’ ","'")
	newscene =newscene.replace(" ' ","'")


	logInfo("Scenario", "2-newscene :"  + newscene)	
	//1 end String formatting////////
	var String VarFoundScenario= "NULL"
	var String optionFound

	//logInfo("Scenario", "receivedCommand :"  + receivedCommand)		
	GlobalScene_LastUpdate.postUpdate(new DateTimeType()) 
	FoundScenario.postUpdate("NULL") 

//Bloc 1 end String formatting////////
//Bloc 2 Start Options ////////
	switch (newscene) 
        {		
				case "bloque tele",
				case "bloch tele":{
						VarFoundScenario=newscene
						//FoundScenario.postUpdate(newscene) 
						M1_1.sendCommand("OFF")
						M1_1.postUpdate("OFF")
					
				}
				case "allume appliques" ,
				case "allume applique" :
				{
					VarFoundScenario=newscene 

					appliqueSwitch.sendCommand(ON)
					appliqueSwitch.postUpdate(ON)  	  	
				//	FoundScenario.postUpdate(newscene) 
				}	

				case "eteindre appliques" :

				{
					VarFoundScenario=newscene  	

					appliqueSwitch.sendCommand(OFF)
					appliqueSwitch.postUpdate("OFF")  	
				//	FoundScenario.postUpdate(newscene) 
				}


				case "allume terrasse" :
				{	 
					VarFoundScenario=newscene  
					TerraseSwitch2.sendCommand("ON")
					TerraseSwitch2.postUpdate(ON)
					publish("mosquitto", "broadlink/mqtt_RM_1/rf/Terrrasse_ON", "replay")		
				//	FoundScenario.postUpdate(newscene) 
				}	

				case "eteindre terrasse":
				{ 
					VarFoundScenario=newscene
					TerraseSwitch2.sendCommand("OFF")
					TerraseSwitch2.postUpdate("OFF")
					publish("mosquitto", "broadlink/mqtt_RM_1/rf/Terrrasse_OFF", "replay") 		
				//	FoundScenario.postUpdate(newscene) 
				}

				
				
				case "allume clim salon":
				{ 
					VarFoundScenario=newscene 
				//	if 	(Clim_1.state.toString.toLowercase="on"){return;}

					Clim_1.sendCommand("ON")
					Clim_1.postUpdate(ON)	 
				//	FoundScenario.postUpdate(newscene) 
				}					
				
				case "eteindre clim salon":
				{	 
					VarFoundScenario=newscene  

				//	if 	(Clim_1.state.toString.toLowercase="off"){return;}

					Clim_1.sendCommand("OFF")
					Clim_1.postUpdate("OFF")	 	
				//	FoundScenario.postUpdate(newscene) 
				}			

				
				case "allume clim parents" :
				{ 
					VarFoundScenario=newscene 
					Clim_2.sendCommand("ON")
					Clim_2.postUpdate(ON)
				//	FoundScenario.postUpdate(newscene) 
				}	

				case "eteindre clim parents":
				{	 
					VarFoundScenario=newscene
					Clim_2.sendCommand("OFF")
					Clim_2.postUpdate("OFF")	
				//	FoundScenario.postUpdate(newscene) 
				}					
				
				case "allume clim noya",
				case "allume clim nono" :
				{	 
					VarFoundScenario=newscene
					Clim_3.sendCommand("ON")
					Clim_3.postUpdate(ON)				 
					 
				//	FoundScenario.postUpdate(newscene) 
				}	
				case "allume clim chateau":
				{ 
					VarFoundScenario=newscene 
					Clim_4.sendCommand("ON")
					Clim_4.postUpdate(ON)
					 
				//	FoundScenario.postUpdate(newscene) 
				}	

				case "eteindre clim chateau":
				{	 
					VarFoundScenario=newscene  
					Clim_4.sendCommand("OFF")
					Clim_4.postUpdate("OFF")
					 	
				//	FoundScenario.postUpdate(newscene) 
				}					
				

				case "allume clim maison":
				{ 
					VarFoundScenario=newscene 
					Clim_4.sendCommand("ON")
					Clim_4.postUpdate(ON)
					
					Clim_3.sendCommand("ON")
					Clim_3.postUpdate(ON)				//	FoundScenario.postUpdate(newscene) 
			
					Clim_2.sendCommand("ON")
					Clim_2.postUpdate(ON)				//	FoundScenario.postUpdate(newscene) 
			

					Clim_1.sendCommand("ON")
					Clim_1.postUpdate(ON)				//	FoundScenario.postUpdate(newscene) 
					FoundScenario.postUpdate(newscene) 
			
				}	



				case "eteindre clim maison":
				{	 
					VarFoundScenario=newscene  
					Clim_4.sendCommand("OFF")
					Clim_4.postUpdate("OFF")
					Clim_3.sendCommand("OFF")
					Clim_3.postUpdate("OFF")
					Clim_2.sendCommand("OFF")
					Clim_2.postUpdate("OFF")
					Clim_1.sendCommand("OFF")
					Clim_1.postUpdate("OFF")
				//	FoundScenario.postUpdate(newscene) 
				}					
				


				case "eteindre salon":
				{	 
					VarFoundScenario=newscene  

					Clim_1.sendCommand("OFF")
					Clim_1.postUpdate("OFF")

					LG_P_Power.sendCommand("OFF")
					LG_P_Power.postUpdate(OFF )
					SP2_2.sendCommand("OFF")
					SP2_2.postUpdate("OFF")
				}

				case "eteindre lumieres maison":
				{	 

					VarFoundScenario=newscene  

				}

				case "eteindre chambre parents":
				{	 
					VarFoundScenario=newscene  

					Clim_2.sendCommand("OFF")
					Clim_2.postUpdate("OFF")

					ZWaveSwitch1_Channel1_Right.sendCommand(OFF)
					ZWaveSwitch1_Channel2_Left.sendCommand(OFF)	  	
			
					led_desk.sendCommand("OFF")
					led_desk.postUpdate("OFF")

				}

                case "allume bar",
				case "allume ilot",
				case "allume barre":
				{	 
					VarFoundScenario=newscene
					SP2_2.sendCommand("ON")
					SP2_2.postUpdate(ON)				 	 
				//	FoundScenario.postUpdate(newscene) 
				}	

                case "eteindre ilot",
				case "eteindre bar" ,
				case "eteindre barre":
				{	 
					VarFoundScenario=newscene
					SP2_2.sendCommand("OFF")
					SP2_2.postUpdate("OFF")				 	 
				//	FoundScenario.postUpdate(newscene) 
				}	


				case "allume chauffage":
				{	 
					VarFoundScenario=newscene
					SP2_1.sendCommand("ON")
					SP2_1.postUpdate(ON)				 	 
				//	FoundScenario.postUpdate(newscene) 
				}	

 				case "eteindre chauffage":
				{	 
					VarFoundScenario=newscene
					SP2_1.sendCommand("OFF")
					SP2_1.postUpdate("OFF")				 
					 
				//	FoundScenario.postUpdate(newscene) 
				}					

				 case "allume bureau" :
				{ 
					VarFoundScenario=newscene
					//sonoff_desk.sendCommand("ON")
					//sonoff_desk.postUpdate(ON )
					
					led_desk.sendCommand("ON")
					Thread::sleep(1)	
					led_desk.sendCommand("turkey2")
					led_desk.postUpdate("turkey2")	
				//	FoundScenario.postUpdate(newscene) 
				}	


				 case "eteindre bureau" :
        			{ 
					VarFoundScenario=newscene 
					//	//sonoff_desk.sendCommand("OFF")
					//	//sonoff_desk.postUpdate("OFF")

					led_desk.sendCommand("OFF")
					led_desk.postUpdate("OFF")
				//	FoundScenario.postUpdate(newscene) 
				}


				 case "allume routeur" :
				{ 
					VarFoundScenario=newscene
					//sonoff_desk.sendCommand("ON")
					//sonoff_desk.postUpdate(ON )	
				//	FoundScenario.postUpdate(newscene) 
				}	

				}
	  case "lock",
				  case "verrouille",
				  case "arme":
				
				  
				{
				//HomeStatus.sendCommand("bye")
				HomeStatus.postUpdate("lock")
				//logInfo("Scene Bye", "Start on all devices: " + receivedCommand)	
				VarFoundScenario="lock"
				/* Switcher.sendCommand("OFF")
				Switcher.postUpdate("OFF")
				
				TerraseSwitch2.sendCommand("OFF")
				TerraseSwitch2.postUpdate("OFF")
				
				Toilets.sendCommand("OFF")
				Toilets.postUpdate("OFF")
				
				sdblight.sendCommand("OFF")
				sdblight.postUpdate("OFF")
				
				appliqueSwitch.sendCommand("OFF")
				appliqueSwitch.postUpdate("OFF")  
				
				
				SP2_1.sendCommand("OFF")
				SP2_1.postUpdate("OFF")
				SP2_2.sendCommand("OFF")
				SP2_2.postUpdate("OFF")		
				LG_Power_Proxy.sendCommand("OFF")
				LG_Power_Proxy.postUpdate("OFF")
				
				
				//	M1_1.sendCommapdate(OFF)
				
				//M1_2.sendCommand("OFF_M2")
				//M1_2.postUpdate("OFF")_M2" )
				
				//M1_3.sendCommand("OFF_M3")nd("OFF")
				//	M1_1.postU
				//M1_3.postUpdate("OFF")_M3" )
				//M1_4.sendCommand("OFF_M4")
				//M1_4.postUpdate("OFF")_M4" )
				Clim_1.sendCommand("OFF")
				Clim_1.postUpdate("OFF")
				
				Clim_2.sendCommand("OFF")
				Clim_2.postUpdate("OFF")
				
				Clim_3.sendCommand("OFF")
				Clim_3.postUpdate("OFF")

				Clim_4.sendCommand("OFF")
				Clim_4.postUpdate("OFF")
								
				ZWaveSwitch1_Channel2_Left.sendCommand(OFF) 
				ZWaveSwitch1_Channel2_Left.postUpdate( OFF ) 
				
				ZWaveSwitch1_Channel1_Right.sendCommand(OFF) 
				ZWaveSwitch1_Channel1_Right.postUpdate( OFF ) 
				
				
				TV.sendCommand("OFF")
				TV.postUpdate("OFF")
				
				led_desk.sendCommand("OFF")
				led_desk.postUpdate("OFF")


				led_mini2.sendCommand("OFF")
				led_mini2.postUpdate("OFF")

				led_mini3.sendCommand("OFF")
				led_mini3.postUpdate("OFF")
				

				
				LG_P_Power.sendCommand("OFF")
				LG_P_Power.postUpdate(OFF )
				
				logInfo("Bye", "End on all devices: ")
				 */
				 VarFoundScenario=newscene
				//FoundScenario.postUpdate(newscene) 
				//sendTelegram("bot1", "SCENE BYE triggered: Salon except clim, Toilets,Terrase,Switcher,SDB , douche, clim parents, clim noya")    
				}

        case "telephone gil",
		case "gil telephone":				{
				VarFoundScenario="wmd_gil"
				logInfo("WMD RING", newscene)	
				wmd_global.sendCommand("wmd_gil")
				wmd_global.postUpdate("wmd_gil")
				
				//FoundScenario.postUpdate(newscene) 
				}
		case "musique gil",
		case "musique gili",
		case "musique billy",
		case "musique guili",
		case "guili musique",

		case "gili sonne",
		case "gil sonne":
				{
				VarFoundScenario="ring_gil"
				logInfo("WMD RING", newscene)	
				wmd_global.sendCommand("ring_gil")
				wmd_global.postUpdate("ring_gil")
				
				//FoundScenario.postUpdate(newscene) 
				}

        case "telephone karen",
		case "karen telephone",
		case "karen  téléphone",
		case "téléphone karen":
				{
				VarFoundScenario=newscene
				logInfo("WMD RING", newscene)	
				wmd_global.sendCommand("wmd_karen")
				wmd_global.postUpdate("wmd_karen")
				}

        case "telephone heni",
		case "heni telephone":
				{
				VarFoundScenario=newscene
				logInfo("WMD RING", newscene)	
				wmd_global.sendCommand("wmd_heni")
				wmd_global.postUpdate("wmd_heni")
						//	FoundScenario.postUpdate(newscene) 
				}
......................................
......................................

......................................


        case "telephone noya",
		case "noya telephone",
		case "telephone nono",
		case "nono telephone":

				{
					VarFoundScenario=newscene
					logInfo("WMD RING", newscene)	
					wmd_global.sendCommand("wmd_noya")
					wmd_global.postUpdate("wmd_noya")
				}

		case "allume pc":
			{
					VarFoundScenario=newscene
			}
		case "volume 10":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(10)
		//			LG_TV0_Volume.postUpdate(10)
			}

		case "volume 30":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(30)
		//			LG_TV0_Volume.postUpdate(30)
			}
		case "volume 40":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(40)
		//			LG_TV0_Volume.postUpdate(30)
			}
		case "volume 50":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(50)
		//			LG_TV0_Volume.postUpdate(50)
			}

		case "volume 60":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(60)
		//			LG_TV0_Volume.postUpdate(60)
			}

		case "volume 70":
			{
					VarFoundScenario=newscene
					LG_TV0_Volume.sendCommand(70)
		//			LG_TV0_Volume.postUpdate(70)
			}

		case "silence salon":
			{
						
					VarFoundScenario=newscene

					irobot.sendCommand("irobot_pause")
					irobot.postUpdate("irobot_pause")
				
				
					LG_TV0_Mute.sendCommand("ON")
					LG_TV0_Mute.postUpdate(ON)
				
					ChromecastAudio_Control.sendCommand("PAUSE")
					ChromecastAudio_Control.postUpdate("PAUSE")
			}	
			
		case "silence chambre":
			{
						
					TV_vol.sendCommand("Tvmute")
					TV_vol.postUpdate("mute")
		
					VarFoundScenario=newscene
			}	

					case "toaster",
					case "toaster 5 minutes":
			{
						
					SP2_3.sendCommand("ON")
					SP2_3.postUpdate(ON)
		
					VarFoundScenario=newscene

      				ToasterTimer = createTimer(now.plusMinutes(5 ), [|
            		SP2_3.sendCommand(OFF)
            		ToasterTimer = null
					say("Le toast est prêt. bon appetit")
        			])




			}	


					case "toaster 10 minutes":
			{
						
					SP2_3.sendCommand("ON")
					SP2_3.postUpdate(ON)
					VarFoundScenario=newscene

      				ToasterTimer = createTimer(now.plusMinutes(10 ), [|
            		SP2_3.sendCommand(OFF)
            		ToasterTimer = null
					say("Le toast est prêt. bon appetit")
        			])
			}		


					case "eteindre toaster":
			{
						
					SP2_3.sendCommand("OFF")
					SP2_3.postUpdate(OFF)
					VarFoundScenario=newscene

					say("oui monsieur")
        			
			}		


			
}
	logInfo("Scenario", "-----------------------------------------------------------------------")
	optionFound="_Closed"
	logInfo("Scenario ", "--END OF CLOSED OPTIONS---"+"VarFoundScenario= "+ VarFoundScenario  )	 

//Bloc 2 End Options ////////

	//FoundScenario.postUpdate(VarFoundScenario) 
	

//Bloc 3 start Options ////////


if (VarFoundScenario.contains("NULL")){		
			if ( newscene.contains("turn off")  || newscene.contains("tein")|| newscene.contains("eteindre")){
						logInfo("cmd ", "OFF" )	
						cmd = "OFF"
			}

			if ( newscene.contains("turn on")  || newscene.contains("allume") ){
				cmd = "ON"
			}

			if ( newscene.contains("switcher 60m") ){
				Switcher.sendCommand("60m")
				VarFoundScenario="allume eau chaude 60"

			}

			if (newscene.contains("allume eau chaude")  || newscene.contains("allume dude")){
				Switcher.sendCommand("30m")
				VarFoundScenario="allume eau chaude"
			}


			if ( newscene.contains("switcher 30m") ){
				Switcher.sendCommand("30m")
				VarFoundScenario="allume eau chaude 30"
			}


 		 	if (newscene.contains("eteindre eau chaude")  || newscene.contains("eteindre dude")){
			   Switcher.sendCommand("OFF")						//	Switcher.postUpdate("OFF")
				VarFoundScenario="stop eau chaude"
	        }

			if (newscene.contains("bain") || newscene.contains("ben"))  {
				logInfo("cmd ", "bain: " + cmd )	

						if (cmd=== null) {
							switch (sdblight.state.toString) 
								{
									case "OFF" :
									{
										cmd = "ON"       
									}
									case "ON" :
									{
										cmd = "OFF"       
									}
								}
							}

							VarFoundScenario="Salle de Bain_" +cmd

						sdblight.sendCommand(cmd)
						sdblight.postUpdate(cmd)

						appliqueSwitch.sendCommand(cmd)
						appliqueSwitch.postUpdate(cmd)  

						SP2_1.sendCommand(cmd)
						SP2_1.postUpdate(cmd)
						}

			
			if (newscene.contains("douche")) {
				logInfo("douche ", "douche: " )	
				if (cmd === null) {
				switch (ZWaveSwitch1_Channel1_Right.state.toString) 
					{
							case "OFF",
							case "off" :
							{
								cmd = "ON"       
							}
							case "ON",
							case "on" :
							{
								cmd = "OFF"       
							}
					}
				}
				VarFoundScenario="douche_" +cmd
				ZWaveSwitch1_Channel1_Right.sendCommand(cmd)
				ZWaveSwitch1_Channel2_Left.sendCommand(cmd)
			}

			if ( newscene.contains("romantique")  || newscene.contains("amour") || newscene.contains("sexe") || newscene.contains("sex")){
									VarFoundScenario="romantique"
									led_desk.sendCommand("on")
									Thread::sleep(2)	
									led_desk.sendCommand("red")
									led_desk.postUpdate("red")
									//sonoff_desk.sendCommand("OFF")
									//sonoff_desk.postUpdate("OFF")
									// +cmd
			}

			if ( newscene.contains("led")){
									VarFoundScenario="led  off"// +cmd
									led_desk.sendCommand("OFF")
									led_desk.postUpdate("OFF")
			}

			if ( newscene.contains("vert")){
									VarFoundScenario="led  green"// +cmd
									led_desk.sendCommand("ON")
									Thread::sleep(2)	
									led_desk.sendCommand("green")
									led_desk.postUpdate("green")
									
			}

			if ( newscene.contains("blanc")){
									VarFoundScenario="led  white"// +cmd
									led_desk.sendCommand("ON")
									Thread::sleep(2)	
									led_desk.sendCommand("white")
									led_desk.postUpdate("white")
			}


			if (newscene.contains("toilettes") || newscene.contains("toilette")) {
				logInfo("cmd ", "toilettes: current state " + Toilets.state.toString )

				if (cmd=== null) {
				switch (Toilets.state.toString) 
					{
							case "OFF" :
							{
							cmd = "ON" 
							//publish("mosquitto", "broadlink/mqtt_M1_1/power", "1/ON")  
								Toilets.sendCommand("ON")
								Toilets.postUpdate(ON)
							}
							case "ON" :
							{
								cmd="OFF"
								Toilets.sendCommand("OFF")
								Toilets.postUpdate("OFF")
							}
					}
					VarFoundScenario="Toilets_" +cmd
				}	
			}


			if (newscene.contains("terrase") || newscene.contains("terrasse")) {
				logInfo("cmd ", "terrase: current state " + TerraseSwitch2.state.toString )
				if (cmd=== null) {
						switch (TerraseSwitch2.state.toString) 
						{				
									case "OFF" :
									{
										cmd = "ON" 
										//publish("mosquitto", "broadlink/mqtt_M1_1/power", "1/ON")  
										TerraseSwitch2.sendCommand("ON")
										TerraseSwitch2.postUpdate(ON)
									}
									case "ON" :
									{
										cmd="OFF"
										TerraseSwitch2.sendCommand("OFF")
										TerraseSwitch2.postUpdate("OFF")
									}
						}
						VarFoundScenario="Terrasse_" +cmd
				}	
			}


		if (newscene.contains("ilot") || newscene.contains("bar")) {
						logInfo("cmd ", "ilot: current state " + SP2_2.state.toString )
						if (cmd=== null) 
						{
								switch (SP2_2.state.toString) 
								{				
											case "OFF" :
											{
												cmd = "ON" 
												//publish("mosquitto", "broadlink/mqtt_M1_1/power", "1/ON")  
												SP2_2.sendCommand("ON")
												SP2_2.postUpdate(ON)
											}
											case "ON" :
											{
												cmd="OFF"
												SP2_2.sendCommand("OFF")
												SP2_2.postUpdate("OFF")
											}
								}
											VarFoundScenario="ilot_" +cmd
						}	
					
		}



///###########################################################################################

			if (newscene.contains("clim salon") || newscene.contains("salon clim")) {
				logInfo("cmd ", "Salon: current state " + Clim_1.state.toString )

			//	if (cmd=== null) {

				switch (Clim_1.state.toString) 
					{
							case "OFF" :
							{
							  cmd = "ON" 
								Clim_1.sendCommand("ON")
								Clim_1.postUpdate(ON)
								

							}
							case "ON" :
							{
								cmd="OFF"
								Clim_1.sendCommand("OFF")
								Clim_1.postUpdate("OFF")
							}
					}
					VarFoundScenario="Clim_1_" + cmd
			//	}	
			}



			if (newscene.contains("clim doudou") || newscene.contains("doudou clim")) {
				logInfo("cmd ", "Salon: current state " + Clim_1.state.toString )

			//	if (cmd=== null) {
				switch (Clim_1.state.toString) 
					{
							case "OFF" :
							{
							  cmd = "ON" 
								Clim_4.sendCommand("ON")
								Clim_4.postUpdate(ON)

							}
							case "ON" :
							{
								cmd="OFF"
								Clim_4.sendCommand("OFF")
								Clim_4.postUpdate("OFF")
							}
					}
					VarFoundScenario="Clim_1_" + cmd
			//	}	
			}
		

			
			if (newscene.contains("clim parents") || newscene.contains("parents clim")) {
				logInfo("cmd ", "parents: current state " + Clim_2.state.toString )

				if (cmd=== null) {
				switch (Clim_2.state.toString) 
					{
							case "OFF" :
							{
							  cmd = "ON" 
								Clim_2.sendCommand("ON")
								Clim_2.postUpdate(ON)
							}
							case "ON" :
							{
								cmd="OFF"
								Clim_2.sendCommand("OFF")
								Clim_2.postUpdate("OFF")
							}
					}
					VarFoundScenario="Clim_2_" +cmd
				}	
			}
			
			
			
				if (newscene.contains("clim nono") || newscene.contains("nono clim")) {
				logInfo("cmd ", "nono: current state " + Clim_3.state.toString )

				if (cmd=== null) {
				switch (Clim_3.state.toString) 
					{
							case "OFF" :
							{
							  cmd = "ON" 
								Clim_3.sendCommand("ON")
								Clim_3.postUpdate(ON)
							}
							case "cold" :
							{
								cmd="OFF"
								Clim_3.sendCommand("OFF")
								Clim_3.postUpdate("OFF")
							}
					}
					VarFoundScenario="Clim_3_" +cmd
				}	
			}



//########################################################################
		//	if (newscene.contains("led")) {
		//		logInfo("cmd ", "led: current state " + led_desk.state.toString )
//		//
		//		if (cmd=== null) {
		//		switch (led_desk.state.toString) 
		//			{
		//					case "OFF" :
		//					{
		//					  cmd = "ON" 
		//							led_desk.sendCommand("ON")
		//							Thread::sleep(10)	
		//							led_desk.sendCommand("green")
		//							led_desk.postUpdate("green")
		//					}
		//					default:
		//					{
		//						cmd="off"
		//						led_desk.sendCommand("OFF")
		//						led_desk.postUpdate("OFF")
		//					}
		//			}
		//			VarFoundScenario="led_desk_" +cmd
		//		}	
		//	}
		

//##############################################


}



	if (newscene.contains("tele") && newscene.contains("parents"))
	{
	logInfo("cmd ", "tele: current state " + LG_P_Power.state.toString )
		if (LP_Switch.state == OFF )
			{
						
				if (cmd=== null)
				{
					switch (TV.state.toString) 
					{
									case "OFF" :
									{
									cmd = "ON" 
									//publish("mosquitto", "broadlink/mqtt_M1_1/power", "1/ON")  
									TV.sendCommand("ON")
									TV.postUpdate(ON )
									}
									case "ON" :
									{
									cmd = "OFF" 
									TV.sendCommand("OFF")
									TV.postUpdate(OFF )     
									}
									
					}
								VarFoundScenario="TV_Parents" +cmd

				}
			}	
	}

	
	if (newscene.contains("tele") )
	{
	logInfo("cmd ", "tele: current state " + LG_P_Power.state.toString )
		if (LP_Switch.state == OFF )
			{
						
				if (cmd=== null)
				{
					switch (LG_P_Power.state.toString) 
					{
									case "OFF" :
									{
									cmd = "ON" 
									//publish("mosquitto", "broadlink/mqtt_M1_1/power", "1/ON")  
									LG_P_Power.sendCommand("ON")
									LG_P_Power.postUpdate(ON )
									}
									case "ON" :
									{
									cmd = "OFF" 
									LG_P_Power.sendCommand("OFF")
									LG_P_Power.postUpdate(OFF )     
									}
									
					}
								VarFoundScenario="TV_" +cmd
				}
			}	
			optionFound="-Opened"
	}

	if	(optionFound!="_Closed"){
			logInfo("Scenario", "-----------------------------------------------------------------------")
			logInfo("Scenario ","VarFoundScenario= "+ VarFoundScenario  )	 
			logInfo("Scenario ", "-----END OF OPENED OPTIONS----" +"VarFoundScenario= "+ VarFoundScenario  )	 
}

//Bloc 3 end Options ////////

switch VarFoundScenario{
			case "NULL":{
			VarFoundScenario=newscene+"_ISSUE"
			logInfo("Scenario ", "-----NOT FOUND----" +VarFoundScenario )	 
//					if(Bot2_Enabled.state == ON){sendTelegram("bot6", VarFoundScenario +"--NOT FOUND--")}				
			}
}			
//			default:{
				FoundScenario.postUpdate(VarFoundScenario) 	
				var String ifttt_key = "d-gsjc-"
				var String notification_json
				val String currentTime = String::format( "%1$tl:%1$tM%1$tp on %1$tA, %1$tB %1$te, %1$tY", new java.util.Date )
				//var lastItem = TriggerGlobalScene.previousState().state.toString
				var lastItem = TriggerGlobalScene.state.toString
				// Avoid sending the alert if the state didn't change
				// Compare state before update and now
				//    var lastState = lastItem.historicState(lastItem.lastUpdate.toDateTime.minusSeconds(1))
				

				var String ifttt_url = "https://maker.ifttt.com/trigger/"+TriggerGlobalScene.state.toString + "/with/key/" + ifttt_key
				var String TriggerStripped =TriggerGlobalScene.state.toString 
				TriggerStripped =TriggerStripped.replace('','_')
				//logInfo("ifttt_url", ifttt_url)
				//notification_json = '{"value1":"' + lastItem + '","value2":"' +  VarFoundScenario +'","value3":"' + currentTime + '"}'
				//logInfo("IFTT",    "sendHttpPostRequest : " + notification_json)
				//sendHttpPostRequest(ifttt_url, "application/json", notification_json)//,8000)	

				//Thread::sleep(10)	
				ifttt_url = "https://maker.ifttt.com/trigger/GlobalScene/with/key/" + ifttt_key
				logInfo("ifttt_url", ifttt_url)
				var String FoundScenarioStripped =VarFoundScenario
				FoundScenarioStripped =FoundScenarioStripped.replace(' ','_')
				notification_json = '{"value1":"' + lastItem + '","value2":"' +  FoundScenarioStripped +optionFound+'","value3":"' + currentTime + '"}'
		//		WebhookUrl.postUpdate(ifttt_url)

				logInfo("notification_json = ", notification_json)	 
				var String myquery = String::format("curl@@-X@@POST@@-H@@Content-Type: application/json@@-d@@"+notification_json + "@@"+ifttt_url)
	
				logInfo("myquery = ", myquery)
				val results = executeCommandLine(myquery, 5000)
				//val results = executeCommandLine("/usr/bin/curl -X POST " +ifttt_url, 5000)
				logInfo("results", results)
end

Well, the reason is, you have typos in there. This rule is really disgusting, It’s not manageable.

As a first point, there should be no need to do a .sendCommand() and a .postUpdate() for the same item, as openHAB will do the .postUpdate() itself (if you don’t configure the item to autoupdate="false")
A second point, please use a code editor such as VSCode or Notepad++, both will tell you that the brace level has errors.
Please pay attention to the level by indenting lines with the same level to the same tab.
Please delete all commented code, as this will only make it more complex to follow the non existent structure…

Please consider to split the rule into less long rules. As far as I understood this rule is a parser for complete sentences. As I don’t speak french (hope this is french…) I have no idea how to parse this in a correct way.

1 Like

I’ll second Udo’s suggestion to use VSCode with the openHAB extension. And it is not necessary to send a command and an update, the command is sufficient.

Have a look at Design Pattern: How to Structure a Rule and A simple scene management: finally a good use of scripts for some ideas you might be able to use to simplify this rule somewhat.

1 Like