It was Triggered by me unlocking and locking the door to change the state.
Here is the rule:
rule "Front Lock Update lock states after alarm events"
when
Item Lock_MF_Dining_Alarm received update
then
postUpdate(EventLog, “Front Door: Updated + lockevent”)
var Number lockevent = Integer::parseInt(transform(“JSONPATH”, “$.event”, “Lock_MF_Dining_Alarm.state.toString”))
if (lockevent == 1 || lockevent == 5 || lockevent == 3) {
Lock_MF_Dining_Proxy.postUpdate(ON)
postUpdate(EventLog, “Front Door: LOCKED”)
}
else if (lockevent == 2 || lockevent == 6 || lockevent == 4) {
Lock_MF_Dining_Proxy.postUpdate(OFF)
postUpdate(EventLog, “Front Door: UNLOCKED”)
}
else if (lockevent == 11) {
postUpdate(EventLog, “Front Door: JAMMED”)
}
end
Here is the proxy rule:
rule "Front Lock Proxy Status Updates"
when
Item Lock_MF_Dining_Proxy received command
then
Lock_MF_Dining_Lock.sendCommand(receivedCommand)
val notificationNumber = if (receivedCommand == ON) 3 else 4
Lock_MF_Dining_Alarm.postUpdate(notificationNumber)
end
The error was due to the quotes around the input string…
var Number lockevent = Integer::parseInt(transform(“JSONPATH”, “$.event”, “Lock_MF_Dining_Alarm.state.toString”))
See if this helps. Let me know if you’d like explanations for any of it.
rule "Front Lock Update lock states after alarm events"
when
Item Lock_MF_Dining_Alarm received update
then
switch (transform("JSONPATH","$.type",Lock_MF_Dining_Alarm.state.toString)) {
case "ACCESS_CONTROL" : {
switch (transform("JSONPATH", "$.event", Lock_MF_Dining_Alarm.state.toString)) {
case "1", case "3", case "5" : {
Lock_MF_Dining.postUpdate(ON)
postUpdate(EventLog, "Front Door: LOCKED")
}
case "2", case "4", case "6" : {
Lock_MF_Dining.postUpdate(OFF)
postUpdate(EventLog, "Front Door: UNLOCKED")
}
case "11" : {
postUpdate(EventLog, "Front Door: JAMMED")
}
}
}
case "BURGLAR" : {
postUpdate(EventLog, "Front Door: BURGLAR")
}
}
end
All you need are these items (a proxy item is not needed):
String Lock_MF_Dining_Alarm "Front Lock Alarm" {channel="zwave:device:8fe51373:node41:alarm_raw"}
Switch Lock_MF_Dining "Front Lock" {channel="zwave:device:8fe51373:node41:lock_door"}
An important thing to note is that the way your rule was written, if you had the alarm mode set to anything but disabled, lock picking, or a kick, or anything else that would have set off the tamper alarm (sends an event 6) would have unlocked the door! Filter on the type first.
Thank you, This is a great rule and good catch on the tamper alarm.
Now that I see the rule and walk through it I think I understand it.
You are welcome… I’m happy to have helped out! If you want a little more functionality, look at the rule and lambda I linked to, which also includes handling of user codes, and will prep you for when/if you add a second lock. Eventually, I will be adding some other missing events that are in the specification, which these locks may or may not fully support (user code deleted/added, keypad busy/disabled, new program code entered, etc.)
Hello folks I noticed that this post should solve my issue of not being able to get status updates from my locks. The question is I see two different ways to tackle the problem. Post 27 and post 39 on this thread. Can someone explain what the difference is between both and is there somewhere I can get all the info together? I have read all 65 posts and since I am rather new to openhab it’s a little confusing to me.
From reading the concept seems like you are using the Lambda to allow for reuse of code which I think is great. I would like to use the new alarm_raw channel as that is where I see movement in my logs.
In using the code from @5iver on post 39 I am getting an error when I save the file.
2018-04-22 20:19:39.723 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'lock.rules' has errors, therefore ignoring it: [7,45]: mismatched character ' ' expecting ']'
[7,51]: no viable alternative at input '|'
[8,5]: missing EOF at 'logDebug'
Do you mean this rule and lambda?
Try again… I just updated it. You must be using a recent snapshot build of OH. There was a change where lambdas need a space inside the square brackets.
Hello - I know this is old, but I was trying to follow along with what you did. I’ve got the following rule as a way to get started:
rule “Backdoor Lock Update”
whenItem vBackdoorLock received update
then
var LockalarmNotification = transform(“JSONPATH”,"$.notification", BackDoorLock_AlarmRaw.toString)
logInfo(“BackdoorNotification”, BackDoorLock_AlarmRaw.toString)
end
However my log file shows:
2018-06-25 21:25:00.029 [INFO ] [home.model.script.Backdoor LockEvent] - BackDoorLock_AlarmRaw (Type=StringItem, State={“notification”:“ACCESS_CONTROL__MANUAL_UNLOCK”,“level”:“1”,“type”:“ACCESS_CONTROL”,“event”:“2”,“status”:“255”}, Label=null, Category=null)
How do I get it to where I can separately pull out the notification, the type, the event, and the status separately?
Thank you!
Look two posts up for a link to another post with a full setup. Just set up the items with your device info and you should be up and running.
Thanks. Was a stupid error. I had not installed the JSON transformation yet.
Hi all (& @5iver)
I’ve been spending much of today skimming through this thread and the new secure z-wave development thread to try and sort out an answer to this, but have been having difficulty.
I have 3 Schlage Connect BE469 locks that I’m hoping will be able to be integrated with OpenHab2. It appears they should be able to work with their alarm, lock and unlock features. Is it possible to program user codes from OpenHab? Is there a better way to do this (and manage rules/time/day restrictions for each user code)?
If not currently in place, is this on the near roadmap?
Thanks!
(& Thanks @chris for all of your rapid and involved development work on OpenHab & the new secure inclusion developments!)
BDM
Yes, you can program user codes (I don’t). Here’s what it looks like in Habmin…
As for rules, you can trigger events when a code is used (you can find some of that in my example rule), but you wouldn’t be able to put in restrictions. Well, you could probably modify the codes through the REST API, but it would be better to add some channels in the device db for this.
Thanks @5iver, this is helpful.
Is it this lack of ability to apply rules ( by which I mean the cleaner code only works on given days/ times) that causes you to not use OH2 to program your locks?
Is it the (apparent) limitation to 5 ( rather than 30) codes?
What do you use to program the codes instead?
Thanks
BDM
We have 5 locks and I prefer to just manually configure the codes. We’ve also chosen to not automate anything involving secure access (garage doors don’t open, locks don’t unlock, etc.). We also work from home, so someone can always answer the door, but also wouldn’t trust anyone to be inside our house unsupervised .
There are 30 slots available. TMK, all can be configured through OH, but I could be wrong.
I am running OH 2.3 with latest Z-wave add-on. (not experimental). I was able to discover Schlage BE469 but can’t get it to work (lock/unlock). Do I have to use beta Z-wave binding (2.4), or 2.3 should be fine ?
I deleted thing and added again. Now it shows as unknown device.
You need the dev version. No other version has security. For lock/unlock status, you need a rule.
[Edit: sceurity was merged into master before the 2.4 stable release.]
So I’m finally working to fine-tune my smart lock set-up. I have several Schlage BE469’s, that have largely been working as simple keypad locks until now (with the addition of a few features like a button to lock everything down).
I’m now trying to set up these lock rules, but am running into challenges. I’m running openhabian 2.4 with a razberry pi hat - no apparent issues with the z-wave connections to the locks.
My issue seems to be in getting / setting the item states:
Rule ‘Lock: Update lock states after alarm_raw event’: cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
In looking at other suggestions on this topic, I’ve looked into my persistence.
I am using mapdb for default persistence (and use influxdb for grafana). The first statement should have worked, but I added the gLock group as well to ensure it was captured. I have restarted my openhab instance several times after making changes, as well as restarted the raspberry pi.
As I’m still a bit of a novice with OpenHab, I’m at a bit of a loss as to my next steps to try and debug this further. I’ve attached my relevant items, rules and persist files, as well as the relevant sections from the log. I’d appreciate any/all suggestions!
mapdb.persist
Strategies {
}
Items {
*: strategy = everyChange, restoreOnStartup
gLock* : strategy = everyChange, restoreOnStartup, everyHour
}
locks.rules
rule "Lock: Update lock states after alarm_raw event"
when
Item FF_Garage_Lock_Alarm_Raw received update
or
Item FF_Entryway_Lock_Alarm_Raw received update
or
Item FF_MudroomEntry_Lock_Alarm_Raw received update
or
Item FF_MasterBedroom_Lock_Alarm_Raw received update
or
Item FF_Kitchen_Lock_Alarm_Raw received update
or
Item C_Entryway_Lock_Alarm_Raw received update
then
val actionItem = gLock.members.findFirst[ item | item.name.toString == triggeringItem.name.toString.replace("_Alarm_Raw","") ]
logInfo("locks.rules", "Starting Lock Update Raw Event Rule")
logDebug("Rules", "Lock: Alarm events: {}=[{}]",actionItem.name,triggeringItem.state.toString)
switch (transform("JSONPATH","$.type",triggeringItem.state.toString)) {
case "ACCESS_CONTROL" : {
switch (transform("JSONPATH", "$.event", triggeringItem.state.toString)) {
case "1", case "3", case "5" : {
actionItem.postUpdate(ON)
logDebug("Rules", "Lock: Alarm events: {} updated to ON (locked)",actionItem.name)
}
case "2", case "4" : {
actionItem.postUpdate(OFF)
logDebug("Rules", "Lock: Alarm events: {} updated to OFF (unlocked)",actionItem.name)
}
case "6" : {
actionItem.postUpdate(OFF)
val StringBuilder message = new StringBuilder(actionItem.name)
message.append(" was unlocked with")
switch (transform("JSONPATH", "$.code", triggeringItem.state.toString)) {
case "1" : {
message.append(" user code 1")
}
case "2" : {
message.append(" user code 2")
}
}
logDebug("Rules", "Lock: {}",message.toString)
sendMail("myemail@gmail.com", "Test Message", message)
//SMS_Notification.sendCommand(message.toString)
//Kodi_Notification.sendCommand(message.toString)
}
case "11" : {
logDebug("Rules", "Lock: Alarm events: {} is jammed, so setting lock to OFF (unlocked)",actionItem.label)
actionItem.postUpdate(OFF)
//SMS_Notification.sendCommand(actionItem.label + " is jammed")
//Kodi_Notification.sendCommand(actionItem.label + " is jammed")
}
case "16" : {
val String message = actionItem.label + " keypad is disabled due to too many failed codes"
logDebug("Rules", "Lock: Alarm events: {}",message)
endMail("myemail@gmail.com", "Lock Keypad Disabled - too many failed codes", message)
//SMS_Notification.sendCommand(message)
//Kodi_Notification.sendCommand(message)
}
default : {
val String message = "Unknown door lock Event, " + triggeringItem.state.toString
logDebug("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
}
}
if (transform("JSONPATH", "$.event", triggeringItem.previousState(true).state.toString) == "11" && transform("JSONPATH", "$.event", triggeringItem.state.toString) != "11") {
val String message = actionItem.label + " is no longer jammed"
logDebug("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
//Kodi_Notification.sendCommand(message)
}
}
case "BURGLAR" : {
//gSiren.sendCommand(ON)
val String message = "Intruder at " + actionItem.label
logDebug("Rules", "Lock: Alarm events: {}",message)
sendMail("1234567890@msg.telus.com", "Burglar Alarm", message)
sendMail("myemail@gmail.com", "Burglar Alarm", message)
//SMS_Notification.sendCommand(message)
//Audio_Notification.sendCommand(message)
}
case "POWER_MANAGEMENT" : {
val String message = "Power Management alarm for " + actionItem.label + ", " + triggeringItem.state.toString
logDebug("Rules", "Lock: Alarm events: {}",message)
sendMail("myemail@gmail.com", "Lock Power Alarm", message)
//SMS_Notification.sendCommand(message)
}
default : {
val String message = "Unknown Type in alarmRawParser, " + triggeringItem.state.toString
logDebug("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
}
}
/*
Example text from alarm raw event from one of my locks
FF_MasterBedroom_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
*/
end
locks.items
/* locks moved from default.items. some groups may still cross over */
/* See locks rules file for parsing and management of the raw alarm string */
Group:Switch:OR(OFF,ON) gLock "Locks [MAP(lock.map):%s]" <lock> (Home)
Switch FF_Garage_Lock "Lock (Garage) [MAP(lock.map):%s]" <lock> (FF_Garage, gLock) {channel="zwave:device:713fde47:node18:lock_door"}
String FF_Garage_Lock_Alarm_Raw "Lock (Garage) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node18:alarm_raw"}
Switch FF_Entryway_Lock "Lock (Main Entry) [MAP(lock.map):%s]" <lock> (FF_Entryway, gLock) {channel="zwave:device:713fde47:node12:lock_door"}
String FF_Entryway_Lock_Alarm_Raw "Lock (Main Entry) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node12:alarm_raw"}
Switch FF_MudroomEntry_Lock "Lock (Mudroom Entry) [MAP(lock.map):%s]" <lock> (FF_Hallway, gLock) {channel="zwave:device:713fde47:node17:lock_door"}
String FF_MudroomEntry_Lock_Alarm_Raw "Lock (Mudroom Entry) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node17:alarm_raw"}
Switch FF_MasterBedroom_Lock "Lock (Master Entry) [MAP(lock.map):%s]" <lock> (FF_MasterBedroom, gLock) {channel="zwave:device:713fde47:node19:lock_door"}
String FF_MasterBedroom_Lock_Alarm_Raw "Lock (Master Entry) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node19:alarm_raw"}
Switch FF_Kitchen_Lock "Lock (Kitchen Entry) [MAP(lock.map):%s]" <lock> (FF_Kitchen, gLock) {channel="zwave:device:713fde47:node14:lock_door"}
String FF_Kitchen_Lock_Alarm_Raw "Lock (Kitchen Entry) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node14:alarm_raw"}
Switch C_Entryway_Lock "Lock (Carriage House Entry) [MAP(lock.map):%s]" <lock> (C_Entryway, gLock) {channel="zwave:device:713fde47:node18:lock_door"}
String C_Entryway_Lock_Alarm_Raw "Lock (Carriage House Entry) : Alarm Raw [%s]" <shield> {channel="zwave:device:713fde47:node18:alarm_raw"}
logs:
2019-05-11 13:12:33.740 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 13:12:33.759 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
[...]
2019-05-11 13:12:45.330 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
2019-05-11 13:12:45.337 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 13:12:45.359 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 13:12:45.388 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
2019-05-11 13:12:45.388 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 1
==> /var/log/openhab2/events.log <==
2019-05-11 13:12:45.394 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from OFF to ON
[...]
2019-05-11 13:12:49.968 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}
2019-05-11 13:12:49.974 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 13:12:49.990 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
==> /var/log/openhab2/events.log <==
2019-05-11 13:12:50.028 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from ON to OFF
==> /var/log/openhab2/openhab.log <==
2019-05-11 13:12:50.028 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 0
2019-05-11 13:12:50.025 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': An error occurred during the script execution: Could not invoke method: org.openhab.action.mail.internal.Mail.sendMail(java.lang.String,java.lang.String,java.lang.String) on instance: null
==> /var/log/openhab2/events.log <==
[...]
2019-05-11 13:12:55.757 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"} to {"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}
2019-05-11 13:12:55.764 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"} to {"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 13:12:55.779 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
==> /var/log/openhab2/events.log <==
2019-05-11 13:12:55.791 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from OFF to ON
==> /var/log/openhab2/openhab.log <==
2019-05-11 13:12:55.795 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 1
2019-05-11 13:12:55.798 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
==> /var/log/openhab2/events.log <==
[...]
So I noticed a couple errors, potential fixes based on other posts and looking through my code.
- I didn’t have the ALARM_RAW items as part of the gLock group, which has been suggested elsewhere. Done now.
- I didn’t have the logging set to DEBUG for the rule engine. After hunting through the config file for the appropriate line, I ended up just changing the rule to logInfo instead of log debug. I then captured a fresh log, below.
- I had missed a door in the items file, and incorrectly duplicated a door’s node number (insignificant to this case, but fixed nonetheless as I’ll need it correct in the future)
I’m still having the same problem. In the log you can see me unlock the Entryway lock (manually), lock it (using the keypad schlage button), then unlock it (using the code), and finally lock it manually again.
Edit: Incorrect: I’ve noticed the error seems to occur after manual lock/unlock, and not the key codes.
Edit: Update after looking through
Manual Unlock (Event Code 2) -> Error
Keypad Lock (Event Code 5) - > Eventually, Error
Keypad Unlock (Event Code 6) -> No error, reported user code used as expected
Manual Lock (Event Code 1) -> Eventually, Error
.
Any ideas for next steps?
–
JSONPath Transformation installed
Persistence settings:
PaperUi > Configuration > System >Persistence > Default Service > mapdb
(Incidentally, I have the gLock group in both influxdb.persist and mapdb.persist , as I had been wanting to be able to use the building access data in grafana. Could this be part of the problem?)
.
mapdb.persist
Strategies {
}
Items {
*: strategy = everyChange, restoreOnStartup
gLock* : strategy = everyChange, restoreOnStartup, everyHour
}
influxdb.persist
Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
every2Minutes : "0 */2 * ? * *"
every5Minutes : "0 */5 * ? * *"
every15Minutes : "0 */15 * ? * *"
}
Items {
gTemperatureItems*: strategy = everyHour, everyChange
gHumidityItems*: strategy = everyHour, everyChange
gMotionItems*: strategy = every15Minutes, everyChange
gAnyRecentMotion*: strategy = every15Minutes, everyChange
gLightSensorItems*: strategy = everyHour, everyChange
gWeatherTemp*, gWeatherHumidity*: strategy = everyHour
Presence_Sensors*: strategy = every15Minutes, everyChange
gLock*: strategy = everyHour, everyChange
}
items:
/* locks moved from default.items. some groups may still cross over */
/* See locks rules file for parsing and management of the raw alarm string */
Group:Switch:OR(OFF,ON) gLock "Locks [MAP(lock.map):%s]" <lock> (Home)
Switch FF_Garage_Lock "Lock (Garage) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node18:lock_door"}
String FF_Garage_Lock_Alarm_Raw "Lock (Garage) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node18:alarm_raw"}
Switch FF_Entryway_Lock "Lock (Main Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node12:lock_door"}
String FF_Entryway_Lock_Alarm_Raw "Lock (Main Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node12:alarm_raw"}
Switch FF_MudroomEntry_Lock "Lock (Mudroom Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node17:lock_door"}
String FF_MudroomEntry_Lock_Alarm_Raw "Lock (Mudroom Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node17:alarm_raw"}
Switch FF_MasterBedroom_Lock "Lock (Master Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node19:lock_door"}
String FF_MasterBedroom_Lock_Alarm_Raw "Lock (Master Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node19:alarm_raw"}
Switch FF_Kitchen_Lock "Lock (Kitchen Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node14:lock_door"}
String FF_Kitchen_Lock_Alarm_Raw "Lock (Kitchen Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node14:alarm_raw"}
Switch F2_Entryway_Lock "Lock (Second Floor Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node20:lock_door"}
String F2_Entryway_Lock_Alarm_Raw "Lock (Second Floor Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node20:alarm_raw"}
Switch CH_Entryway_Lock "Lock (Carriage House Entry) [MAP(lock.map):%s]" <lock> (gLock) {channel="zwave:device:713fde47:node16:lock_door"}
String CH_Entryway_Lock_Alarm_Raw "Lock (Carriage House Entry) : Alarm Raw [%s]" <shield> (gLock) {channel="zwave:device:713fde47:node16:alarm_raw"}
Rule:
rule "Lock: Update lock states after alarm_raw event"
when
Item FF_Garage_Lock_Alarm_Raw received update
or
Item FF_Entryway_Lock_Alarm_Raw received update
or
Item FF_MudroomEntry_Lock_Alarm_Raw received update
or
Item FF_MasterBedroom_Lock_Alarm_Raw received update
or
Item FF_Kitchen_Lock_Alarm_Raw received update
or
Item F2_Entryway_Lock_Alarm_Raw received update
or
Item CH_Entryway_Lock_Alarm_Raw received update
then
val actionItem = gLock.members.findFirst[ item | item.name.toString == triggeringItem.name.toString.replace("_Alarm_Raw","") ]
logInfo("locks.rules", "Starting Lock Update Raw Event Rule")
logInfo("Rules", "Lock: Alarm events: {}=[{}]",actionItem.name,triggeringItem.state.toString)
switch (transform("JSONPATH","$.type",triggeringItem.state.toString)) {
case "ACCESS_CONTROL" : {
switch (transform("JSONPATH", "$.event", triggeringItem.state.toString)) {
case "1", case "3", case "5" : {
actionItem.postUpdate(ON)
logInfo("Rules", "Lock: Alarm events: {} updated to ON (locked)",actionItem.name)
}
case "2", case "4" : {
actionItem.postUpdate(OFF)
logInfo("Rules", "Lock: Alarm events: {} updated to OFF (unlocked)",actionItem.name)
}
case "6" : {
actionItem.postUpdate(OFF)
val StringBuilder message = new StringBuilder(actionItem.name)
message.append(" was unlocked with")
switch (transform("JSONPATH", "$.code", triggeringItem.state.toString)) {
case "1" : {
message.append(" user code 1")
}
case "2" : {
message.append(" user code 2")
}
}
logInfo("Rules", "Lock: {}",message.toString)
sendMail("anemailaddress@gmail.com", "Test Message", message.toString)
//SMS_Notification.sendCommand(message.toString)
//Kodi_Notification.sendCommand(message.toString)
}
case "11" : {
logInfo("Rules", "Lock: Alarm events: {} is jammed, so setting lock to OFF (unlocked)",actionItem.label)
actionItem.postUpdate(OFF)
//SMS_Notification.sendCommand(actionItem.label + " is jammed")
//Kodi_Notification.sendCommand(actionItem.label + " is jammed")
}
case "16" : {
val String message = actionItem.label + " keypad is disabled due to too many failed codes"
logInfo("Rules", "Lock: Alarm events: {}",message)
sendMail("anemailaddress@gmail.com", "Lock Keypad Disabled - too many failed codes", message.toString)
//SMS_Notification.sendCommand(message)
//Kodi_Notification.sendCommand(message)
}
default : {
val String message = "Unknown door lock Event, " + triggeringItem.state.toString
logInfo("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
}
}
if (transform("JSONPATH", "$.event", triggeringItem.previousState(true).state.toString) == "11" && transform("JSONPATH", "$.event", triggeringItem.state.toString) != "11") {
val String message = actionItem.label + " is no longer jammed"
logInfo("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
//Kodi_Notification.sendCommand(message)
}
}
case "BURGLAR" : {
//gSiren.sendCommand(ON)
val String message = "Intruder at " + actionItem.label
logInfo("Rules", "Lock: Alarm events: {}",message)
sendMail("1234567890@msg.telus.com", "Burglar Alarm", message)
sendMail("anemailaddress@gmail.com", "Burglar Alarm", message)
//SMS_Notification.sendCommand(message)
//Audio_Notification.sendCommand(message)
}
case "POWER_MANAGEMENT" : {
val String message = "Power Management alarm for " + actionItem.label + ", " + triggeringItem.state.toString
logInfo("Rules", "Lock: Alarm events: {}",message)
sendMail("anemailaddress@gmail.com", "Lock Power Alarm", message)
//SMS_Notification.sendCommand(message)
}
default : {
val String message = "Unknown Type in alarmRawParser, " + triggeringItem.state.toString
logInfo("Rules", "Lock: Alarm events: {}",message)
//SMS_Notification.sendCommand(message)
}
}
/*
FF_MasterBedroom_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
*/
end
Log file:
2019-05-11 17:21:42.503 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 17:21:42.509 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock=[{"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"}]
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:42.525 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from ON to OFF
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:42.523 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock updated to OFF (unlocked)
2019-05-11 17:21:42.525 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 0
2019-05-11 17:21:42.535 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
==> /var/log/openhab2/events.log <==
[...]
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:44.337 [DEBUG] [.internal.InfluxDBPersistenceService] - got String value {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:44.342 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
2019-05-11 17:21:44.350 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__MANUAL_UNLOCK","level":"1","type":"ACCESS_CONTROL","event":"2","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:44.371 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 17:21:44.376 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock=[{"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"}]
2019-05-11 17:21:44.387 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock updated to ON (locked)
2019-05-11 17:21:44.392 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 1
2019-05-11 17:21:44.394 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:44.397 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from OFF to ON
[...]
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:48.266 [DEBUG] [.internal.InfluxDBPersistenceService] - got String value {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:48.279 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}
2019-05-11 17:21:48.284 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_LOCK","level":"0","type":"ACCESS_CONTROL","event":"5","status":"255"} to {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:48.298 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 17:21:48.304 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock=[{"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"}]
2019-05-11 17:21:48.324 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 0
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:48.324 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from ON to OFF
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:48.331 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: FF_Entryway_Lock was unlocked with user code 2
==> /var/log/openhab2/events.log <==
[...]
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:50.189 [DEBUG] [.internal.InfluxDBPersistenceService] - got String value {"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:50.202 [vent.ItemStateChangedEvent] - FF_Entryway_Lock_Alarm_Raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"} to {"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}
2019-05-11 17:21:50.206 [vent.ItemStateChangedEvent] - zwave_device_713fde47_node12_alarm_raw changed from {"notification":"ACCESS_CONTROL__KEYPAD_UNLOCK","code":"2","level":"2","type":"ACCESS_CONTROL","event":"6","status":"255"} to {"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:50.225 [INFO ] [e.smarthome.model.script.locks.rules] - Starting Lock Update Raw Event Rule
2019-05-11 17:21:50.230 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock=[{"notification":"ACCESS_CONTROL__MANUAL_LOCK","level":"1","type":"ACCESS_CONTROL","event":"1","status":"255"}]
2019-05-11 17:21:50.244 [DEBUG] [.internal.InfluxDBPersistenceService] - got OnOffType value 1
==> /var/log/openhab2/events.log <==
2019-05-11 17:21:50.251 [vent.ItemStateChangedEvent] - FF_Entryway_Lock changed from OFF to ON
==> /var/log/openhab2/openhab.log <==
2019-05-11 17:21:50.254 [INFO ] [eclipse.smarthome.model.script.Rules] - Lock: Alarm events: FF_Entryway_Lock updated to ON (locked)
2019-05-11 17:21:50.260 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
2019-05-11 17:21:50.897 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract org.eclipse.smarthome.core.types.State org.eclipse.smarthome.core.persistence.HistoricItem.getState() on null
.
Remove them from there, add a gLockRaw group and put them in there. Add that group to persistence. Then use one trigger…
Member of gLockRaw received update
It seems like your locks are not persisting their data. My guess is that your default persistence is mapdb (you can check/change this in Paper UI or runtime.cfg. You do not have any strategies defined in your mapdb persist. You will need to add them…
Another thing you can try is to use…
if (transform("JSONPATH", "$.event", triggeringItem.previousState(true, "influxdb").state.toString) == "11" && transform("JSONPATH", "$.event", triggeringItem.state.toString) != "11") {
There are some related discussions in this thread around post 145…
A couple of comments:
Try temporarily removing the whole “if (transform …” for the no longer jammed. That’s the only place using previousState. This is nice to have, but you don’t absolutely need it. Do all of your issues go away?
I do not like to put the raw alarm into persistence. If you do, you’ll find that if the system restarts, and your cases do anything interesting, you’ll make those things happen again depending on the last activity. For me this could mean turning on or off the alarm or sending unwanted messages. I did the following so I get history without using persistence. If there is a restart, the entries will be null, but I don’t care too much about the jammed state during a restart.
At the top of the rule:
import java.util.Map
// retain the old event for each lock
// not using persistence as don't want the rule to fire
// on an update at startup and do weird things
var Map<String, Number> messageOldEvents = newHashMap
Then, at the case “ACCESS_CONTROL” I add this:
val messageEvent = transform("JSONPATH","$.event",triggeringItem.state.toSt
ring)
// should be null if not in hashmap, won't compare below
var messageOldEvent = messageOldEvents.get(actionItem.name.toString)
messageOldEvents.put(actionItem.name.toString, messageEvent)
Finally, my test for unjammed looks like this:
if (messageOldEvent == "11" && messageEvent != "11") {
val String message = actionItem.label + " is no longer jammed"
logInfo("Rules", "Lock: Alarm events: {}",message)
sendMail("myemail@email.com",actionItem.label, message)
}
Thanks a lot @5iver and @jswim788. I will start out with the mapdb strategies ( hadn’t realized I hadn’t defined these), the gLockRaw fine-tuning, and then go on from there.
=============
Edit/Update: I’ve fixed the mapdb.persist strategies, refined the gLocRaw in the items file, mapdb persist file, and updated the rules to trigger when a member of the gLockRaw group is updated. The rule still correctly fires with an update from a lock, however the error is still thrown, likely indicating the locks are still not persisting.
FYI, my new persist files:
mapdb.persist
Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
every2Minutes : "0 */2 * ? * *"
every5Minutes : "0 */5 * ? * *"
every15Minutes : "0 */15 * ? * *"
default = everyChange
}
Items {
*: strategy = everyChange, restoreOnStartup
gLock* : strategy = everyChange, restoreOnStartup, everyHour
gLockRaw* : strategy = everyChange, everyHour
}
influxdb.persist
Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
every2Minutes : "0 */2 * ? * *"
every5Minutes : "0 */5 * ? * *"
every15Minutes : "0 */15 * ? * *"
default = everyChange
}
Items {
gTemperatureItems*: strategy = everyHour, everyChange
gHumidityItems*: strategy = everyHour, everyChange
gMotionItems*: strategy = every15Minutes, everyChange
gAnyRecentMotion*: strategy = every15Minutes, everyChange
gLightSensorItems*: strategy = everyHour, everyChange
gWeatherTemp*, gWeatherHumidity*: strategy = everyHour
Presence_Sensors*: strategy = every15Minutes, everyChange
gLock*: strategy = everyHour, everyChange
}
=============
InfluxDB notifications show up in the log as it’s set to log at debug level (no idea when this was set, it wasn’t from me). I don’t think mapdb is set to this, but I’ll look into what mapdb is getting for persistence after.
@jswim788 I like how clean your lock jammed code is. I will explore this further if the first steps don’t resolve it.
Cheers