I'd like to receive a notification (via Rule Machine or the Notification app) whenever a code is added to or deleted from my lock. But I can't find a way to do this.
I have a rule to add a code on certain dates, then remove it later. I'd like a notification so that I know this has been done. An independent notification triggered by the lock itself is best. But the only triggers I can find are for the door being locked or unlocked. There is a "lock code" trigger, but that only tells me when a code is USED, not set or deleted.
I tried that, but all I could see that it gave me was the last code used to open the door. It didn't trigger when the code was added to the lock, only when the door was opened via a code.
OK -- better. I got a notification when the code was added. Do you know if there is any way to indicate WHICH code was added or deleted? I was hoping the "%text" attribute would tell me something, but it doesn't. Is there a list somewhere of the "%%" codes that can be added to a notification message in this case??
Glad you got that part working (it wouldn't make sense for it to work as in your other post; I suspect you were using lastCodeName instead.)
There isn't an easy way to get the specific change, but %value% will give you the current list. The Rule Machine docs list all the builtin variables like this, though the page you're on (in the UI) normally does too.
Thanks -- but all I get for %value% is "added" or "deleted", not which user or code was added or deleted. For my current purposes this is OK, as I'll rarely be doing this and should know which code it was that was triggered on any given day -- I won't have cleaners coming in on the same day as guests. Having the user name associated with the code would be nice, but I can live without it.
This can't happen. It would be the current value of the attribute (or really the one that made the rule trigger, usually the same at this point). I think you're using the wrong attribute again, this time possibly codeChanged (which does create events with such values). You want to use lockCodes for this as I mentioned above.
OK, I see. Yes, I am using codeChanged. But lockCodes reports something lock code related, which is encrypted. So I can see something changed, but unless I turn off the encryption I can't see WHAT changed. I was hoping for then name of the last code added or deleted.
Watch the logs for what's coming through. Create your own global variable. Call it %code-added%. When it comes through the log, send that info to %code added% and have the notification say Current code %code-added% as been add to door lock X
Ok, yeah, you're going to have that problem if you look at that attribute no matter what then. Is there a reason you have encryption turned on? It only affects display in the UI, not any actual functionality. Adding hub login security or other restrictive measures are more appropriate if you're worried a about someone obtaining the codes (and if they can get this far, they can just unlock the lock there in the first place). You'd still have the issue of there being an easy way to do this since it involves JSON parsing, but it would at least be possible (even if it's just sending both the old and new lists) or easier witha custom app.
You are right that when I turn off encryption, I get better info. I got the complete list of door codes. But paranoid as I am, I really don't what THAT data being sent across who knows what servers to my phone (I'm using Pushover for notifications). So I'll leave encryption on and just live with getting only "code added/code deleted" messages. That is less than I'd prefer, but enough for my needs.
Sounds promising, but you completely lost me at "When it comes through the log..." I'd have to trigger an action based on a particular kind of log message, parse that message, and set a variable based on what I find. None of that sounds like anything I've seen anywhere. Maybe that can be done with some custom code, but I don't need this THAT badly...
Really? Do you know of an example anywhere that I could look at? I'm poking around in Rule Machine and don't see anything remotely like any of that.
Well, I just found the "token" option for setting a variable in the documentation, but how all this would interact with the logging is not at all clear...
Very interesting. So not the log per se, but catching the same info the log would. Unfortunately, the "code changed" %text% is empty. I'll have to go back to the unencrypted "lockCodes" and have to then parse that. If I can get that far then maybe have it just send a list of "currently active codes" by username. That would be safe to send in plaintext, and tell me everything I need to know. So I guess I need now to figure out how to parse the JSON from the unencrypted lock codes...
But probably not today...
The %text% value will depend on the specific driver; specifically, it's whatever you see in the "description text" column on "Events" under the device detail page. While it's optional and may not be set for all events, often it's just something like "Dimmer X switch is on," so ultimately something that can be deduced from other event data.
It should be noted that this isn't really looking at logs per se; it just so happens that most drivers put this information out as an "info" log when the event happens (if you have that preference enabled in the driver -- and it's a stock driver or other that follows this convention). There's no official way to actually do that, but there are some community solutions that may work, but you'd need to verify that that data is even there in the first place, which I don't recall offhand (can't say I've seen it, but I've also never looked; and it's a very rare event for me).
One alternative: how are you setting the codes now? If it's something like LCM, you could use a Rule to add and remove the code manually, then you'll at least know when that happens since it's entirely under your control (true either way, I suppose, so I guess the point here is that you can also add a notification in the rule or whatever you want). By "that happens," I mean that the command was sent to the lock. Whether it responds is another story. That is what the event like lockCodes changing will tell you. This isn't impossible to tell; you could have a "Wait for events" in your rule for this event after sending the command, possibly with a timeout, then assume that if the timeout happened, the code didn't change and if it was the actual event, then it did. With encryption, you won't be able to get the actual codes that were added or removed, but because you did it in the rule, you'll at least know what it should have been and can act appropriately.