Syncing two switches

Hi,
I have a MQTT based switch running (Shelly), which allows me to switch on/off lights via Openhab’s web interface, the original wall swich and furhtermore via my Logitech Harmony using Hue Emulation. In principle everthing is working, but one problem remains: I can’t sync the status of the Hue Emulation switch with the status of the MQTT switch. E.g. if I turn on the light via the Harmony remote (Hue emulation) and later on off via the wall switch, the Hue emulation would not know about the off status.
I tried to resolve that via rules, but that brought me into an endless loop (off via MQTT triggers off for HUE, triggers off for MQTT …). Is there a preferred/best practice way to sync the state of two switches in such a scenario?

Thank you for your support.

Thomas

Look into the documentation and serach for profiles and especially the follow profile

It can be solved with rules without the endless loop. This is where the distinction between sendCommand and postUpdate is important. And sometimes a proxy item is required.

The follow profile is one way (i.e. second channel follows the first but the first but the first doesn’t follow the second) so it might not be suitable.

To follow vice versa with the follow profile both item have to follow each other.

Thank you all for the quick response and suggestions.

I implemented the way via postUpdate and it works perfrectely fine.

Here is a code snippet, just in case somebody face the same issue

rule "Stehlampe anschalten via Hue"
when
    Item egHueEmuLichtStehlampe received command ON
then
    sendCommand(egLichtStehlampe,"ON")
end

rule "Stehlampe ausschalten via Hue"
when
    Item egHueEmuLichtStehlampe received command OFF
then
    sendCommand(egLichtStehlampe,"OFF")
end

rule "Stehlampe anschalten Hue Status"
when
    Item egLichtStehlampe changed from OFF to ON
then
    postUpdate(egHueEmuLichtStehlampe,"ON")
end

rule "Stehlampe ausschalten Hue Status"
when
    Item egLichtStehlampe changed from ON to OFF
then
    postUpdate(egHueEmuLichtStehlampe,"OFF")
end

Where egLichtStehlampe is the MQTT switch and egHueEmuLichtStehlampe is the emulated Hue switch.

Thanks again and best regards,

Thomas