import java.util.Date
rule "Alarmanlage"
when
Item Windows changed to OPEN
then
if (sAlarmanlage.state == ON) {
Windows.members.forEach(contacts|
if (contacts.state == OPEN) {
sendTelegram("iPhone", "Alarmmeldung:\n" + "Alarmanlage wurde ausgelöst\n" + contacts.name 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) ]
}
)
}
end
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
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 org.openhab.library.tel.types.CallType
import java.util.Map
rule "Fritzbox Active Call ON"
when
Item Active_Call changed from OFF to ON or
Item Active_Call_Out changed from OFF to ON
then
// 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("192.168.2.152",3005, subject, text, "", 10000)
sendCommand(PlexWZPause,OFF)
}
var String url = "http://xxx:9001/status?p0=display&p1=&p2=" + text.encode("UTF-8") + "&p3=60&player=mac1" //WZ
sendHttpGetRequest(url)
url = "http://xxx:9001/status?p0=display&p1=&p2=" + text.encode("UTF-8") + "&p3=60&player=mac2" //SZ
sendHttpGetRequest(url)
}
// 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)
end
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.
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
I’ll be back, when I know more or I need further assistance.