I think the most revealing result is the last one you mentioned: the problem never occurs if the automation is activated manually. If the automation is activated by its trigger, then the problem occurs (but only if the switch action is first).
When an automation is activated manually, its trigger (and condition, if any) is skipped. That means there’s no checking of the temperature or the switch’s state.
Try one more thing, remove the test for the switch’s state:
This is to determine if there’s any ‘quantum entanglement’ between the act of testing the switch’s state and the act of setting the switch’s state. The two shouldn’t influence each other and this test should prove/disprove it.