Change bridge of things by rule

Hi all,

for redundancy I have two bridges A and B. If A fails (goes offline) I want to connect all things to bridge B which were formerly connected to bridge A.

Is there a way to change the bridge of things from a rule?

I don’t believe you can change an item’s channel links from a rule (I could be wrong about that). However, you can connect an item to channels from both bridges, then use a rule to detect when the primary has gone offline. When that happens, you can disable the primary bridge and then enable the backup by using sendHTTPGetRequest to issue a command through the REST API.

You could also just try leaving both bridges active. If you do that, the bridges will send two identical commands to the item and receive two identical commands from the item. That may be fine, and it may cause problems.

Does the bridge fail often enough that you need to be concerned about it? If so, your time might be better spent determining why that’s happening. Otherwise, I wouldn’t expect the backup to be any more reliable.

There is not enough information here to answer the question. What binding? How do you know if A goes offline?

You can enable/disable Things from rules through the ThingRegistry (not available in Rules DSL I think). But I don’t think you can move the Things to a different bridge. As I understand it, the Thing ID is used in part to keep track of which Things belong to which bridge and since you can’t change the ID of a Thing you’d lose that tracking if you try to move to a different bridge.

But you could set up two sets of Things and link both sets to the Items. In a rule you can detect when A goes offline and enable the Things for B (it’s probably enough to enable/disable just the Bridge).

My question is independent of a specific binding but generic for every binding using bridges.

In the meantime I found out, that I am able to change the bridge of a thing by using REST-API:

1.) get thing (say X) configuration by using endpoint GET /things/{thingUID}
2.) change “bridgeUID” (bridge A) in configuration to UID of bridge B
3.) set configuration of thing X by using endpoint PUT /things/{thingUID} and the formentioned edited configuration
4.) disable and enable X (needed for letting openhab recognize that bridge of thing X has changed)

Now I am searching for an easier way to automate this for all things which are connected to bridge A.

For the question “How do you know if A goes offline?” => the things status (bridge A) changes to offline.

If I were concerned about a bridge going offline, I’d just do what Rich and I suggested before: link the item to two channels, then enable the secondary bridge if/when the primary bridge goes offline.

Since the item always sends/receives from the two channels, it would fail over to the secondary bridge immediately (without requiring any reinitialization) and minimize downtime.

I don’t know how you would automate what you’ve described for all things attached to a bridge. I suspect you could do so based on naming conventions.

GET /links - e.g., $.[?(@.channelUID contains 'tibber:tibberapi:f3f7052db4')]

Linking the items to two channels as suggested by @rlkoshak seems the way to go though.

1 Like

Thanks for all your input. I’ll try to link the items to two channels.