Logic Question for a virtual switch (used to sync between Hubitat and HomeKit)

Hi all! I would appreciate some of your advice on how best to handle some logic that involves rules that have triggers that are also changed by rules.

Specifically for me, I'm trying to sync some modes/scenes between HomeKit and Radio Ra2. I'm using a Virtual Switch, which has to work as a trigger both ways - i.e. if a scene is turned on in HomeKit, it turns on the Virtual Switch, which will then trigger a rule in Hubitat to turn on other devices on the Hubitat side (and press some buttons on Ra2 Keypads, etc.). On the flip side, if a button from a RA2 keypad is pressed, this has to turn on the same Virtual Switch so that anything on the HomeKit side can also run.

I'm new to Rule Machine, so I'm trying to figure out how to handle this virtual switch that can be used as the TRIGGER for a rule, but also needs to be turned ON by some other rule, which then causes a feedback loop.

Example: Someone in our house uses their phone or Siri to turn on "Home" setting. This turns on a virtual switch called "(VS) Home". In Hubitat, I have a rule (1) that uses that "(VS) Home" as a trigger, which then calls a "Home" rule (2) that sets the lights, presses some buttons on the Ra2 Main Repeater, changes the mode to Not Away, etc.

However, I also have some keypads on the RA2 side that are also triggers for a separate rule (3) that will call the "Home" (2) rule, as well as turn on the "(VS) Home" switch, so that HomeKit is synced, However, this press will ALSO call the first rule (1), causing the (2) rule to run twice.

Would love some thoughts on some techniques on how to handle this kind of logic. I hope I've explained it clearly - if I haven't please ask, and I'll try to clarify. I'm SURE there are simpler ways of doing or thinking about this, and/or better tools that I should be using to sync these mode/scenes.

And on a grander scheme, I would love to know your other techniques for those of you syncing HomeKit and Hubitat/Ra2.

Thanks so much in advance.

Why not just set rule 3 to turn on the switch and leave it at that?

Switch turns on from Alexa
Switch rule (2) runs.

Rule 3 runs and turns on the switch
Switch rule (2) runs.

I may be missing a piece of the puzzle. If what I suggested above doesn't hit the mark or I'm missing something, it would help to see what you've got in place.

@bob692006 Thanks so much for your reply. This solves my problem - Rule 3 would also need to check if the switch is already on when the rule is run (then toggle it off and back on), as sometimes there would be situations where the VS might not be in sync (if individual devices on the Hubitat side were altered for example), so pressing the button again would bring all devices back to the original programmed scene/mode. Thanks for helping with some clarity.

Download the Hubitat app