Helper flag resets itself!

Hi all
I have an old AC unit that is controlled by IR. Unfortunately it has the same IR code for on and off so I created a helper flag that is either set to on or off by the relevant automation when triggered by temperature.
It all works fine until the flag randomly resets itself to off!! There’s no entry in the log or history file relating to something setting the flag to off, it just happens.
Does anyone have any ideas as to why this might happen and what to do to stop it??

Please clarify what you mean by “helper flag”.

Ah yes sorry.
I created a toggle helper called AC flag, so that I could reference the state of the device in automations.
It’s this toggle that randomly flips to off instead of only being changed by the automations that are supposed to set it.
Like I said, there is nothing in the history for the helper that states what changes its state, which is why I’m struggling to debug it.
This is the history:-

Sure looks to me like it’s telling you exactly why it turned off, because of your automation called ‘Office AC off’.

Not quite as simple as that. If you look at the timeline you’ll see there are 2 on events, the first was the automation as expected. However, the toggle then sets to off by itself (nothing in the history you note). I then manually set it to on again to make sure the off automation does its job, which it does. The issue is that the toggle sets to off by itself between the 2 on events without logging anything in the history.