How to replace a broken device in openHAB?

I had to replace one of my Shelly 2.5 with a new Shelly Plus 2PM. How do I replace the old thing with the new thing in OH3 without having to setup all derived items and equipment from scratch?

I tried the following:

  1. Add the new device as a thing
  2. Copy the code from the new device:
  3. Paste the code into the old item

Unfortunately, when I tried to save the new code, I got an error: Changing the thing UID is not supported

Is there any way of achieving what I want to do?

  1. Take note of the old Thing’s UID. Delete the old Thing. Do not unlink the Items. Do not remove the Items.
  2. Discover the new Thing. Before accepting it from the Inbox, change the Thing’s ID to match the old one’s ID. This is the only time you can change the Thing’s ID.

If the new Thing has the same UID, the old Links and Items will just work.

Since you already added the new device as a Thing, you probably should, as step 0, remove the new Thing first.

2 Likes

Okay, thanks. I’m glad that this is possible.

I did the following:

  1. I removed the new device thing (that I previously created)
  2. I noted the device uid of the old device thing
  3. I deleted the old device thing
  4. I rediscovered the new device and added it as thing with custom ID, using the old device ID as custom ID.
  5. It then asked me to provide a label and I accepted whatever it suggested as default.

This gave me an error and the new thing was not created. The error message in the bottom left corner disappeared before I could read it but I found this in the openhab.log file:

2023-02-17 16:23:53.418 [ERROR] [ore.internal.discovery.InboxResource] - Thing shelly:shellyplus2pm-relay:c049ef883550 unable to be approved: New Thing ID shelly:shelly25-relay:c4d7a1 must not contain multiple segments

If I understand this correctly, something has changed regarding the requirements for a valid UID so that I am not able to create a new thing with the old thing uid. Is that correct? Any way to work around this?

That Thing ID doesn’t look wrong to me. But it might be that you only should copy over the last part of the ID from the old to the new, not the whole thing.

I don’t have any things to experiment with and it’s been a long time since I’ve done this.

You mean what comes after the last colon?

Edit: I tried that and that will get the thing approved, but it will not have the same uid and hence it will not inherit the exisiting items from the old thing…

Edit2: I found the code that produces the error message here

According to this, a thingID may not contain an AbstractUID.SEPARATOR.

I found that the separator is defined as a colon here (that is for OH4.0 while I am on 3.4, but I assume that this has not changed).

So, it looks like it is not possible to specify the entire UID as a custom UID, only the last part, while whatever comes before the colon cannot be changed. If this is correct, it looks like we cannot create a thing with the exact UID of a previous thing.

Is there any way of reverting this deletion?

Before I deleted the thing, the rules operating it still worked (even with the new device, because I gave the new device the same IP), but when I now try to recreate the thing in order to get those rules working again, it doesn’t work.

I manually created a thing in the shelly binding, same UID, same everything, but it does not inherit its previous items (except for signal strength). So the rules still don’t work.

How do I revert the deletion so that the rules work again?

Edit: It looks like the problem is that when I manually recreate the thing, the channels are not recreated because the device is no longer online (for some reason, it picks up the signal strength channel from the new device, probably because it is associated to the IP).

Is there any way of restoring the other channels?

Oh, there are ways.

  1. Stop OH.
  2. Navigate to /var/lib/openhab/jsondb
  3. Open org.openhab.core.thing.Thing.json
  4. Find the entry for your new Thing
  5. Replace the UID with your old Thing’s UID; notice that the ID will be a part of the ID for all the Channels as well as the Thing itself
  6. Start OH and watch for errors.

Assuming there haven’t been too many changes/restarts since you deleted the Thing, look in /var/lib/openhab/jsondb/backup. Every time you make a change a backup is saved from before the change. Restore the org.openhab.core.thing.Thing.json to the latest backup version there and work backwards until you are back to where you started or run out of backups.

Again, you’ll need to stop OH prior to restoring the backup.

If it’s autodiscovered, it’s the job of the binding to detect and create the Channels.

1 Like

That path doesn’t exist on my instance:

Is it because I’m running OH in a docker container?

Edit: I found the file in /openhab/userdata/jsondb/and replaced the new uid string with the old uid string everywhere it occurred and it seems to work now.

Thank you for your assistance!

Yes. Inside the container it’s /openhab/userdata/jsondb.

Outside the container it’s what ever folder you have mounted to /openhab/userdata.