I'm moving over from Vera where I wrote a few dozen lines of code to periodically check if a door lock code was currently enabled. If so, I would set a virtual switch "Occupied" which would trigger an automation to set the thermostat, lock an interior door, and turn on a porch light.
How do I go about determining if one or more door lock codes are currently active and then setting a mode to "occupied"?
This is the last major hurdle I have to overcome before fully migrating to Hubitat.
With a bit of difficulty. (Unless someone can think of something I'm missing.)
First, no lock I'm aware of on Hubitat supports literally enabling or disabling a code; they are just added and removed from the device's own list of lock codes. (I think Z-Wave actually has provisions for built-in schedules, but I'm not sure how many locks actually implement this and don't know of anything on Hubitat that would use it.)
Second, I'm assuming the above is what you mean by a lock code being "enabled"--being available, on the lock, for use. In this case, no stock app I'm aware of (and not Rule Machine as far as I can tell) allows automating things based on the value of the lockCode attribute for that device, which is what you'd need to read. This isn't impossible to do; you'd just need a custom app to read the attribute and see if whatever criteria you're looking for are met (a code matching a specific name? a code matching a specific value/code?). But it would probably be easier to incorporate the switch into whatever automation you're using for the codes in the first place.
But ... perhaps you just mean when a lock code is used. That's easy and can be done with, among other possibilities, Rule Machine: just trigger on a specific lock code entered, then configure your actions to turn on that switch. You'd also need to figure out how to turn it off (maybe if the door is unlocked without a code, as it might be done from the inside? or automatically at a certain time every day if you have a predicable schedule? until some other code is used?).
I'm already using the Lock Code Manager plugin to manage the user pin codes on the z-wave lock. The part that I'm missing is triggering a mode change when the Lock Code Manager pushes the pin code to the z-wave lock.
Pin code is pushed to z-wave lock = Occupied
Pin code removed from z-wave lock = Unoccupied
I figured worst case I would write code to accomplish this task but wanted to see if there was anything I was missing or if anyone else had done something similar.
Ah, so you are indeed looking for what I was thinking with the first thing. There isn't a good built-in way to do this, but LCM's automation capabilities are pretty limited last time I checked--just enabling a code for a specific date range or indefinitely, nothing like some third-party apps on other platforms that allow hourly ranges every day or whatnot (probably given the above nature of locks). So, this might not be super-useful unless you are using something else. But regardless, I think you'll need a custom app to handle this. I can't think of any community apps that can do anything like this, but there may be some I'm not aware of. You can certainly also write your own from scratch, though any "getting started"-type guides for Hubitat are pretty much nonexistent (but very similar to SmartThings "old"-style SmartApps if you are familiar with those).
Did you ever resolve this? I would like to add one pin code into my locks during daylight hours and remove it during sleep. I don't see a way to do this in Rule Machine? I did look at Lock Code Manager but it won't work for me due to lack of IOS support.