Swap devices leaves ghost states

I have noted that if I use the swap devices feature, states from the original device are copied to the replacement device even if the device doesn't feature the attribute.

Example

If the original device has temperature, humidity, and motion, but the replacement only had motion and temperature. The replacement device will now list the unused humidity attribute in its current states as well as in rule machine and other apps.

Is there a way to remove the invalid attribute states from the replacement device after using the swap devices feature?

There is no way currently, but that might change in the future :wink:

1 Like

In a custom driver add some code to remove it, then take the code back out.

First add a command in the metadata section

command "removeAttribute"

Then add a function below to be called

void removeAttribute() {
     device.deleteCurrentState("NAME_OF_ATTRIBUTE")
}

Run the command and refresh the page, it should be gone.

4 Likes