Use Dashboard to Manage Lock Codes

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

Hi @Angus_M - this is my driver. It's not the complete code, but as an example it shows how to use the groovy.json jsonSlurper .

Learned a bit more about Groovy and removed a lot of the hard coding. Looks like even attribute definitions can be added programatically. 2021-01-02

Hope this helps:-

import groovy.json.*
	
metadata {
definition (name: "Virtual JSON Parser", namespace: "timtuxworth", author: "Tim Tuxworth")     {
   capability "Actuator"
    
    command   "sendLockCodes",["string"]
    
    attribute "lockcodeslist", "string"
    attribute "lastUpdated", "string"
    
    attribute "slotlabel", "string"
    attribute "codelabel", "string"
    attribute "namelabel", "string"

    Integer s;
    for(s = 1; s <= 9; s++)
    {
        attribute "slot" + Integer.toString(s), "number"
        attribute "code" + Integer.toString(s), "string"
        attribute "name" + Integer.toString(s), "string"
    }
}
def sendLockCodes(lockcodesjson) {

sendEvent(name: "lockcodeslist", value: lockcodesjson, displayed: true)

def jsonSlurper = new JsonSlurper()
def lockobjects = jsonSlurper.parseText(lockcodesjson)

assert lockobjects instanceof Map

sendEvent( name: "slotlabel", value: "#")
sendEvent( name: "codelabel", value: "Code")
sendEvent( name: "namelabel", value: "Name")

Integer s;
for(s = 1; s <=9; s++)
{
    sendEvent( name: "slot" + Integer.toString(s), value: Integer.toString(s))
    sendEvent( name: "code" + Integer.toString(s), value: "-")
    sendEvent( name: "name" + Integer.toString(s), value: "-")
}

// for this to work the JSON passed in must be in the format, by adding attributes you could extract any number of rows.
// {"1":{"name":"Test1","code":"1111"},
//  "2":{"name":"Jo2","code":"2121"},
//  "3":{"name":"XX","code":"1234"}
// }

log.debug(lockobjects.toString())
lockobjects.each { lockobject ->
    def slot = lockobject.key
    
    sendEvent( name: "slot" + slot, value: slot)
    sendEvent( name: "code" + slot, value: lockobjects[slot].code)
    sendEvent( name: "name" + slot, value: lockobjects[slot].name)
}

lastUpdated = new Date()
sendEvent( name: "lastUpdated", value: lastUpdated.format("MM-dd - h:mm:ss a") )

}
3 Likes

I have the problem you're describing about the virtual device for LockCode not showing as possible device in dashboard. How do you add permission? I don't see anything when creating the variable.

Go to the Apps tab, scroll down to Hubitat Dashboard, and select the child app corresponding to the dashboard you want it available in. Variable device should be available there to check for inclusion.

1 Like

@thebearmay thanks!!! Both for quick response and that it worked!

Anyone have update on when this sort of feature would be formally supported. While this is a nice 'workaround', it's really just that.... a workaround. Being able to configure the LockCodeManager app remotely via Dashboard would be really helpful for those of us who have VRBO / AirBnB locations.

1 Like

I use the VPN service available in my router, combined with a Dynamic DNS entry to log into my network from a remote location and then run the apps.

There is an upcoming service for remote access. Below is a recent thread that speculates about this service. It is likely coming to the next update or two if it is showing in the Hubitat app. No formal details about this service have been released that I am aware of.

1 Like

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