Hi,
I was wondering if it was possible to compare values from different payloads in the same function. I keep getting an undefined error for my msg.payload[1]. Or if we can't, anybody would have a better idea?
Here is my flow:
[{"id":"fd617437.ba4bd8","type":"function","z":"14f8d12a.1216bf","name":"Switch","func":"host = msg.topic;\nbattery = msg.payload[0];\npower = msg.payload[1];\n\nswitch(host) {\n case \"mic1\" :\n if (battery === \"< REP 1 BATT_BARS 005 >\") {\n msg.payload.battery = '<i class=\"fa fa-battery-full\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 004 >\") {\n msg.payload.battery = '<i class=\"fa fa-battery-three-quarters\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 003 >\") {\n msg.payload.battery = '<i class=\"fa fa-battery-three-quarters\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 002 >\") {\n msg.payload.battery = '<i class=\"fa fa-battery-half\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 001 >\") {\n msg.payload.battery = '<font color=\"yellow\"><i class=\"fa fa-battery-quarter\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 000 >\") {\n msg.payload.battery = '<font color=\"red\"><i class=\"fa fa-battery-empty\"></i>';\n return [msg, null];\n } else if (battery === \"< REP 1 BATT_BARS 255 >\") {\n msg.payload.battery = '<font color=\"yellow\"><i class=\"fa fa-exclamation-triangle\"></i>';\n return [msg, null];\n } else if (power === \"< REP 1 TX_RF_PWR UNKN >\") {\n msg.payload.battery = '<font color=\"red\"><i class=\"fa fa-times-circle\"></i>';\n return [msg, null];\n }\n break;\n default:\n msg.payload = \"Unknown command\" ;\n return [null, null, msg];\n }\nreturn msg;","outputs":3,"noerr":0,"initialize":"","finalize":"","x":1670,"y":560,"wires":[["5a63a0d2.0192e","639ebaaf.06ff14"],[],["fa5eec2a.6b602"]]},{"id":"5a63a0d2.0192e","type":"debug","z":"14f8d12a.1216bf","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.battery","targetType":"msg","statusVal":"payload","statusType":"auto","x":1920,"y":480,"wires":[]},{"id":"639ebaaf.06ff14","type":"debug","z":"14f8d12a.1216bf","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.power","targetType":"msg","statusVal":"payload","statusType":"auto","x":1910,"y":540,"wires":[]},{"id":"fa5eec2a.6b602","type":"debug","z":"14f8d12a.1216bf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1890,"y":600,"wires":[]},{"id":"3add34e0.bab05c","type":"inject","z":"14f8d12a.1216bf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"mic1","payload":"< REP 1 BATT_BARS 005 >","payloadType":"str","x":1270,"y":540,"wires":[["afe300da.e3e17"]]},{"id":"ddecd044.debda","type":"inject","z":"14f8d12a.1216bf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"0.5","topic":"mic1","payload":"< REP 1 TX_RF_PWR UNKN >","payloadType":"str","x":1260,"y":580,"wires":[["afe300da.e3e17"]]},{"id":"afe300da.e3e17","type":"join","z":"14f8d12a.1216bf","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1530,"y":560,"wires":[["fd617437.ba4bd8","4354a72f.531cd8"]]},{"id":"4354a72f.531cd8","type":"debug","z":"14f8d12a.1216bf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1670,"y":620,"wires":[]}]