Automation to only turn off switch if last turned on by automation

You could do something like this: