[SOLVED] Error occurred during the script execution: index=1, size=1

Hi,

i have a switch to turn on the Hot water.

i can trigger turn on the script for 30m, 60m, 90m.

i just want that to add a timer to change automatically the status off after that the duration was selected

My configuration:

  • RASPBERRY PI 3 MODEL B+
  • openHAB 2.3.0 Release Build
String      Switcher	        "Hot water"				<Switcher>                                  (gAll,gChart,gHistory,gBye,gNight)
String      Switcher_Mode        "Mode"				<Switcher>                                  (gAll,gChart,gHistory,gBye,gNight)
var Timer myTimer  = null    
//import org.openhab.model.script.actions.Timer

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Switcher"
when
   Item  Switcher received command
then 

	switcher_LastUpdate.postUpdate(new DateTimeType())
 	switch (receivedCommand) {
                case "OFF" :
				{   
				    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py 0")
				    if(Switcher.state==Switcher.previousState ) {return;}
					if(Bot5_Enabled.state == ON){sendTelegram("bot5", "דוד מצב :" + receivedCommand )}  
				}

                case "ON" :
				{

					switch (Switcher_Mode.state.toString){		
							
						case "30m",
						case "30" :
					{
						executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t30")
						if(Bot5_Enabled.state == ON){sendTelegram("bot5", "דוד מצב :" + receivedCommand )}  
							
						myTimer = createTimer(now.plusSeconds(30) [
						Switcher.postUpdate("OFF")
 						myTimer = null   // reset the timer

						])

					}
						case "60m",
						case "60" :
					{
						if(Bot5_Enabled.state == ON){sendTelegram("bot5", "דוד מצב :" + receivedCommand )}  
						executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t60")
					
						myTimer = createTimer(now.plusMinutes(60) [
						Switcher.postUpdate("OFF")
						myTimer = null   // reset the timer

						])
					}
						case "90m",
						case "90" :
					{  	
						executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t90")
						if(Bot5_Enabled.state == ON){sendTelegram("bot5", "דוד מצב :" + receivedCommand )}  
						myTimer = createTimer(now.plusMinutes(90) [
						Switcher.postUpdate("OFF")
						myTimer = null   // reset the timer
						])	
					}

				}
         }
	 }
end

Sitemap

The off works but when Selecting ON.

see logs below :slight_smile:

2018-10-15 13:42:44.071 [ome.event.ItemCommandEvent] - Item 'Switcher' received command ON

==> /var/log/openhab2/openhab.log <==
2018-10-15 13:42:44.161 [INFO ] [.script.Switcher_Mode.state.toString] - 30m

==> /var/log/openhab2/events.log <==
2018-10-15 13:42:44.219 [vent.ItemStateChangedEvent] - Switcher changed from OFF to ON
2018-10-15 13:42:44.225 [GroupItemStateChangedEvent] - gBye changed from OFF to ON through Switcher

==> /var/log/openhab2/openhab.log <==
2018-10-15 13:42:44.234 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t30'

==> /var/log/openhab2/events.log <==
2018-10-15 13:42:44.254 [GroupItemStateChangedEvent] - gNight changed from OFF to ON through Switcher
2018-10-15 13:42:44.302 [vent.ItemStateChangedEvent] - switcher_LastUpdate changed from 2018-10-15T13:38:22.327+0300 to 2018-10-15T13:42:44.137+0300

==> /var/log/openhab2/openhab.log <==
2018-10-15 13:42:44.907 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Switcher': An error occurred during the script execution: index=1, size=1

==> /var/log/openhab2/events.log <==
2018-10-15 13:42:44.992 [vent.ChannelTriggeredEvent] - logreader:reader:openhablog:newErrorEvent triggered 2018-10-15 13:42:44.907 **[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Switcher': An error occurred during the script execution: index=1, size=1**

any help would be more than appreciated

You are missing a , in your timer declarations:

                    myTimer = createTimer(now.plusSeconds(30), [
                        Switcher.postUpdate("OFF")
                         myTimer = null   // reset the timer
                    ])

So your rule is now:

rule "Switcher"
when
    Item  Switcher received command
then 
    switcher_LastUpdate.postUpdate(new DateTimeType())
    switch (receivedCommand) {
        case "OFF" : {   
            executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py 0")
            if(Switcher.state == Switcher.previousState) return;
            if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
        }
        case "ON" : {
            switch (Switcher_Mode.state.toString) {        
                case "30m", case "30" :{
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t30")
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                    myTimer = createTimer(now.plusSeconds(30), [
                        Switcher.postUpdate("OFF")
                         myTimer = null   // reset the timer
                    ])
                }
                case "60m", case "60" : {
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t60")
                    myTimer = createTimer(now.plusMinutes(60), [
                        Switcher.postUpdate("OFF")
                        myTimer = null   // reset the timer
                    ])
                }
                case "90m", case "90" : {      
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t90")
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                    myTimer = createTimer(now.plusMinutes(90), [
                        Switcher.postUpdate("OFF")
                        myTimer = null   // reset the timer
                    ])    
                }
            }
        }
    }
end
2 Likes

Thanks for you answer (as usual :))

but i am getting another issue:

==> /var/log/openhab2/openhab.log <== 2018-10-15 14:48:32.843 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Switcher’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: rules.rules#|::0.2.0.2.0.1.1.1.1.0.0.1.1.1.0.2::0::/1) ==> /var/log/openhab2/events.log <== 2018-10-15 14:48:32.944 [vent.ChannelTriggeredEvent] - logreader:reader:openhablog:newErrorEvent triggered 2018-10-15 14:48:32.843 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Switcher’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: rules.rules#|::0.2.0.2.0.1.1.1.1.0.0.1.1.1.0.2::0::/1)

Check that the timer in not null before creating it.

@vzorglub seems we recently discussed this in a different topic.:smile: For this rule your absolutely correct the , keeps it clean, as this is more than one line. Nice work Vincent!

The final code which works :slight_smile:

var Timer myTimer = null

rule "Switcher"
when
    Item  Switcher received command
then 
    switcher_LastUpdate.postUpdate(new DateTimeType())
    switch (receivedCommand) {
        case "OFF" : {   
            executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py 0")
            if(Switcher.state == Switcher.previousState) return;
            if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
           
        }
        case "ON" : {
            switch (Switcher_Mode.state.toString) {        
                case "30m", case "30" :{
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t30")
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                  		
                        myTimer = createTimer(now.plusMinutes(30), [
                        Switcher.postUpdate("OFF")
                         myTimer = null   // reset the timer
                    ])
                }
                case "60m", case "60" : {
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t60")
                    myTimer = createTimer(now.plusMinutes(60), [
                        Switcher.postUpdate("OFF")
                        myTimer = null   // reset the timer
                    ])
                }
                case "90m", case "90" : {      
                    executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t90")
                    if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
                    myTimer = createTimer(now.plusMinutes(90), [
                        Switcher.postUpdate("OFF")
                        myTimer = null   // reset the timer
                    ])    
                }
            }
        }
    }
end

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


We can probably remove about 15 lines on code from this rule by extracting the minutes value, parsing it into an int and get rid of the second switch case

1 Like

Apology OP. @vzorglub Since your here---- ferrite beads, ferrite beads!!! The leads at the esp were longer than I remembered, about 6", snapped on a ferrite bead and good so far.:crossed_fingers:

This should do the job, I hope:

rule "Switcher"
when
    Item  Switcher received command
then 
    switcher_LastUpdate.postUpdate(new DateTimeType())
    switch (receivedCommand) {
        case "OFF" : {   
            executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py 0")
            if(Switcher.state == Switcher.previousState) return;
            if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
           
        }
        case "ON" : {
            val String switcherModeString = Switcher_Mode.state.toString.substring(0,1)
            val int minutesValue = Integer::parseInt(switcherModeString)
            executeCommandLine ("python /etc/openhab2/scripts/Switcher-V2-Python/switcher.py t" + switcherModeString)
            if(Bot5_Enabled.state == ON) sendTelegram("bot5", "דוד מצב :" + receivedCommand )
            myTimer = createTimer(now.plusMinutes(minutesValue), [
                Switcher.postUpdate("OFF")
                myTimer = null   // reset the timer
            ])
        }
    }
end

Thanks a lot

substring is really useful

Please tick the solution post, thanks

I have the same error with my rule?

My configuration:

  • RASPBERRY PI 3 MODEL B+
  • OpenHAB 2.5.0 Build #1485

My Items

Contact garageDoorContact           "garage door contact [MAP(contact.map):%s]"   
Switch GarageDoor_Timer { expire="10m,command=OFF" }

And here is my Rule:

Rule "Garage Door Sensor changed"
when
    Item garageDoorContact changed from CLOSED to OPEN
then
    logInfo("Garage Door contact changed" + triggeringItem.state.toString)
    sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)  
    
	if (triggeringItem.state == OPEN) {
        GarageDoor_Timer.sendCommand(ON)  // Start timer
        sendBroadcastNotification(" Garage Door OPEN ")
    } else {
        GarageDoor_Timer.postUpdate(OFF) // Cancel timer
    }
end

Error

2019-01-23 06:48:56.584 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1

Any help would be appreciated.

First rule not Rule
Second your rule makes no sense
triggeringItem.state will ALWAYS be OPEN because that’s how you trigger the rule:

rule "Garage Door Sensor changed"
when
    Item garageDoorContact changed
then
    if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
    logInfo("Garage Door contact changed" + triggeringItem.state.toString)
    sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)  
    if (triggeringItem.state == OPEN) {
        GarageDoor_Timer.sendCommand(ON)  // Start timer
    } else {
        GarageDoor_Timer.postUpdate(OFF) // resets the timer
end

rule "Garage door timer expired"
when
    GarageDoor_Timer received command OFF
then
    sendBoradcastNotification"Garage door it still open after 10m")
end

Thanks for the quick response.

I tried your changes and I got the following error?

New rule

rule "Garage Door Sensor changed"
when
    Item garageDoorContact changed
then
    if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
    logInfo("Garage Door contact changed" + triggeringItem.state.toString)
    sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)  
    if (triggeringItem.state == OPEN) {
        GarageDoor_Timer.sendCommand(ON)        // Start timer
    } else {
        GarageDoor_Timer.postUpdate(OFF)        // resets the timer
    }    
end


rule "Garage door timer expired"
when
    GarageDoor_Timer received command OFF   // this is 332
then
    sendBoradcastNotification("Garage door it still open after 10m")
end

Error

2019-01-23 09:45:46.217 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'our_house.rules' has errors, therefore ignoring it: [332,5]: no viable alternative at input 'GarageDoor_Timer'



???

My fault:

rule "Garage door timer expired"
when
    Item GarageDoor_Timer received command OFF   // this is 332
then
    sendBoradcastNotification("Garage door it still open after 10m")
end

Got it, I missed that as well…

Thanks, I will test later today.

Well I just tested

Here’s the door open error?

2019-01-23 11:35:51.156 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1


and the close error?

2019-01-23 11:36:32.156 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1


for the following :slight_smile:

rule "Garage Door Sensor changed"
when
    Item garageDoorContact changed
then
    if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
    logInfo("Garage Door contact changed" + triggeringItem.state.toString)
    sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)  
    if (triggeringItem.state == OPEN) {
        GarageDoor_Timer.sendCommand(ON)        // Start timer
    } else {
        GarageDoor_Timer.postUpdate(OFF)        // resets the timer
    }    

end


rule "Garage door timer expired"
when
    Item GarageDoor_Timer received command OFF
then
    logInfo("Garage Door ", " Opened for 10 min.")
    sendBoradcastNotification("Garage door it still open after 10m")
end

Any Ideas?

Put a loginfo on the first line of the rule

Same error?

2019-01-23 11:55:35.693 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Garage Door Sensor changed': An error occurred during the script execution: index=1, size=1

With this?

rule "Garage Door Sensor changed"
when
    Item garageDoorContact changed
then
    logInfo("Garage Door contact changed - Then")
    if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return; //Invalid state: Do nothing
    logInfo("Garage Door contact changed" + triggeringItem.state.toString)
    sendBroadcastNotification("Garage Door " + triggeringItem.state.toString)  
    if (triggeringItem.state == OPEN) {
        GarageDoor_Timer.sendCommand(ON)        // Start timer
    } else {
        GarageDoor_Timer.postUpdate(OFF)        // resets the timer
    }    

end


rule "Garage door timer expired"
when
    Item GarageDoor_Timer received command OFF
then
    logInfo("Garage Door ", " Opened for 10 min.")
    sendBoradcastNotification("Garage door it still open after 10m")
end

2 rules with the same name?
I don’t know…