Previous state of a device

I have an aqara switch module that can be controlled by either the physical light switch, or automation.

One automation triggers when the physical switch is pressed, but its possible its already been turned on by a different automation trigger by another sensor.

If the other automation has triggered the switch and turned it on, and someone then presses the physical switch, it will toggle it off. But it would be useful to know the current state of the switch and if its already on, leave it on.

I think I have figured out another way of doing this. Instead of the trigger being on or off, I have used ‘toggle’, and I then have an if condition to determine the current state of the switch.