Determing how script has been called


My automations have all got a bit messy and once I have a better understanding I will reconfigure them all but for the time being I have another query.

In my lounge, I have several devices that when turned on will then turn other devices on. The main 2 devices are my av receiver and my tv. My TV cant be turned on and off directly so I have purchaed a broadlink RM3 mini which I have configured through HA so can now be turned on and off.

I have an automation that when av receiver is turned on it will turn on TV, and vice versa, if TV is turned on and it will turn AV receiver on.

The problem is say I turn tv on, it then turns av on, which then triggers to turn tv on etc and sometimes things get messed up as the tv doesnt always update its status in HA quickly (DLNA).

Is there anway I can code it so if TV automation turns amp on, the amp automation to turn TV on wont run?

Sorry for long post and hope it makes sense!