I assume what you are saying is, if command switch is on and safety switch gets turned on, then relay should not be activated until command switch is turned off and back on again.
Usually to disable an input, we would use the gate node, but turning on the safety would immediately pass the state of command switch, so it would immediately enable the relay if command switch is on. You want to enable the command switch only if safety is on AND command is off. That would look like this (the tweak-boolean on the right is the safety – true means we are live; left is the command switch; watch node at the bottom represents relay):
There are two problems with this.
- Turning on the command switch disables the gate, which can happen before the new switch state has passed through it. We could fix this by adding a defer node between the command button and the “and” node to guarantee that the new switch state reaches gate before the gate is disabled.
- There is no good way to turn the relay back off.
I’m thinking we probably need a flip-flop to remember current relay state instead of just using logic to calculate it. We could use the gate code above (with delay node added), but I think we can do it more directly:
The “and” node says that we only have true when both switches are true and the command switch was off (“defer” of “not” of command switch). This will obviously not stay true for long since it goes back to false as soon as defer “expires”, but all we need is a quick pulse to set the flip-flop.
The puls… nodes are both pulse-on-false. If either switch is turned off, we immediately force the flip-flop (and hence the relay) to off.
There is one bug/feature with this code…it turns the relay on if both switches are on at power-up. Adding a delay that starts on boot seems to resolve this:
Now the delay timer needs to NOT be active before relay can be activated…in this case, at least 1 second after boot. If both switches are on when delay expires, we don’t have condition that command switch was off, so relay is not activated until command switch is turned off and back on.
Bonus, if you remove the wire from command switch to the “and” node and reduce the “and” to only 3 inputs, the “and” node can now light a warning light that the system is armed. Add a new 2-input “and” that takes input from command switch and the 3-input “and” node. Use 2-input “and” to SET the flip-flop instead of wiring directly from the 3-input “and”.