Status issue

Hi,

I’ve been trying to use the below code. I use it as a button and it’s shown in the image below. However whenever I press the PAUSE button to start this code, it has issues keeping the status of the app. A video of my problem is in the link: https://youtu.be/JL-OVcBCMxE. In the video, I pressed the pause button, and this messes up the status. The only way to fix this is by pressing the refresh button manually, but my goal is to have it maintain status. I based my code off of the ZigBee Switch template and I would appreciate any help on how to maintain the status of the app once the PAUSE button is pressed.

def lock() {
   zigbee.command(0x0006, 0x02) +
   refresh()
}

metadata {
    definition (name: "ZigBee Switch", namespace: "smartthings", author: "SmartThings", ocfDeviceType: "oic.d.switch") {
        capability "Actuator"
        capability "Configuration"
        capability "Refresh"
        capability "Switch"
        capability "Health Check"
        capability "Lock"

        fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006", deviceJoinName: "Switch", manufacturer: "Tek",  model: "MD001"
    }

    // simulator metadata
    simulator {
        // status messages
        status "on": "on/off: 1"
        status "off": "on/off: 0"

        // reply messages
        reply "zcl on-off on": "on/off: 1"
        reply "zcl on-off off": "on/off: 0"
    }

    tiles(scale: 2) {
        multiAttributeTile(name:"switch", type: "generic", width: 6, height: 4, canChangeIcon: true){
            tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
                attributeState "on", label:'${name}', action: "switch.off", icon:"st.switches.light.on", backgroundColor:"#00A0DC", nextState:"off"
                attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"on"
            }
        }
        standardTile("lock", "device.lock", width: 2, height: 2, canChangeIcon: true, decoration: "flat") {
			state "default", label: 'PAUSE', action:"lock.lock", backgroundColor: "#00A0DC"
		}
        standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
            state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
        }
        main "switch"
        details(["switch", "lock", "refresh"])
    }
}

// Parse incoming device messages to generate events
def parse(String description) {
    log.debug "description is $description"
    def event = zigbee.getEvent(description)
    if (event) {
        sendEvent(event)
    }
    else {
        log.warn "DID NOT PARSE MESSAGE for description : $description"
        log.debug zigbee.parseDescriptionAsMap(description)
    }
}

def off() {
    zigbee.off()
}

def on() {
    zigbee.on()
}

def lock() {
	zigbee.command(0x0006, 0x02)+
    refresh()
}

/**
 * PING is used by Device-Watch in attempt to reach the Device
 * */
def ping() {
    return refresh()
}

def refresh() {
    zigbee.onOffRefresh() + zigbee.onOffConfig()
}

def configure() {
    // Device-Watch allows 2 check-in misses from device + ping (plus 2 min lag time)
    sendEvent(name: "checkInterval", value: 2 * 10 * 60 + 2 * 60, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
    log.debug "Configuring Reporting and Bindings."
    zigbee.onOffRefresh() + zigbee.onOffConfig()
}