Automation of two Aqara wall switches

Hello,

Here is my scenario.
In a corridor i have two physical switches (sw-01 & sw-02) and each one turn on one lamp (let’s say light-01 & light-02)
I replaced the physical switches with two smart switches from Aqara (H1 EU wall switch non-neutral).

What i want to active is sort of 3way switch, so when i turn on one switch , both lights to turn on.And when i turn off one of the switches , both lights to turn off.

How i set it up is , i created a group with the two switches , and i created two automation.
The first automation turns on the switches of the group when sw-01 or sw-02 is pressed, and the second automation turn off the switches of the group when sw-01 or sw-02 is pressed.

In theory that sound good to me , but in reality do not work good.
Sometimes i noticed that lights goes crazy. lights turn on and off constantly and this keeps going till i restart HA. Is like they get into an infinity loop.
This usually happens when i perform two actions in short period, turn on and off immediately for example sw-01.

Any tips or an idea how can i solve this issue?
Thanks!

Please post the automations (correctly formatted), but I think you might not need two automations: just trigger on any state change of any of those two switches in one automation and call the light toggle service on both lights.

thanks,
will check also your approach.

Here is my automation

- id: '1651948972739'                                        
  alias: corridor_switches_off                               
  description: ''                                            
  trigger:                                                   
  - platform: device                                         
    type: turned_off                                         
    device_id: 49c135d1598f8a06f5fd8caf49483d90              
    entity_id: switch.switch_corridor_mirror3                
    domain: switch                                           
  condition: []                                              
  action:                                                    
  - service: switch.turn_off                                 
    data: {}                                                 
    target:                                                  
      entity_id: switch.corridor_group_3                     
  mode: single                                               
- id: '1652022744390'                                        
  alias: corridor_switches_on                                
  description: ''                                            
  trigger:                                                   
  - platform: device                                         
    type: turned_on                                          
    device_id: 49c135d1598f8a06f5fd8caf49483d90              
    entity_id: switch.switch_corridor_mirror3                
    domain: switch                                           
  condition: []                                              
  action:                                                    
  - service: switch.turn_on                                  
    data: {}                                                 
    target:                                                  
      entity_id: switch.corridor_group_3                     
  mode: single