[SOLVED] Profile=follow / Or how to synchronize two items?

Pi4b, OH2.5.12

I am using the profile=follow function for two of my items, but this isn´t working as expected.
These are two sonoff tasmota wall switches which don´t switch anything physically.
I only switch a “dummy switch” for activating an alarm rule.

What I cannot get working is that these two switches are working in both directions - meaning when A is switched B is following and vice versa. Currently A is activating/deactivating B but not in the opposite direction.

This is the current item definition

Switch E_Touch10_2 {channel="mqtt:homeassistant_AC7EB3:583ffe5b:AC7EB3:AC7EB3_5FRL_5F2#switch", channel="mqtt:homeassistant_AC7A89:583ffe5b:AC7A89:AC7A89_5FRL_5F2#switch" [profile="follow"]}

I tried to add a second item changing both channels, but this then both channels do ON/OFF/ON/OFF…
What is wrong here?

Currently I don´t have the second item/channel defined individually because this seems not necessary when using the profile=follow function

You have to declare the follow profile per channel, not once per item.
try this

Switch E_Touch10_2 { channel="mqtt:homeassistant_AC7EB3:583ffe5b:AC7EB3:AC7EB3_5FRL_5F2#switch"[profile="follow"], channel="mqtt:homeassistant_AC7A89:583ffe5b:AC7A89:AC7A89_5FRL_5F2#switch"[profile="follow"]}

Follow profile is very useful for master-slave configurations. You’ll get into trouble if you try to make two masters - who is in charge? Great risk of endless loop.

See if you can follow this -

Using rules instead of follow profile allows the subtle controls of distinguishing change from update for determining action.

2 Likes

Hi, I just tried this but unfortunately it doesn´t work.
Now only the command from PaperUI gets reflected on both switches. But the switches are ignored when I use the switch it doesn´t switch the other switch nor in OH.

Maybe creating a rule is the better thing for this purpose as rosko57 is stating below.
Basically these are three masters the two switches and the OH App. Each is master.

Don’t use follow at all!
Please use instead the “Is Command” feature in mqtt.
Please keep in mind, that under normal circumstances, each incomming message through a binding is a status and not a command. To use an external switch to control other hardware (i.e. of another binding), you have to change the status to a command, either by using a rule (ItemA received update → ItemB.sendCommand) or by changing the behavior of the channel itself.

You can find the option by selecting “SHOW MORE” and scrolling down to the very end. You have to do this on each Channel, which should be treated as a command.

Hi Udo,
Maybe a bit more background.
I am using this command in an alarm rule

if(E_Touch10_2.state == OFF)

in order to activate the rule or not. No physical switch just the state of these switches.
I am using two sonoff T3 (3 items and 3 channels) which are located on two floors and of course I would like to use both of them to control the Alarm.
Switch E_Touch10_2 and Switch S_Touch90_2
The current setup with profile=follow works “almost” correct:-)
When I press the second button on E_Touch10_2 the alarm gets activated and the profile=follow
takes care to activate the second switch S_Touch90_2 as well and of course the light is reflecting the state.
This is the current item setup for the first switch whereby I don´t have the second switch defined individually this seems not to be necessary.

Switch E_Touch10_2 {channel="mqtt:homeassistant_AC7EB3:583ffe5b:AC7EB3:AC7EB3_5FRL_5F2#switch", channel="mqtt:homeassistant_AC7A89:583ffe5b:AC7A89:AC7A89_5FRL_5F2#switch" [profile="follow"]}

The only problem I do face is that physically using the second switch on S_Touch90_2 will not deactivate the first switch.
Therefore I thought the usage of that profile=follow is somehow wrong and I would need to add a second item just the other way arround. Unfortunatelly that doesn´t work it creates a kind of a loop for both devices

BTW. I can´t see the usage of “is command” in MQTT to solve this issue

The follow profile is about getting external devices to mirror the internal state of an openHAB Item.

You seem to want an Item that responds to instructions from external devices. The MQTT “is command” feature transforms incoming messages into Item commands, the same as you get when clicking in a UI.

Ah. Now, you only can do this with a rule. You will also need one Item per switch, because you want to use the switch as an actuator (although nothing connected, but still…).

Group:Switch gAlarmSwitch
Switch E_Touch10_2 (gAlarmSwitch) {channel="mqtt:homeassistant_AC7EB3:583ffe5b:AC7EB3:AC7EB3_5FRL_5F2#switch"}
Switch E_Touch11_2 (gAlarmSwitch) {channel="mqtt:homeassistant_AC7A89:583ffe5b:AC7A89:AC7A89_5FRL_5F2#switch"}

First, create a Switch group for all Alarm Switches (is gAlarmSwitch here)
Second, group all Alarm switches with that group.
Third, use a Rule:

var Boolean bLock = false // global var has to be defined first (no rules ahead)

rule "update other switches"
when
    Member of gAlarmSwitch changed
then
    if(bLock)     // check if rule already started
        return;   // and break if true
    bLock = true  // lock rule
    gAlarmSwitch.members.filter[j|j.name != triggeringItem.name].forEach[i| // get a list of Alarm Switch Items without the triggering one.
        i.sendCommand(triggeringItem.state.toString)                        // and send the command to switch state
    ]
    Thread::sleep(500)                                                      // give some time to rest
    bLock = false // Unlöock rule
end
2 Likes

OK,OK :slight_smile:

  1. Just to confirm, this is a separate additional synchronization rule, and the current usage of e.g. the state of one of these switches in another rule (e.g. my alarm rule) stays untouched?
  2. Cause I would setup that rule as a separate file, I don´t need to take care for defining that global var first, as you mentioned?
  3. And this is a generic way to synchronize two switches (or more) belonging to the same group?
    Of course this doesn´t make sense in all cases but absolutely required when you use e.g. two sonoff touch switches visualizing per LED if ON or OFF.
  4. Is the rule the same for OH2.5 and OH3?

Thanks a lot

Edit: In the meanwhile I changed my setup

  • edited the items and added a group
  • created a separate rule file

and BINGO worked :slight_smile:

The global lock variable is needed, because the rule will trigger itself. Although this might not do any harm, it is bad style not to take care of this point.