Getting an event from a lock for ONLY when the lock is unlocked by a code

Well this was a fun little learning experience. Sorry it isn't working for you but I will go ahead and post this here for anyone following this thread and wants to use this. I simplified my process and created the app specifically for the purpose of triggering for only when a code is used. I do not see a way with only Rule Machine to do this so it takes this extra app and virtual switch to be used within a rule. I know you could do everything within the app but I like to have the actions within a rule so I can do more with it if I want to.

Schalge Lock Reporter3

/*
Installation Notes:
You must create a Virtual Switch to be used in a rule so when it is on, you will perform an action.
The virtual switch should have the "Enable auto off" set to 5 seconds.

Schlage Lock Events for reference
Lock Name = "Front Door Lock" (Varies per installation)
Virtual Switch Name = "Front Door Code Used"  (Varies per installation)

Locked using keypad Schlage button or code.
Lock event: lock : Front Door Lock was locked by keypad [physical]

Locked using inside dial.
Lock event: lock : Front Door Lock was locked by thumb turn [physical]

Locked using automation.
Lock event: lock : Front Door Lock was locked [digital]

Unlocked using code.
Unlock event: lock : Front Door Lock was unlocked by John

Unlocked using inside dial.
Unlock event: lock : Front Door Lock was unlocked by thumb turn [physical]

Unlocked using automation.
Unlock event: lock : Front Door Lock was unlocked [digital]

Credit to @rvrolyk "Russ Vrolyk" for the original code this is based on.
*/


definition(
    name: "Schlage Lock User Code Reporter",
    namespace: "chipworkz",
    author: "chipworkz",
    description: "Triggers when a user code is used to unlock the door",
    category: "Convenience",
	iconUrl: "",
    iconX2Url: "",
    iconX3Url: "")


def lock = [
    name: "lock",
    type: "capability.lock",
    title: "Lock",
    description: "Select the lock to monitor.",
    required: true,
    multiple: false
]

def virtuaCodeUsedSwitch = [
    name: "virtuaCodeUsedSwitch",
    type: "capability.switch",
    title: "Virtual Code Used Switch",
    description: "Virtual switch that should be turned on when a code is used.",
    required: true,
    multiple: false
]

def enableLogging = [
    name:				"enableLogging",
    type:				"bool",
    title:				"Enable debug Logging?",
    defaultValue:		false,
    required:			true
]

preferences {
	page(name: "mainPage", title: "<b>Schlage Lock User Code Reporter:</b>", install: true, uninstall: true) {
		section("") {
			input lock
			input virtuaCodeUsedSwitch
		}
		section ("<b>Advanced Settings</b>") {
			input enableLogging
		}
	}
}

def installed() {
	log.info "Installed with settings: ${settings}"
	initialize()
}

def updated() {
	log.info "Updated with settings: ${settings}"
	unsubscribe()
	initialize()
}

def initialize() {
    log "Lock status: ${lock.displayName} " + lockStatus()
	subscribe(lock, "lastCodeName", unlockHandler)
}

def lockStatus() {
	return lock.currentValue("lock")
}

def unlockHandler(evt) {
	log("Unlock event: ${evt.descriptionText}")
	if (evt.name == 'lastCodeName') {
		virtuaCodeUsedSwitch.on()
		}
}

def log(msg) {
    if (enableLogging) {
        log.debug msg
    }
}