Occupancy sensor driver code

I did purchase a Zigbee occupancy sensor (not a motion sensor), and it added the device to the hub. However, I see no occupancy sensor drivers available, and I was wondering if I could create one. I did look at some of the custom driver codes, and I'm lost. I do have the API guide. However, I'm unsure how to debug what is coming from the clusters. I tried to parse using the following code.

def parse(description) {
    log.debug "description is $description"
    def event = ZigBee.getEvent(description)
    if (event) {
        log.debug event
    } else {
        log.debug "didn't get an event."
    }
}

However, I don't see anything in the logs panel. Can someone please guide me to the correct path?

TIA

Which one? If it is the Aqara FP1, take a look at the thread titled, "Aqara P1 motion sensor" starting with this post from @kkossev

No, I got a different one from OWON. I'll look at the Aqara one. Thank you.

1 Like

That was helpful. I'll try and butcher that one and will report back. Thanks again

1 Like

Hmm, I do have a question on logging, I just need to see what the device is doing and then find out how to code for the clusters. I cannot see anything in the Past Logs if I just use parse

def parse(String description) {
    if (logEnable == true) log.debug "${device.displayName} parse: description is $description"
    
    def descMap = [:]
    try {
        descMap = zigbee.parseDescriptionAsMap(description)
        log.debug descMap
    }
    catch ( e ) {
        log.warn "${device.displayName} parse: exception caught while parsing descMap:  ${descMap}"
        return null
    }
}

How I can see this?

Do you have a preference (or other variable) named logEnable, and is it set to true? If not, the log.debug line won't execute. You can remove that if, or you can add such a preference (or field, etc.) and set its value accordingly. If you're using a stock Hubitat driver example as your starting point, this corresponds to the "Enable debug logging?" preference and also automatically disables itself after 30 minutes, by the way.

If that's all correct, then your device just isn't reporting anything to the hub. For Zigbee, you will normally need to configure reporting on the desired clusters, and that's probably why. (The other possibility is that your device isn't paired or doesn't have a route to the hub, etc.) That is not my area of expertise, but it will require knowledge of either standard Zigbee clusters or whatever that manufacturer happens to use (which may not be those).

I do have the following

    preferences {
		input name: "infoLogging", type: "bool", title: "Enable info message logging", description: ""
		input name: "debugLogging", type: "bool", title: "Enable debug message logging", description: ""
	}

I took your advice and changed my parse function to do the following.

def parse(String description) {
	log.debug "${device.displayName}: ${description}"
}

The good news is it is showing one message but that is it.

Bathroom: Parsing: catchall: 0104 0001 01 01 0040 00 16DC 00 00 0000 01 01 200086

Is there a delay in showing the logs in the Past log screen? The live one is not showing a thing.

Thank you for your help.

Nothing will show up in Past Logs if it wasn't there in Current Logs at some point (whether you were there to see it or not), but there shouldn't be any delay with Past Logs aside from the fact that, unlike Current Logs, it is not dynamically refreshed and just shows the contents at the times you loaded the page.

I'm not sure how familiar you are with Zigbee (I'm not much...), but the device will not send any reports to the hub unless it's configured to. This could be why you don't see what you're expecting in parse(). This is generally done in the configure() method in your driver, which is automatically called on pairing but can be manually run any time from the device detail page (e.g., if you modified this method and the relevant code wasn't in your driver originally). Improper configuration is my guess.

I'm running debug evey where. I'm not familiar with Zigbee coding. Your point on configuring the device is what I'm now looking at. I'll let you know. Thank you for pointing me in the right direction.

Download the Hubitat app