Here is one way to store the IR mapping data as a CSV spreadsheet:
DeviceID,IRFunction,IRType,IRCode,frequency,preamble,repeat
ZG-ZW410,IN-1,JSON,"343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,21,22,21,22,63,22,21,22,21,22,21,22,63,22,21,22,63,22,63,22,21,22,63,22,63,22,63,22,1512,343,85,22,3700",37735,,1
ZG-ZW410,IN-2,JSON,"344,187,22,23,22,23,22,23,22,23,22,23,22,23,22,23,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,23,22,23,22,69,22,23,22,69,22,69,22,23,22,23,22,23,22,69,22,23,22,69,22,23,22,23,22,69,22,69,22,69,22,1661,343,93,22,3999,343,93,22,4100",41450,,1
ZG-ZW410,IN-3,JSON,"343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,63,22,63,22,63,22,21,22,21,22,21,22,63,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,1519,343,85,22,3700",37914,,1
ZG-ZW410,IN-4,JSON,"345,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,1516,343,85,22,3649,343,85,22,3649,343,85,22,3700",37825,,1
And here is what it looks like when parsed into a JS Array of objects:
[
{
"DeviceID": "ZG-ZW410",
"IRFunction": "IN-1",
"IRType": "JSON",
"IRCode": "343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,21,22,21,22,63,22,21,22,21,22,21,22,63,22,21,22,63,22,63,22,21,22,63,22,63,22,63,22,1512,343,85,22,3700",
"frequency": 37735,
"repeat": 1
},
{
"DeviceID": "ZG-ZW410",
"IRFunction": "IN-2",
"IRType": "JSON",
"IRCode": "344,187,22,23,22,23,22,23,22,23,22,23,22,23,22,23,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,23,22,23,22,69,22,23,22,69,22,69,22,23,22,23,22,23,22,69,22,23,22,69,22,23,22,23,22,69,22,69,22,69,22,1661,343,93,22,3999,343,93,22,4100",
"frequency": 41450,
"repeat": 1
},
{
"DeviceID": "ZG-ZW410",
"IRFunction": "IN-3",
"IRType": "JSON",
"IRCode": "343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,63,22,63,22,63,22,21,22,21,22,21,22,63,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,1519,343,85,22,3700",
"frequency": 37914,
"repeat": 1
},
{
"DeviceID": "ZG-ZW410",
"IRFunction": "IN-4",
"IRType": "JSON",
"IRCode": "345,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,1516,343,85,22,3649,343,85,22,3649,343,85,22,3700",
"frequency": 37825,
"repeat": 1
}
]
Not to throw another spanner in the gears, but I'm growing to like the YAML format even more:
- DeviceID: ZG-ZW410
IRFunction: IN-1
IRType: JSON
IRCode: >-
343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,21,22,21,22,63,22,21,22,21,22,21,22,63,22,21,22,63,22,63,22,21,22,63,22,63,22,63,22,1512,343,85,22,3700
frequency: 37735
preamble: ''
repeat: 1
- DeviceID: ZG-ZW410
IRFunction: IN-2
IRType: JSON
IRCode: >-
344,187,22,23,22,23,22,23,22,23,22,23,22,23,22,23,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,23,22,23,22,69,22,23,22,69,22,69,22,23,22,23,22,23,22,69,22,23,22,69,22,23,22,23,22,69,22,69,22,69,22,1661,343,93,22,3999,343,93,22,4100
frequency: 41450
preamble: ''
repeat: 1
- DeviceID: ZG-ZW410
IRFunction: IN-3
IRType: JSON
IRCode: >-
343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,63,22,63,22,63,22,21,22,21,22,21,22,63,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,1519,343,85,22,3700
frequency: 37914
preamble: ''
repeat: 1
- DeviceID: ZG-ZW410
IRFunction: IN-4
IRType: JSON
IRCode: >-
345,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,1516,343,85,22,3649,343,85,22,3649,343,85,22,3700
frequency: 37825
preamble: ''
repeat: 1
It's a superset of JSON, without all the punctuation and restrictions on embedded newlines.
Here is a set of flows that show how to convert your data into either csv or yaml files. Using an inject node, it then reads those files, converts the data into the JS objects that will later need to be sent to the gateway, and stores them indexed by DeviceID and IRFunction into a flow variable called "IRCodeMap". This process only needs to be done once at startup, so the code map is available to the other flows.
[{"id":"1c8a64c7.1f718b","type":"yaml","z":"f9a2eec9.c2e26","property":"payload","name":"","x":510,"y":1520,"wires":[["6e7f6048.2bf41","d662fa6d.6027b8"]]},{"id":"b6c1d99.3e55228","type":"csv","z":"f9a2eec9.c2e26","name":"","sep":",","hdrin":true,"hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","x":510,"y":1480,"wires":[["d662fa6d.6027b8"]]},{"id":"dd4fc694.791198","type":"file in","z":"f9a2eec9.c2e26","name":"","filename":"irCodes.yaml","format":"utf8","chunk":false,"sendError":false,"x":310,"y":1520,"wires":[["1c8a64c7.1f718b"]]},{"id":"a348ee2e.03fa3","type":"file in","z":"f9a2eec9.c2e26","name":"","filename":"irCodes.csv","format":"utf8","chunk":false,"sendError":false,"x":310,"y":1480,"wires":[["b6c1d99.3e55228"]]},{"id":"5b3f1f1b.00d64","type":"inject","z":"f9a2eec9.c2e26","name":"","topic":"csv","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":1480,"wires":[["a348ee2e.03fa3"]]},{"id":"ecfca482.237b88","type":"inject","z":"f9a2eec9.c2e26","name":"","topic":"yaml","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":1520,"wires":[["dd4fc694.791198"]]},{"id":"642ee161.c812","type":"comment","z":"f9a2eec9.c2e26","name":"Build IR Code mapping files","info":"","x":180,"y":1340,"wires":[]},{"id":"d662fa6d.6027b8","type":"debug","z":"f9a2eec9.c2e26","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1480,"wires":[]},{"id":"d5db4ceb.e224c","type":"inject","z":"f9a2eec9.c2e26","name":"irCodes.json","topic":"json","payload":"{\"ZG-ZW410/IN-1\":{\"frequency\":37735,\"irCode\":\"343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,21,22,21,22,63,22,21,22,21,22,21,22,63,22,21,22,63,22,63,22,21,22,63,22,63,22,63,22,1512,343,85,22,3700\",\"preamble\":\"\",\"repeat\":1},\"ZG-ZW410/IN-2\":{\"frequency\":41450,\"irCode\":\"344,187,22,23,22,23,22,23,22,23,22,23,22,23,22,23,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,23,22,23,22,69,22,23,22,69,22,69,22,23,22,23,22,23,22,69,22,23,22,69,22,23,22,23,22,69,22,69,22,69,22,1661,343,93,22,3999,343,93,22,4100\",\"preamble\":\"\",\"repeat\":1},\"ZG-ZW410/IN-3\":{\"frequency\":37914,\"irCode\":\"343,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,21,22,63,22,63,22,63,22,63,22,21,22,21,22,21,22,63,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,1519,343,85,22,3700\",\"preamble\":\"\",\"repeat\":1},\"ZG-ZW410/IN-4\":{\"frequency\":37825,\"irCode\":\"345,171,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,21,22,63,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,63,22,63,22,63,22,63,22,63,22,63,22,63,22,1516,343,85,22,3649,343,85,22,3649,343,85,22,3700\",\"preamble\":\"\",\"repeat\":1}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1380,"wires":[["89c0e126.325a6"]]},{"id":"ceeb2110.8bb41","type":"csv","z":"f9a2eec9.c2e26","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\n","temp":"DeviceID,IRFunction,IRType,IRCode,frequency,preamble,repeat","skip":"0","x":510,"y":1360,"wires":[["819667ca.861ba8"]]},{"id":"c46ff270.aa17","type":"yaml","z":"f9a2eec9.c2e26","property":"payload","name":"","x":510,"y":1400,"wires":[["77f80ad7.8685c4"]]},{"id":"89c0e126.325a6","type":"change","z":"f9a2eec9.c2e26","name":"parse into array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$spread(payload).(\t $key := $keys($)[0];\t $dev := $.*;\t {\t \"DeviceID\": $substringBefore($key, \"/\"),\t \"IRFunction\": $substringAfter($key, \"/\"),\t \"IRType\": \"JSON\",\t \"IRCode\": $dev.irCode,\t \"frequency\": $dev.frequency,\t \"preamble\": $dev.preamble,\t \"repeat\": $dev.repeat\t }\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":1380,"wires":[["ceeb2110.8bb41","c46ff270.aa17"]]},{"id":"819667ca.861ba8","type":"file","z":"f9a2eec9.c2e26","name":"","filename":"irCodes.csv","appendNewline":true,"createDir":false,"overwriteFile":"true","x":690,"y":1360,"wires":[]},{"id":"77f80ad7.8685c4","type":"file","z":"f9a2eec9.c2e26","name":"","filename":"irCodes.yaml","appendNewline":true,"createDir":false,"overwriteFile":"true","x":690,"y":1400,"wires":[]},{"id":"6e7f6048.2bf41","type":"change","z":"f9a2eec9.c2e26","name":"","rules":[{"t":"set","p":"IRCodeMap","pt":"flow","to":"payload {\t $.DeviceID: $.{\t IRFunction:\t IRType = \"JSON\" ?\t {\t \"frequency\": frequency,\t \"irCode\": IRCode,\t \"preamble\": preamble,\t \"repeat\": repeat\t } :\t IRType = \"TCP\" ?\t {\t \"tcpCode\": TCPCode,\t \"preamble\": preamble,\t \"repeat\": repeat\t } :\t \"Invalid type: \" & IRType \t } ~> $merge()\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":1520,"wires":[[]]},{"id":"f263829b.d9e78","type":"inject","z":"f9a2eec9.c2e26","name":"","topic":"ZG-ZW410","payload":"IN-1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1660,"wires":[["7a41d875.ce8e88"]]},{"id":"f85553c7.3c2e5","type":"inject","z":"f9a2eec9.c2e26","name":"","topic":"ZG-ZW410","payload":"IN-2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1700,"wires":[["7a41d875.ce8e88"]]},{"id":"7a41d875.ce8e88","type":"change","z":"f9a2eec9.c2e26","name":"lookup IRCode data","rules":[{"t":"set","p":"json","pt":"msg","to":"$flowContext(\"IRCodeMap\")\t ~> $lookup($$.topic)\t ~> $lookup($$.payload)","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"topic & \"/\" & payload","tot":"jsonata"},{"t":"move","p":"json","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":1680,"wires":[["ccb39610.0d5368"]]},{"id":"ccb39610.0d5368","type":"debug","z":"f9a2eec9.c2e26","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":1680,"wires":[]},{"id":"caeba302.2a3e3","type":"inject","z":"f9a2eec9.c2e26","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":1620,"wires":[["938ed2e8.559a2"]]},{"id":"938ed2e8.559a2","type":"change","z":"f9a2eec9.c2e26","name":"verify IRCodeMap","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"IRCodeMap\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":1620,"wires":[["ccb39610.0d5368"]]},{"id":"1797c703.3d0569","type":"comment","z":"f9a2eec9.c2e26","name":"Check IR Code mapping files","info":"","x":180,"y":1440,"wires":[]},{"id":"fe5a4ff2.25c44","type":"comment","z":"f9a2eec9.c2e26","name":"Lookup IR Codes from topic/payload","info":"","x":200,"y":1580,"wires":[]}]
The last flow injects a msg like { "topic": "ZG-ZW410", "payload": "IN-2" }
-- this is wired to a change
node that uses the flow context to lookup the json data to be sent to the device, sending the original data structure that you requested:
{"frequency":41450,"irCode":"344,187,22,23,22,23,22,23,22,23,22,23,22,23,22,23,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,69,22,23,22,23,22,69,22,23,22,69,22,69,22,23,22,23,22,23,22,69,22,23,22,69,22,23,22,23,22,69,22,69,22,69,22,1661,343,93,22,3999,343,93,22,4100","preamble":"","repeat":1}
--Steve