[{"id":"ca2ba311.83e5","type":"function","z":"ffbd7f06.4a014","name":"","func":"if (msg.payload.length === 0) {\n msg.payload.service = \"turn_off\";\n return msg;\n}\n\nlet color = \"blue\" // default to person2\nif (msg.payload.length == 2) {\n color = \"purple\";\n} else if (msg.payload[0].entity_id == \"device_tracker.person1\") {\n color = \"red\";\n}\n\nmsg.payload = {\n data: {\n \"color_name\": color\n }\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":722,"y":784,"wires":[["c73875e7.3076d8"]]},{"id":"f4ee87a5.83de18","type":"ha-get-entities","z":"ffbd7f06.4a014","server":"2dad33ee.42bf5c","name":"","rules":[{"property":"entity_id","logic":"includes","value":"device_tracker.person1,device_tracker.person2","valueType":"str"},{"property":"state","logic":"is","value":"home","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":566,"y":784,"wires":[["ca2ba311.83e5"]]},{"id":"c73875e7.3076d8","type":"api-call-service","z":"ffbd7f06.4a014","name":"Light","server":"2dad33ee.42bf5c","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.light\"}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":866,"y":784,"wires":[[]]},{"id":"5c072cb7.c8c374","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","server":"2dad33ee.42bf5c","entityidfilter":"device_tracker.person1,device_tracker.person2","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":248,"y":784,"wires":[["f4ee87a5.83de18"]]}]
Another option
[{"id":"3ace1d47.60aa72","type":"function","z":"ffbd7f06.4a014","name":"","func":"//If person1 is home -> LED = Red\n//If person2 is home -> LED = Blue\n//If both are home -> LED = Purple\n//If no one is home -> LED = off\nif (msg.payload.length === 0) return [null, msg];\n\nlet color = \"blue\" // default to person2\nif (msg.payload.length == 2) {\n color = \"purple\";\n} else if (msg.payload[0].entity_id == \"device_tracker.person1\") {\n color = \"red\";\n}\nmsg.color = color;\nreturn [msg, null];","outputs":2,"noerr":0,"x":770,"y":896,"wires":[["fddf289d.e6e4a8"],["b9c08f14.0c6aa"]]},{"id":"aed9fda.d304a","type":"ha-get-entities","z":"ffbd7f06.4a014","server":"2dad33ee.42bf5c","name":"","rules":[{"property":"entity_id","logic":"includes","value":"device_tracker.person1,device_tracker.person2","valueType":"str"},{"property":"state","logic":"is","value":"home","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":614,"y":896,"wires":[["3ace1d47.60aa72"]]},{"id":"b9c08f14.0c6aa","type":"api-call-service","z":"ffbd7f06.4a014","name":"Turn off Light","server":"2dad33ee.42bf5c","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.light\"}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":934,"y":944,"wires":[[]]},{"id":"fddf289d.e6e4a8","type":"api-call-service","z":"ffbd7f06.4a014","name":"Set color","server":"2dad33ee.42bf5c","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.light\",\"color_name\":\"{{color}}\"}","render_data":true,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":924,"y":896,"wires":[[]]},{"id":"f81b3b78.116248","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","server":"2dad33ee.42bf5c","entityidfilter":"device_tracker.person1,device_tracker.person2","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":296,"y":896,"wires":[["aed9fda.d304a"]]}]