Rule Machine + Lock Code Manager: Check if a randomly generated code is already in use

I run a small business out of my house and need to generate a new lock code daily for employees. I also have roommates, and we each have a number of codes that are kept private and don't change often.

I'm attempting to create a RM automation that generates a random 6-digit number, checks it against the existing lock codes for a conflict (i.e. if that code already exists), then replaces the old employee code (always in the 28th slot) with the new code.

I've been able to get everything to work except for the conflict check. My z-wave keypad using the Generic Z-wave Lock Driver (I couldn't find a generic keypad driver) which has been working perfectly for all my other automations. I can replace the lock code just fine, but I can't find a way to get RM to access any of the lock codes.

The closest I've gotten is using a custom action to send the getCodes() command which throws an error when I set the parameter to an integer (in hopes of returning the code in that Slot), and just sends every code to the logs when I leave the parameter blank. Perhaps if I could access the logs from RM then I could do some string parsing and accomplish my conflict check that way?

Alternatively, is there is there a way to query Lock Code Manager instead of the device directly?

Am I asking all the wrong questions?

getCodes() doesn’t take any arguments.

You could potentially save the output of getCodes() to a string variable, and then do some sort of comparison.

My lock (Yale Assure2) does not allow duplicate codes. It simply will not allow you to place a code in a new slot if another slot already contains that code.

Does your device not store all the lock codes in the lockCodes state?

Using RM, I add a code for a cleaner who comes weekly, it is the same code but we wanted it to only be active on the day she is to be here. It gets added and removed on that day every week. So after I add, I do a check to see if the code was successfully added. The data from the lockCodes state is stored in a string variable first then check to see if the variable contains the code.

3 Likes

This worked! I didn't even think of setting a local variable equal to the getCodes attribute.

I also like your idea of simply sending a notification if the new code isn't present after attempting to add it. I'd imagine that if the keypad was used during the 1 or 2 seconds that setCodes takes to run, there could be an issue.

My primary concern is the unlikely scenario in which my randomly generated 6-digit number matched up with an existing code already in use by me or one of my roommates. Then if someone with ill intent just happened to write that code down, it would continue to work the next day.

I'm bad at statistics so I asked gpt what the probability of that occurring was and its answer was 0.0002% per day, or 0.727% per year. Not super likely but I'm an edge case kinda guy.

Thank you for solving my risk management problem :sweat_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.