Tracking why a light was switched on

I want to switch a light by a motion sensor: if somebody comes into the room, the light goes on. If the motion sensor goes off, the light should go off. But only if it was switched on by the motion sensor. If it was switched on manually, I should not go off.
So the best thing would be if I could set a light attribute “switch reason”. Is that possible?
I want to avoid a separate input_boolean.

how about you show what you have done so far
dont forget to format the code correctly

I’m pretty sure that’s not possible.

Why?