Hub mesh and device swap - now has attributes it does not have

I made a big mistake due to not understanding how device swap works. I paired an Aqara contact sensor with my Aqara-specific Hubitat hub, using Xiaomi Aqara Mijia Sensors and Switches. The device has only Open/Closed as a state, not temperature or anything else. On the paired hub this shows as expected.

I then used Hub Mesh to share it with my main hub.

The device was intended to replace a Smartthings contact/multi sensor on a closet door. The ST device has many types of sensor including temperature but I only require contact in that situation. So I used Swap Apps Device under settings on my main hub so that the Aqara would replace ST sensor in 4 apps it was used in. What I didn't realise is that it actually swaps the device UID, not just replaces the old device in the apps but actually gives it the old device's identity!!

So it's inherited the States of the ST sensor including temperature - and is showing the last received temperature of the ST. This is now showing on dashboards and is misleading as it is not the correct temperature for obvious reasons.

Is there anything I can do to rectify this easily or do I just have to remove it from the apps, unlink via Hub Mesh, destroy the device on the main hub, relink it as a new device and add it to the apps again as itself?

It’s fixable. Let me whip up a temporary device driver that will give you access to the device.deleteCurrentState() method.

I can;t apply that to the device as represented on the main hub, only on the hub its paired to, which already has the correct states

That’s an interesting wrinkle… I wonder if I can call that from an app… Testing….

Appears to work, let me get you some clean code….

1 Like

Doesn’t give you a lot of feed back but should work for you….

App Code
/*

 */

static String version()	{  return '0.0.0'  }
definition (
	name: 			"Quick and Dirty", 
	namespace: 		"thebearmay", 
	author: 		"Jean P. May, Jr.",
	description: 	"Allow killing of current states",
	category: 		"Utility",
	importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/xxxxx.groovy",
    installOnOpen:  true,
	oauth: 			false,
    iconUrl:        "",
    iconX2Url:      ""
) 

preferences {
   page name: "mainPage"
}
def installed() {
//	log.trace "installed()"
    state?.isInstalled = true
    initialize()
}

def updated(){
//	log.trace "updated()"
    if(!state?.isInstalled) { state?.isInstalled = true }
	if(debugEnable) runIn(1800,logsOff)
}

def initialize(){
}

void logsOff(){
     app.updateSetting("debugEnable",[value:"false",type:"bool"])
}

def mainPage(){
    dynamicPage (name: "mainPage", title: "", install: true, uninstall: true) {
      	if (app.getInstallationState() == 'COMPLETE') {   
	    	section("Main")
		    {
                input "qryDevice", "capability.*", title: "Devices of Interest:", multiple: false, required: true, submitOnChange: true
                if (qryDevice != null) {
                    input "stateStr", "string", title:"Current State to Remove", submitOnChange: true
                    if (stateStr != null)
                        input "removeState", "button", title: "Remove"
                }
                input "debugEnabled", "bool", title: "Debug?"
                if(state?.btnPush) {
                    qryDevice.deleteCurrentState("$stateStr")
                    state.btnPush = false
                }
		    }         

	    } else {
		    section("") {
			    paragraph title: "Click Done", "Please click Done to install app before continuing"
		    }
	    }
    }
}

def appButtonHandler(btn) {
    switch(btn) {
          case "removeState":
            state.btnPush = true
            break
          default: 
              log.error "Undefined button $btn pushed"
              break
      }
}

2 Likes

Yeah that worked thanks! I shall keep an eye on it and make sure they don't come back for any obscure reason. It also works better than changing to type Device which often doesn't get rid of the states using the commands, in my experience. So it will also be helpful to people with a device directly paired with current hub

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.