2.3.3.137: Deleting a device used in a rule expression leaves dangling conditions

If a rule references a device, and that device is removed, the expression leaves the conditions with no way to remove them without having to delete the rule line. Also, the expression itself is gone (only the true/false state remains), and I can't remember what the logical conditions were to recreate it.

One potential way to avoid this is not to delete devices with references immediately (use reference counting since devices already track references). Mark it for deletion, and once all references are removed, then the cleanup would delete it permanently. The RM would see the deleted flag and indicate the rule expression as such. This would prevent the logic from disappearing and allow the user to edit the rule with a new device.

It would be great if RM had a way to allow replacing any device used in a rule with a different device instead of having to recreate the rules. (A device swapper). This situation can occur if I have a bad device and need to delete or re-add it. Currently, all the rules that reference the deleted device become invalid and there's no way to delete that expression or change it since the edit/delete dropdowns do not show those lines.

1 Like

I think one thing you can do is create a virtual device and swap that with the old actual device using the clone function. Then swap out the virtual device for the new actual device.

2 Likes

You can also use the "Swap Apps Device" under Settings

3 Likes

That’s even better!

I had no idea that was added. But unfortunately, it doesn't help if the device is already removed.

Cloning a rule will also do this, and unlike Swap Apps Device, it affects only this particular rule and works on any kind of device (including children's devices).

The best way to avoid this is to heed the warning in the UI when you remove a device and remove it from all apps first. Apps don't have a way to know when devices are removed, and while most can be made to work around any oddities caused by a device being pulled out from under its feet, some may not--hence the warning.

6 Likes

Swap Apps Device works great if you use it before you delete the old device. You can, as @didymus suggests, create a virtual device, then use Swap Apps Device to swap that out with the old device before you remove it. Then exclude or remove the old device. Install new device and then swap out the virtual device for the new actual device.

There are some who have had good luck using the replace button on the Z-wave details page, but that replace button has had problems in the past and if it doesn't work I am concerned I would be stuck with a ghost.....so I like the procedure above.

While I appreciate that, sometimes, the circumstances do not allow for the perfect order of operations. Since devices already know what is referencing them, the system can prevent these null references by delaying hard deletions. Reference counting is a common pattern to avoid referential integrity issues.

In my situation, my Konnected devices no longer had a valid token (I think a Hubitat update invalided them), so I had to reinstall everything. But I can't swap devices until I re-add the new ones. Having to add new ones using new names, swapping devices, deleting the old devices, then renaming the new devices, is a lot more work than necessary.

1 Like

Thanks for both suggestions. I was not aware of the swap device feature so I'll keep it in mind the next time. Unfortunately, having to create virtual devices for 18 devices is too time consuming going back and forth in the UI.

1 Like

I love the behavior in webCoRE when a device is removed out from under it - it leaves the rule/expression intact in the piston, but replaces the device with the old ID string as a placeholder (which is the same value in all the pistons that used to refer to that device). This let me easily repair any broken pistons by updating the device from the old ID to the new device.

(At least this is how webCoRE works under ST; I've not used it on Hubitat)

4 Likes

That would be a good option too.

I was working on an issue today and force removed a device. After adding it back in I simply went back into the trigger and selected the new device on that line. Normally I would do a swap device but I didn't notice any issues when editing the rule line that holds the triggering device

I keep hearing about the swap devices app. But, the last time I needed it, it did not work for zigbee devices (Which is what I needed at the time). Does the app work for zigbee now?

Nevermind, I just looked and it does show all my devices now. Cool

Just note that it doesn't work for child devices.

I learned that the hard way with inovelli.....

1 Like

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