Rule from OH1 does not run in OH2

Hi together,

i do have the following rule:

import java.util.Date

rule "Alarmanlage"
    Item Windows changed to OPEN
      if (sAlarmanlage.state == ON) {
        	if (contacts.state == OPEN) {
        		sendTelegram("iPhone", "Alarmmeldung:\n" + "Alarmanlage wurde ausgelöst\n" + as String + " wurde geöffnet"
        		+ " um " + String::format("%1$tH:%1$tM:%1$tS", new Date() ))
					sendCommand(z_Wendeltreppe_Sirene, ON)	
					sendCommand(RauchmelderNebenstellenalarm, ON)
    				createTimer(now.plusSeconds(300)) [| sendCommand(z_Wendeltreppe_Sirene, OFF) ]
    				createTimer(now.plusSeconds(300)) [| sendCommand(RauchmelderNebenstellenalarm, OFF) ]

The rule does activate a siren when a window is opened.

With OH1 everything worked fine but after the migration to OH2 it does not work anymore and openhab.log says:

2017-02-04 18:17:29.767 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Alarmanlage': cannot invoke method public org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.items.GenericItem.getState() on null

It is complaining about the if(sAlarmanlage.state == ON) {

Does this Items exist in your OH 2?

Is this Item’s state defined?

Because of the same heading, I add my problem here as well. I’ve a rule which runs on my OH1 but doesn’t on OH2
The rule:

import org.openhab.model.script.actions.*
import java.lang.Math
import java.util.Map

rule "Fritzbox Active Call ON"
     Item Active_Call changed from OFF to ON or
     Item Active_Call_Out changed from OFF to ON
 	// Zeigt Telefonnummer oder Name des Anrufers am Plex und Squeezebox Display
     if (Active_Call.state==ON) {
 	    val CallType incCall = fboxIncomingCallResolved.state as CallType
 	    var String caller = "" + incCall.destNum //destNum is external number OR resolved Name if no phonebook entry exists
 		var String text= "Eingehender Anruf: " + caller
 	    logInfo("RSS", text)		
 		if (PlexWZPower.state==ON) {
 			sendXbmcNotification("",3005, subject, text, "", 10000)
 		var String url = "http://xxx:9001/status?p0=display&p1=&p2=" + text.encode("UTF-8") + "&p3=60&player=mac1" //WZ
 		url = "http://xxx:9001/status?p0=display&p1=&p2=" + text.encode("UTF-8") + "&p3=60&player=mac2" //SZ
 	// reduce volumes at squeezeboxes
 	volumes = storeStates(sq_wohnen_volume, sq_gaeste_volume, sq_schlafen_volume, sq_bad_volume)
 	sendCommand(sq_wohnen_volume, 20)
 	sendCommand(sq_schlafen_volume, 20)
 	sendCommand(sq_bad_volume, 20)
 	sendCommand(sq_gaeste_volume, 20)		

The error:

2017-02-06 18:51:50.561 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Fritzbox Active Call ON’: void

I’ve no idea, what Rule Fritzbox Active Call ON: void means.

Don’t import anything from org.openhab any more. It all gets imported for your now and they have all moved somewhere else besides.

That could be the cause, though I doubt it.

Add some logging to see if you can tell:

  • is the rule body even being triggered?
  • which line is it failing on?

This binding seems to have a lot of additional behaviors like the Call Item type and CallType states. Have you searched around on the forum to see if one needs to do anything special to work with these binding specific types? You might indeed need the import after all for CallType.

Do you see any parsing errors when OH starts up?

Thanks for your hints. I removed the imports, which solved the Rule … void problem. Nevertheless the rule doesn’t match. I’m going to dig deeper into the rule. The items Active_Call and Active_Call_Out do their job and change when phone is ringing or a call is outgoing.
I don’t understand why the rule works in OH1 but doesn’t in OH2. This means, I have to test any of my rules, to get sure to get the same function as before :frowning:

I’ll be back, when I know more or I need further assistance.

I need to try this, when I’m at home. Sounds this could be the solution :slight_smile:

Edit: this was the solution :slight_smile:

Yes the items exists and has the state ON:
2017-02-12 13:05:14.979 [INFO ] [.eclipse.smarthome.model.script.Test] - sAlarmanlage=ON

Could it be that one of the ‘contacts’ of the forEach loop is uninitialized and throws the error?

There shouldn’t be any errors if there are contacts that are not initialized. Your == OPEN would just evaluate to false.