You could set a Boolean variable to keep track of toggle switch positions, however if you change a switch by clicking it ingame, the variable will no longer have the same state as the ingame switch.
It is theoretically possible to get ingame switch states for DCS using LUA scripting and a VoiceAttack plugin, but I'm not personally aware of anyone maintaining such a thing (it doesn't help that there is apparently no standardized method for getting these switch states in different modules).
This topic is an attempt to explain the basics of control flow ("IF/THEN").
A basic conditional keypress would look something like
Begin Boolean Compare : [>masterArm] Does Not Equal True
Press Left Shift+M keys and hold for 0,06 seconds and release
Set Boolean [>masterArm] to True
End Condition
I.E. if the last known toggle state is not on (represented by true), make it on and keep that value for later reference.
A command for switching the same control off would do the inverse: Check whether the toggle is off, and if not turn it off and save that value.
Make sure you check the "Evaluate 'Not Set' as false" option on the "Begin a Conditional (If Statement) Block" action's "True/False (Boolean)" tab.
A tip for switches that have multiple positions, have keyboard shortcuts for either direction, and stop at either end: Rather than keeping track of their state, unless whatever the switch is controlling would be adversely affected by doing so, you can go to either end position and work back or forward from there.
E.G. if you have a switch that has "off", "standby", and "on" positions, if you want "standby", you go toward off twice (in case the current state is "on"), then toward "on" once, making the final position "standby".
This can normally be done quickly enough to barely be noticeable.
If there are more positions, you can also optimize this by going to the side that's closest to the desired end position, E.G. if you have five positions, and you want the fourth, you'd go toward five five times, then one toward one to end up at four, rather than going toward one five times, then toward five four times.