Double click event from a rocker switch

Hi, I’m starting to understand the logic of esphome code and I realize now that my previous post had some silly questions. Please disregard them.

I got it all working with the following code:

esphome:
  name: i3-kitchen
  on_boot:
    priority: 600
    then:
      - binary_sensor.template.publish:
          id: template_sw1
          state: ON
      - binary_sensor.template.publish:
          id: template_sw2
          state: OFF

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "####################################"

ota:
  password: "###############################"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "I3-Kitchen Fallback Hotspot"
    password: "##############"

captive_portal:

# Physical wall switch sensor automation
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO12
      mode: INPUT
    name: i3-kitchen Input 1
    id: wallswitch1
    internal: true
    filters:
      - delayed_on_off: 50ms
    on_state:
      then:
        - if:
            condition:
               lambda: 'return id(template_sw1).state;'
            then:
              - binary_sensor.template.publish:
                  id: template_sw1
                  state: OFF
            else:
              - binary_sensor.template.publish:
                  id: template_sw1
                  state: ON
    on_multi_click:
    - timing:
        - ON for at most 500ms
      then:
        - if:
            condition:
               lambda: 'return id(template_sw2).state;'
            then:
              - binary_sensor.template.publish:
                  id: template_sw2
                  state: OFF
            else:
              - binary_sensor.template.publish:
                  id: template_sw2
                  state: ON
    - timing:
        - OFF for at most 500ms
      then:
        - if:
            condition:
               lambda: 'return id(template_sw2).state;'
            then:
              - binary_sensor.template.publish:
                  id: template_sw2
                  state: OFF
            else:
              - binary_sensor.template.publish:
                  id: template_sw2
                  state: ON

# Virtual switches
  - platform: template
    name: "Kitchen counter LED switch"
    id: template_sw1
  - platform: template
    name: "Kitchen cabinets LED switch"
    id: template_sw2

There is just one small issue with the above code. When I quickly flip the wall switch ON->OFF->ON or OFF->ON->OFF, the on_multi_click automation works and it toggles the value of the template_sw2 but it also momentarily changes the value of the template_sw1 which is undesirable behaviour.

Would you have any idea how to fix it?