Can a tag toggle between two states?
The tag cannot, because it remembers nothing at all between reads. Something else has to hold the state, and where that something lives is what decides whether the toggle stays reliable or drifts out of step with the thing it controls.
The tag has no memory
A tag is powered only while it is being read, and it retains nothing about having been read. It cannot know whether it is the first tap or the fifth.
So a toggle is never implemented by the tag. It is implemented by whatever receives the tap and decides what the opposite of the current state is.
That is worth stating because people write two records to a tag expecting alternation, which is not something a tag can do.
Where the state lives
On the phone, if an automation application tracks it. Reliable while that phone is the only thing acting, and wrong the moment anything else changes the state.
In the device or system being controlled, which is the good answer: ask the lamp what it is doing and do the opposite.
On a server, for anything reached through an address, which behaves the same way.
The rule is that the state should live with the thing that has it, not with the thing that asks.
How a toggle drifts
Somebody uses the wall switch. The phone still believes the light is off, so the next tap turns it off when you wanted it on.
The tag is read twice from one gesture, because leaving and re entering the field counts as two taps, and the toggle returns to where it started.
A second person taps the same tag from their own phone, which has its own idea of the state.
All three produce the same symptom: a tag that seems to work sometimes and to do nothing at others.
What works better
Two tags, one per state, which removes the question entirely and costs one more object.
One tag that sets a state rather than flipping it, which is the right answer when you almost always want the same outcome.
A toggle implemented by the controlled system, which knows the truth.
And a duration where one applies, since a state that ends by itself never needs a second tap at all.
Frequently asked questions
Can I write two records so they alternate?
No. The phone acts on the first record it can handle, and a tag has no memory of previous reads.
Why does my toggle end up backwards?
Either something else changed the state, or the tag was read twice from one gesture. Both leave the toggle out of step.
What is the most reliable arrangement?
Letting the controlled system decide, since it knows the actual state. Two tags is the simple alternative.
Does a duration avoid this?
Entirely. A state that ends by itself never needs a second tap and cannot drift.