How to get Aqara Wireless Remote Switch to turn on/off the lights?

I have aqara wireless remote switch in home assistant. I use matter on the e1 hub to bring the wireless remote switch into home assistant. I have an automation which turns on my light when i double click the button. Then double clicking again turns the light off.

Now, when i double click the button, it would only turn on or off the lights if the event id of my button is different. For example, if the event id is ‘single press’ and then I double click my button then the light would turn on. But the lights would not turn off when i double click again. The lights would only turn off after i single click my button (which runs another automation for turning on and or the fan) and then double click the button to trigger the toggle lights automation.

I need help with fixing the automation. Or is there another way to do this?

The automation Yaml