Streamlining Flow

I use a flow to synchronize operation of a couple of lights in my workshop with the state of a third light in that room. My flow watches for a state change of the third light then passes the new state to the other two. I currently uses a function node to determine which state, on or off, should be forwarded to the other two lights. I believe my flow can be shortened by changing the payload message as it passes through an HA call service node. For the life of me I cannot figure out how to code the output payload of the kasa node so that the call service node turns the lights on or off depending on which state is passed to it. Here is a sample of the event that’s passed;

{"event":"PowerEvents","timestamp":"2021-09-19T17:52:51-04:00","powerOn":false,"state":false}

I tried using if/then/else statements but I’m always coming up with an error. Here is my code as it stands.

[{"id":"2ee38f5f.ea8f4","type":"inject","z":"3cc42d.6d483bd4","name":"startPowerEvents","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"startPowerEvents","payloadType":"str","x":170,"y":160,"wires":[["1a1a44.0ba4e5bd","ac00e361.2820e","a00e2ab5.f2b988"]]},{"id":"af7ac75b.7eb198","type":"comment","z":"3cc42d.6d483bd4","name":"Syncronize Workshop Light Switch","info":"","x":500,"y":460,"wires":[]},{"id":"a00e2ab5.f2b988","type":"kasa","z":"3cc42d.6d483bd4","name":"Work Bench - HS200(US)","device":"192.168.86.110","interval":60000,"eventInterval":"2500","payload":"getQuickInfo","payloadType":"info","debug":false,"x":470,"y":540,"wires":[["fe24dfec549419cd","a745df8016ce965e","439c768.ae2a288"]]},{"id":"fe24dfec549419cd","type":"debug","z":"3cc42d.6d483bd4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"","statusType":"msg","x":800,"y":480,"wires":[]},{"id":"439c768.ae2a288","type":"switch","z":"3cc42d.6d483bd4","name":"On-Off","property":"payload.powerOn","propertyType":"msg","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":790,"y":540,"wires":[["d2c610ee.1098","c3a407496be97486"],["d8d5534c.c7368","703a4db3b38c5c7f"]],"outputLabels":["On","Off"]},{"id":"d2c610ee.1098","type":"api-call-service","z":"3cc42d.6d483bd4","name":"Workshop On","server":"fcf9b76b.256a88","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.freezer, switch.workbench_power","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1000,"y":500,"wires":[[]]},{"id":"d8d5534c.c7368","type":"api-call-service","z":"3cc42d.6d483bd4","name":"Workshop Off","server":"fcf9b76b.256a88","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.freezer, switch.workbench_power","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1000,"y":580,"wires":[[]]},{"id":"c3a407496be97486","type":"debug","z":"3cc42d.6d483bd4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1260,"y":460,"wires":[]},{"id":"703a4db3b38c5c7f","type":"debug","z":"3cc42d.6d483bd4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1280,"y":560,"wires":[]},{"id":"a745df8016ce965e","type":"api-call-service","z":"3cc42d.6d483bd4","name":"Can I USe One Node To Operate Lights","server":"fcf9b76b.256a88","version":3,"debugenabled":true,"service_domain":"homeassistant","service":"","entityId":"switch.freezer, switch.workbench_power","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload.powerOn","propertyType":"msg","value":"true","valueType":"jsonata"}],"queue":"none","x":1080,"y":680,"wires":[["03987ad623c4711e"]]},{"id":"03987ad623c4711e","type":"debug","z":"3cc42d.6d483bd4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1390,"y":680,"wires":[]},{"id":"fcf9b76b.256a88","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}]

How would I go about coding the output of the “Can I USe One Node To Operate Lights” node to perform the function I’m after?

image

[{"id":"89dfa973fc9a7e99","type":"inject","z":"ffbd7f06.4a014","name":"off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\":\"PowerEvents\",\"timestamp\":\"2021-09-19T17:52:51-04:00\",\"powerOn\":false,\"state\":false}","payloadType":"json","x":128,"y":1568,"wires":[["aa5e88bbf4bfbcfe"]]},{"id":"282b28eb805043ee","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":1568,"wires":[]},{"id":"aa5e88bbf4bfbcfe","type":"change","z":"ffbd7f06.4a014","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \"service\": payload.powerOn ? \"turn_on\" : \"turn_off\"}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1568,"wires":[["282b28eb805043ee"]]},{"id":"bdc1f28fb109be83","type":"inject","z":"ffbd7f06.4a014","name":"on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"event\":\"PowerEvents\",\"timestamp\":\"2021-09-19T17:52:51-04:00\",\"powerOn\":true,\"state\":false}","payloadType":"json","x":130,"y":1616,"wires":[["aa5e88bbf4bfbcfe"]]}]

Awesome! Thank you @Kermit