Conditional Switch?

Hello everyone, I’m new to node-red and I am trying to figure out a flow to control two switch entities, Switch 1 controls the garage upstairs light and switch 2 controls the garage downstairs light. This is what I need:

1st. If switch1 is turned on it should turn switch2 on, if switch2 was off.

2nd. If switch1 turned on switch2, then turning off switch1 should also turn off switch2.

So far I can get the first part but trying to figure out the 2nd part is my problem. I always end up turning it off even if it was on before,

Here’s what I’ve come up with so far.

`

[{"id":"cade29564877d530","type":"server-state-changed","z":"b296b2244ceada51","name":"Upstair Garage Light","server":"77d153ff.91140c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.switch_test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":130,"y":180,"wires":[["69596713019e68dc"],["6a18ebc4a5b660f3"]]},{"id":"6a18ebc4a5b660f3","type":"api-get-history","z":"b296b2244ceada51","name":"Downstairs Light History","server":"77d153ff.91140c","version":0,"startdate":"","enddate":"","entityid":"switch.outlet_south_dormer","entityidtype":"is","useRelativeTime":true,"relativeTime":"20 sec","flatten":false,"output_type":"array","output_location_type":"msg","output_location":"payload","x":170,"y":340,"wires":[["1cd9dfb822828de6","aeae24c03b074e60"]]},{"id":"69596713019e68dc","type":"api-current-state","z":"b296b2244ceada51","name":"Light Off?","server":"77d153ff.91140c","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.outlet_south_dormer","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":340,"y":100,"wires":[["699e9f294ffcf19c"],[]],"outputLabels":["true","false"]},{"id":"1cd9dfb822828de6","type":"debug","z":"b296b2244ceada51","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":380,"wires":[]},{"id":"aeae24c03b074e60","type":"function","z":"b296b2244ceada51","name":"Check Garage Light History","func":"// Check the history of the downstairs garage lights within timeframe and if they were off\n// then allow the upstairs garage light to turn off downstairs lights  as well\nif(msg.payload[0] && msg.payload[0].filter(item => item.state == \"off\").length) {\n    return msg;\n}\n\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":280,"wires":[["b3d0389845fe3617"]]},{"id":"699e9f294ffcf19c","type":"api-call-service","z":"b296b2244ceada51","name":"Turn on Downstairs Garage Light","server":"77d153ff.91140c","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":100,"wires":[[]]},{"id":"b3d0389845fe3617","type":"api-call-service","z":"b296b2244ceada51","name":"Turn Off Downstairs Garage Light","server":"77d153ff.91140c","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":180,"wires":[[]]},{"id":"77d153ff.91140c","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Seems to work but not sure about my function.

[{"id":"05021bfcc6cb15f6","type":"server-state-changed","z":"c628cdea09682a6f","name":"Upstair Garage Light","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.switch_test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":202,"y":592,"wires":[["5490c16e0f268e1e"],["e3e14d912a895a58"]]},{"id":"5490c16e0f268e1e","type":"api-current-state","z":"c628cdea09682a6f","name":"Light Off?","server":"","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.outlet_south_dormer","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"turnOffDownstairs","propertyType":"flow","value":"true","valueType":"bool"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":396,"y":592,"wires":[["e4e8bd6ead20ab6c"],[]],"outputLabels":["true","false"]},{"id":"e4e8bd6ead20ab6c","type":"api-call-service","z":"c628cdea09682a6f","name":"Turn on Downstairs Garage Light","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":636,"y":592,"wires":[[]]},{"id":"e3e14d912a895a58","type":"switch","z":"c628cdea09682a6f","name":"","property":"turnOffDownstairs","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":386,"y":640,"wires":[["3a3dd7635ff08f93","f93c3406b9cea686"],["f93c3406b9cea686"]]},{"id":"3a3dd7635ff08f93","type":"api-call-service","z":"c628cdea09682a6f","name":"Turn Off Downstairs Garage Light","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":636,"y":640,"wires":[[]]},{"id":"f93c3406b9cea686","type":"change","z":"c628cdea09682a6f","name":"","rules":[{"t":"set","p":"turnOffDownstairs","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":606,"y":688,"wires":[[]]}]

Thanks Kermit. I had to switch things around but I managed to get it to work as I needed.

[{"id":"05021bfcc6cb15f6","type":"server-state-changed","z":"b296b2244ceada51","name":"Upstair Garage Light","server":"77d153ff.91140c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.switch_test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":480,"wires":[["5490c16e0f268e1e"],["e3e14d912a895a58"]]},{"id":"5490c16e0f268e1e","type":"api-current-state","z":"b296b2244ceada51","name":"Light Off?","server":"77d153ff.91140c","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.outlet_south_dormer","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"turnOffDownstairs","propertyType":"flow","value":"true","valueType":"bool"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":304,"y":480,"wires":[["e4e8bd6ead20ab6c"],["f93c3406b9cea686"]],"outputLabels":["true","false"]},{"id":"e4e8bd6ead20ab6c","type":"api-call-service","z":"b296b2244ceada51","name":"Turn on Downstairs Garage Light","server":"77d153ff.91140c","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":544,"y":480,"wires":[[]]},{"id":"e3e14d912a895a58","type":"switch","z":"b296b2244ceada51","name":"","property":"turnOffDownstairs","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":170,"y":580,"wires":[["3a3dd7635ff08f93"],[]]},{"id":"3a3dd7635ff08f93","type":"api-call-service","z":"b296b2244ceada51","name":"Turn Off Downstairs Garage Light","server":"77d153ff.91140c","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.outlet_south_dormer","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":544,"y":528,"wires":[[]]},{"id":"f93c3406b9cea686","type":"change","z":"b296b2244ceada51","name":"","rules":[{"t":"set","p":"turnOffDownstairs","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":600,"wires":[[]]},{"id":"77d153ff.91140c","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]