Considering openHAB: swap Things and keep history data

Hi.

I’m migrating from Home Assistant to zigbee2mqtt + other things.
I’m considering openHAB as dashboard and charting for its sane history function. So let’s say I have a sensor Thing that has one measurement Item. At some point I need to replace the Thing, either because it died or I want an upgrade. Can the history of the old Item be associated with the new Item? Of course it would have to be the same type of data with the same unit in order to make any sense.
Otherwise can it ported by fiddling with the backend database provided it is writeable?

What I can guess from Persistence | openHAB is that if I give the same name to the new Item it will just work? Can I even do that? Then what happens if I simply what to change the name of an Item in another scenario?

Thanks!

Yep. The layered nature of the basic openHAB setup means that Items (and therefore Item histories) are connected to Things, but not dependent on them.

Things have Channels and channels are connected to Items, so all you would need to do is to unlink the Item from the first Thing, add the new Thing and link the new Thing’s Channel to the old Item.

The history / persistence is based on the Item name. So as long as the Item name remains the same, the history will continue as is.

In fact, if when replacing the physical device, if you could set it up with the same ID as the old one, you won’t need to change anything on the openhab side. However, if the Thing / device has a unique / unchangeable ID, you simply link the same old item to the new Thing. That’s the beauty of Thing vs Item separation.

I’m not quite familiar with how to do this myself. In the past I would fiddle with the backend, in my case influxdb, and rename the “measurement”. But I think there’s this concept of “Alias” but I’m not familiar with it.

Even though it is absolutely what is written in the manual,

Channels are linked to Items, where such links are the glue between the virtual and the physical layer. Once such a link is established, a Thing reacts to events sent for an item that is linked to one of its Channels. Likewise, it actively sends out events for Items linked to its Channels.

I did not understand that Things and Items worked like that the frist time. I guess it becomes obvious once you start using it. That also explains why I did not find anything while searching as it is obviously a non-issue.

Thank you @JustinG and @jimtng for pointing it out and the clarification on how it is linked to persistence.

The abstraction layers model is good and in my current situation would have provent magnificently flexible: I migrated my Zigbee network from Zigbee Home Automation (HA) to zigbee2mqtt. I would have liked to be able to swap ZHA to MQTT in Home Assistant. There’s no way that can be done without copious pain. In openHAB I could remove a binding, add another, remap Channels to Items and be done with it. Is that right?

Very nearly. Things are binding dependent, so you would add the new binding → create the new Things from that binding → remap the new Thing Channels to the Items.

If you use file-based config, mass changes to your items / links / things can be done using copy/paste and search/replace feature of your editor (e.g. vscode).

In openhab, both UI based configurations and file-based configurations are equally supported, with strong proponents on both sides.

Curious I find myself doing this semi regularly because I like to tinker with esphome, Mqtt and now matter.

I use the same items, I just link them to different channels of different things :slight_smile: