3 or more ways MQTT light switches sometimes get out of sync and lights start flashing

Hello, i Have an automation that let me use 2 or more lights switches to turn one light circuit. The problem is that sometimes get out of sync and the lights start blinking because one switch turn on the other an then start a loop. I want to do an automation that turn off the 3 way automation when this happens and then after some time turn it back on.

The 3 way switch that i use is this one:

## PLAYROOM LIGHTS
  • alias: Play Room Entrance Lights 924
    trigger:
    platform: state
    entity_id:
    - switch.playroom_1_2
    - switch.playroom_2_2
    - switch.playroom_3_2
    action:
    service_template: >
    {% if trigger.to_state.state == “on” %}
    switch.turn_on
    {% elif trigger.to_state.state == “off” %}
    switch.turn_off
    {% endif %}
    entity_id:
    - switch.playroom_1_2
    - switch.playroom_2_2
    - switch.playroom_3_2

remember to use the blue box at the top of the page when formatting code/templates/etc…

Instead of using a switch.turn_on/off try using a scene . It should turn on/off all lights at the same time.

or use groups…

groups:

garage_stairs:
  name: Garage Stairs
  control: hidden
  icon: mdi:home-assistant
  entities:
    - switch.garage_stairs
    - switch.garage_stairs_down

automations:

- alias: Garage Stairs On
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: group.garage_stairs
    to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: group.garage_stairs

- alias: Garage Stairs Off
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: switch.garage_stairs
      to: 'off'
    - platform: state
      entity_id: switch.garage_stairs_down
      to: 'off'
  action:
    service: homeassistant.turn_off
    entity_id: group.garage_stairs

Perfect, thanks