Orphan jobs from previous driver?

I have Sonoff motion and contact sensors. Earlier I was using the user driver for Sonoff Motion sensor, which has features such as presence, recovery etc. Later, based on community recommendation, I changed them to native "Generic Zigbee Motion Sensor": driver.

But, it seems that the device still has some presence/recovery jobs scheduled. I should not be having these, right? How do I remove tany old jobs?

Change the driver for the sensor to 'Device'.
You can then delete all scheduled states and jobs.
Change it back to the generic driver and you are set to go again.


wow, this helped. But it makes me think... which other devices might have orphan jobs? Ideally, Hubitat should have prevented this from happening in the first place.

1 Like

I think it's because the driver that you were using set those schedules up.
If the driver you change to does not cancel those schedules ( unschedule() )then they will remain. They will throw an error but have no real affect on the hub. (I believe).
I suppose that's the risk (if that is the correct description) for using user code.

This caught me out when I was new to HE and I raised the issue as you have just done. Now I know I look for it. :man_shrugging:

Just as a matter of interest, before I realised that using 'Device' could clear things, I cobbled this together which does the same.
I'll post it in case you want to have a look/use it but I always use this when I jump between drivers for testing just to clear things.
There may be other things (please feel free to comment folks) to include to clear the device.

metadata {
	definition (name: "Device Info Clearer", namespace: "", author: "") {

command "WipeDevice"
def WipeDevice() {
    if (debugLogging) log.warn "Wiping Device"

Drivers/devices do not have a way to know when the code beneath them changes, so this isn't currently something drivers can really do on their own. Most drivers don't really schedule much, but if you're switching to radically different drivers, sometimes it does help to switch to "Device" in the meantime and clear state and schedules. Glad you got it figured out!


Perhaps the jobs should maintain some metadata to know which driver scheduled the job.. this way, we can quickly find jobs scheduled without the relevant driver in use.