Use Dashboard to Manage Lock Codes

Now getting an error back from the lock - so I guess that's progress. It would be nice if any error could display on the dashboard. How can I do that? Anyway - the error seems to be showing a mismatch with what the lock is expecting. The string was "3:1234:TEST" - which should be trying to set slot 3, but this is the error:

dev:402020-12-28 04:01:14.575 pm warnchangeIsValid:false, codeNumber 3 is larger than maxCodes of 30

dev:402020-12-28 04:01:14.562 pm debugsetCode- 3

app:852020-12-28 04:01:14.466 pm infoAction: setCode(slot(3), code(1234), name(TEST)) on Lock Front Door

I tried what I think is exactly the same code on the device page and it worked fine and successfully set slot 3 to 1234, TEST.

Screen Shot 2020-12-28 at 4.08.11 PM

LockCodes : {"1":{"name":"code #1","code":"????"},"2":{"name":"code #2","code":"????"},"3":{"name":"Test","code":"1234"

Show your local variables section. Don't copy/paste logs please, only use screenshots.

Local variables:

Screen Shot 2020-12-28 at 4.12.11 PM

When you setup the parameters for the Custom Action, the first parameter has to be a 'number'. Did you do that?

You can check by editing that action, and then editing the parameters.

3 Likes

Bingo - that worked! Thanks @bravenel

1 Like

Ok - next question. To "Manage" locks codes, I also need to be able to see what the current codes are. I have several properties and they are a long way away, so I can't always go there to check what codes are currently active. e.g. I might have a new cleaner - not sure if the code is set up for them on this lock and can't go there to check. So - how can I create a tile on the dashboard that displays the current GetCodes (ideally formatted but worst case as it comes)?

[Yes I'll put a PIN on the Dashboard.]

There is no easy way to do that. The codes come out of the driver as a JSON object that needs to be parsed to make sense of. Generally, these need to be managed in an app or separately. See the built-in app Lock Code Manager. However, that won't help with remotely getting the codes.

Yes the Lock Code Manager is pretty close to what I'm looking for, but it needs to be able to be accessed from the Dashboard otherwise it's not much good. I'm looking to replace Wink and SmartThings with Hubitat and this is what I need.

Then you are best of setting up a simple VPN - I've used OpenVPN and WireGuard; both work well.

1 Like

At least in the generic driver the codes are stored in a map called lockCodes. While the attribute tile won’t display that lock attribute, one could select an appropriate trigger and use it to cause a rule to set the attribute on another virtual device equal to lock.lockCodes, and then use the attribute tile to display it.

1 Like

There is a way to do it, thanks to @thebearmay's suggestion. It is possible to set a variable to a device attribute, and locks do have an attribute that holds the JSON text of the lock codes (you can see this on the device page under state). So it's possible to get that string into a rule, and then do surgery on it to peel apart the codes. These could then be put into connectors for display on a Dashboard. A variant of the rule shown above could be used to display/change all of the lock codes for a lock, each in its own tile.

An alternative approach, and a bit easier, would be to start with a clean slate, erasing all of the codes in the lock to start with. Then, the tile-per-code approach described above could be used to set each of them, and keep it's display visible (getting rid of that last action above that hides the code).

There are several ways this could be done. I'll work one up tomorrow...

You can see below where I pulled the locks codes into the local variable called 'test' This action did this:

This seems interesting. How did you trigger it? I would want to set it in an "onLoad" event for the Dashboard. Is there such a thing?

So I set a global variable "LockCodesList" - which I just populated with lock.LockCodes as the last line of my "set lock code" Rule Machine. I created a connector for it and show it on a Variable String tile. It's very messy on the display but proves the concept.

Screen Shot 2020-12-28 at 10.11.32 PM

But because there are a variable number of possible lock codes (I currently have 6 set, but could set up to 30), I need a loop construct in the rule machine to loop through the JSON if I want to do anything useful with the JSON. Also I can't see how a tile per code would work since there are potentially a variable number of codes.

This would be much easier if there was a way to write code, is there a "Write Code" app? This would be much simpler if I could just write code instead of all this Rule Machine rigmarole.

1 Like

HE does allow you to code your own apps and devices using groovy... A little more effort than using a rule engine but certainly available if you want to just "write code".

1 Like

Yes, this would best be done with an app. not Rule Machine.

I think the biggest constraint you've placed on the usability of this is the Dashboard, and the issues of how to present a large amount of information in very small spaces. Add to that the issue of a variable number of lock codes, and it's just a tough way to go.

1 Like

I've just discovered the BTPWorld Tile Master app and it looks promising - ability to put multiple pieces of information on a single tile. I'm going to see how far I can get with it.

1 Like

So using the @bptworld TileMaster app I managed to get the list of codes layed out ok. It's a little ugly but better than the raw JSON for sure. I can fit about 4 codes on a tile. The 1024 character TileMaster limit means I have to use multiple tiles. It's a bit awkward but it's a one time setup. The result looks like this.

Screen Shot 2020-12-31 at 1.57.22 PM

To get the data into the tile, I had to write a custom device driver that parses the JSON using groovy.json.* then creates a set of attributes for each slot: slot1, code1, name1, slot2, code2, name2 etc.

1 Like

Had a weird bug with this. Would set the code on a lock slot using the LockCode Variable String Tile, then sent the lock codes from the lock (lock.lockCodes attribute) to my JSON parser which then displayed the codes on the tile.

It wasn't working. I had to exit the dashboard and go and manually run the parser to get the tile to update with the new lock code.

It seems this was a timing issue. The lock doesn't update immediately, so even though I had used setCode() on the lock to set the new code in the slot. The rule ran too fast and when it queried the lock the new code hadn't updated yet on the lock.

I put in a 10 second delay after setCode() before querying lock.lockCodes and now the tile updates with the new code after it is set.

1 Like

Would you kindly post your driver? I'm interested in setting this up!

Thanks.

1 Like