I had a sample of code that i use...........right but not practical to use. Do you know a better way?
[{"id":"93bf5ef6.a059","type":"delay","z":"9bbffea9.f46ad","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":590,"y":280,"wires":[["8f918f1d.c225d"]]},{"id":"92860ae4.b57278","type":"change","z":"9bbffea9.f46ad","name":"Clear","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":380,"wires":[["9a0f490e.977568"]]},{"id":"8f918f1d.c225d","type":"exec","z":"9bbffea9.f46ad","command":"tail -n20 /home/pi/logging_history.csv | cat","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Cat","x":790,"y":280,"wires":[["5c9b4292.ae818c"],[],[]]},{"id":"9a0f490e.977568","type":"ring-buffer","z":"9bbffea9.f46ad","name":"","capacity":"20","order":"new-to-old","sendOnlyIfFull":false,"pushAfterClear":false,"extra":false,"perTopic":false,"x":1400,"y":320,"wires":[["8b4c07f0.3e6a38"]]},{"id":"5c9b4292.ae818c","type":"split","z":"9bbffea9.f46ad","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":990,"y":280,"wires":[["42f3140a.a9e9ec"]]},{"id":"b1e1bcef.39c69","type":"debug","z":"9bbffea9.f46ad","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":320,"wires":[]},{"id":"8b4c07f0.3e6a38","type":"ui_template","z":"9bbffea9.f46ad","group":"4698ecb8.dd1894","name":"Command history","order":6,"width":25,"height":20,"format":"<table id=\"table\" border=\"1\">\n\n<style>\ntable {\n font-family: arial, sans-serif;\n border-collapse: collapse;\n width: 100%;\n}\n\ntd, th {\n border: 1px solid #dddddd;\n text-align: center;\n padding: 8px;\n}\n\ntr:nth-child(even) {\n background-color: teal;\n}\n</style>\n <tr>\n <th width=80 >Date</th>\n <th width=20 >Nr</th> \n <th width=300 >Message</th>\n <th width=10 >Status</th>\n </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload track by $index\">\n <td class=\"text\" width=80 ><div align=\"left\">{{row.split(\";\")[0]}}</div></td>\n <td class=\"text\" width=20><div align=\"center\">{{row.split(\";\")[1]}}</div></td>\n <td class=\"text\" width=300><div align=\"left\">{{row.split(\";\")[2]}}</div></td>\n <td class=\"text\" width=10><div align=\"center\">{{row.split(\";\")[3]}}</div></td>\n </tr>\n\n </tbody>\n</table>\n\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1630,"y":320,"wires":[[]]},{"id":"42f3140a.a9e9ec","type":"switch","z":"9bbffea9.f46ad","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":1170,"y":280,"wires":[["9a0f490e.977568"]]},{"id":"7a6e648c.d6d92c","type":"comment","z":"9bbffea9.f46ad","name":"Creo storico allarmi","info":"","x":150,"y":40,"wires":[]},{"id":"52e6b76c.b367d8","type":"inject","z":"9bbffea9.f46ad","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":100,"wires":[["b1a33a61.0eaf38"]]},{"id":"b1a33a61.0eaf38","type":"file in","z":"9bbffea9.f46ad","name":"","filename":"/home/pi/alarm.csv","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":430,"y":100,"wires":[["50abce5e.f788b"]]},{"id":"31a84350.80b17c","type":"function","z":"9bbffea9.f46ad","name":"Creo array di object da elenco allarmi","func":"var alarm = new Array(300);\nalarm=msg.payload;\nglobal.set('alarms',alarm);\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":100,"wires":[[]]},{"id":"50abce5e.f788b","type":"csv","z":"9bbffea9.f46ad","name":"","sep":";","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"x":610,"y":100,"wires":[["31a84350.80b17c"]]},{"id":"6e1676a9.792368","type":"function","z":"9bbffea9.f46ad","name":"Select from array","func":"var date;\ndate = new Date();\ndate = (date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));\n\n//Copio valori da array creato\nvar Topics=new Array(300);\nTopics=global.get('alarms');\n\n//Creo input array\nvar IntIn=new Array(32);\nIntIn[0] = msg.payload.Allarmi_1;\nIntIn[1] = msg.payload.Allarmi_2;\n\n\n//array di appoggio\nvar OutputBit = new Array(32);\nvar old_OutputBit = context.get('old_OutputBit')||0;\nvar index = new Array(32);\nvar old_index = context.get('old_index')||0;\n\n//contatori indipendenti\nvar c = 0;\nvar a = 0;\n// A loop that will run 16 times checking the value of each bit.i will increment 1, 2, 4, 8, 16 and so on. \n//& is a bitwiseand bit\nfor (h = 0; h <= 1; h++){ \nc=0; \n for (i = 1; i <= 32768; i = i * 2){ \n \n if ((IntIn[a] & i) > 0) {\n index[c+(a*16)]=1;\n } else {\n index[c+(a*16)]=0;\n }\n \n if (index[c+(a*16)]!=old_index[c+(a*16)]) {\n OutputBit[c+(a*16)] = {payload:(date+';'+(Topics[c+(a*16)].col1)+';'+(Topics[c+(a*16)].col2)+';'+index[c+(a*16)])};\n } else {\n OutputBit[c+(a*16)] = old_OutputBit[c+(a*16)];\n }\n \n c ++ // increment by 1\n }\n\na ++ //Increment c by 1\n}\n//Return the entire message array. The function must have 32 outputs.\ncontext.set('old_OutputBit',OutputBit)\ncontext.set('old_index',index)\nreturn OutputBit;","outputs":32,"noerr":0,"x":430,"y":1080,"wires":[["a7418c7.bc4627"],["4c6ea1d2.5e291"],["6515a81.912fb58"],["16a867ae.df98a8"],["d108386.831c3c8"],["459872bc.fb9e1c"],["dba50d26.800b8"],["d8d63e8d.fd463"],["2a9d976b.72fb88"],["69024d7.0acfbb4"],["71776cbb.841a94"],["64145828.8242e8"],["6e141af7.803564"],["a626f958.a75628"],["7768657f.3e5d5c"],["7a8b8358.10640c"],["357f1756.30ec98"],["f664db15.40abe8"],["57d2f72a.3ae2b8"],["b58744f.425b1b8"],["7eea8c1c.4693a4"],["fdc0d110.e6663"],["a7e58249.f7585"],["bdb0dbcf.6d9a78"],["2bb5d464.954bec"],["b014f24c.7358e"],["3887b747.153168"],["dd2f4eab.9b707"],["f6b8f226.2a396"],["b76f1f3a.39fd6"],["d64c172f.6169c8"],["49807a51.fd0544"]]},{"id":"eaacd90c.0171e8","type":"file","z":"9bbffea9.f46ad","name":"History","filename":"/home/pi/logging_history.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1590,"y":1020,"wires":[[]]},{"id":"63cbdaeb.b29ee4","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"single","variable":"Allarmi_1","diff":true,"name":"","x":120,"y":280,"wires":[["7d9233b3.c596cc"]]},{"id":"16a867ae.df98a8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":640,"wires":[["eaacd90c.0171e8"]]},{"id":"d108386.831c3c8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":680,"wires":[["eaacd90c.0171e8"]]},{"id":"459872bc.fb9e1c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":720,"wires":[["eaacd90c.0171e8"]]},{"id":"dba50d26.800b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":760,"wires":[["eaacd90c.0171e8"]]},{"id":"d8d63e8d.fd463","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":800,"wires":[["eaacd90c.0171e8"]]},{"id":"2a9d976b.72fb88","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":840,"wires":[["eaacd90c.0171e8"]]},{"id":"69024d7.0acfbb4","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":880,"wires":[["eaacd90c.0171e8"]]},{"id":"71776cbb.841a94","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":920,"wires":[["eaacd90c.0171e8"]]},{"id":"64145828.8242e8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":960,"wires":[["eaacd90c.0171e8"]]},{"id":"6e141af7.803564","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1000,"wires":[["eaacd90c.0171e8"]]},{"id":"a626f958.a75628","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1040,"wires":[["eaacd90c.0171e8"]]},{"id":"7768657f.3e5d5c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1080,"wires":[["eaacd90c.0171e8"]]},{"id":"7a8b8358.10640c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1120,"wires":[["eaacd90c.0171e8"]]},{"id":"a7418c7.bc4627","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":520,"wires":[["eaacd90c.0171e8"]]},{"id":"4c6ea1d2.5e291","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":560,"wires":[["eaacd90c.0171e8"]]},{"id":"6515a81.912fb58","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":600,"wires":[["eaacd90c.0171e8"]]},{"id":"b58744f.425b1b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1300,"wires":[["eaacd90c.0171e8"]]},{"id":"7eea8c1c.4693a4","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1340,"wires":[["eaacd90c.0171e8"]]},{"id":"fdc0d110.e6663","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1380,"wires":[["eaacd90c.0171e8"]]},{"id":"a7e58249.f7585","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1420,"wires":[["eaacd90c.0171e8"]]},{"id":"bdb0dbcf.6d9a78","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1460,"wires":[["eaacd90c.0171e8"]]},{"id":"2bb5d464.954bec","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1500,"wires":[["eaacd90c.0171e8"]]},{"id":"b014f24c.7358e","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1540,"wires":[["eaacd90c.0171e8"]]},{"id":"3887b747.153168","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1580,"wires":[["eaacd90c.0171e8"]]},{"id":"dd2f4eab.9b707","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1620,"wires":[["eaacd90c.0171e8"]]},{"id":"f6b8f226.2a396","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1660,"wires":[["eaacd90c.0171e8"]]},{"id":"b76f1f3a.39fd6","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1700,"wires":[["eaacd90c.0171e8"]]},{"id":"d64c172f.6169c8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1740,"wires":[["eaacd90c.0171e8"]]},{"id":"49807a51.fd0544","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1780,"wires":[["eaacd90c.0171e8"]]},{"id":"357f1756.30ec98","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1180,"wires":[["eaacd90c.0171e8"]]},{"id":"f664db15.40abe8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1220,"wires":[["eaacd90c.0171e8"]]},{"id":"57d2f72a.3ae2b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1260,"wires":[["eaacd90c.0171e8"]]},{"id":"2c82e29a.6cbbae","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"single","variable":"Allarmi_2","diff":true,"name":"","x":120,"y":340,"wires":[["c8581f4.4b426e"]]},{"id":"7d9233b3.c596cc","type":"link out","z":"9bbffea9.f46ad","name":"Word_1","links":["abae3fb5.c7bcb","4b5d4a2b.e2e564"],"x":235,"y":280,"wires":[]},{"id":"c8581f4.4b426e","type":"link out","z":"9bbffea9.f46ad","name":"","links":["abae3fb5.c7bcb","4b5d4a2b.e2e564"],"x":235,"y":340,"wires":[]},{"id":"abae3fb5.c7bcb","type":"link in","z":"9bbffea9.f46ad","name":"Canged_alarm_value","links":["7d9233b3.c596cc","c8581f4.4b426e"],"x":355,"y":280,"wires":[["93bf5ef6.a059","92860ae4.b57278"]]},{"id":"ccd062b1.8c964","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"all","variable":"","diff":true,"name":"","x":180,"y":1080,"wires":[["6e1676a9.792368"]]},{"id":"bf97f077.348a1","type":"comment","z":"9bbffea9.f46ad","name":"Leggo i valori che cambiano e li scrivo in un file di archivio","info":"","x":270,"y":520,"wires":[]},{"id":"318b312.30a17ce","type":"comment","z":"9bbffea9.f46ad","name":"Aggiorno la visualizzazione","info":"","x":170,"y":200,"wires":[]},{"id":"4698ecb8.dd1894","type":"ui_group","z":"","name":"History_Alarm","tab":"a114e290.f4417","disp":true,"width":25,"collapse":false},{"id":"73e529c2.107728","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.160","port":"102","rack":"0","slot":"0","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"","vartable":[{"addr":"QB0","name":"Speed"},{"addr":"DB2,i0","name":"Power"},{"addr":"DB2,i2","name":"Temperature"},{"addr":"I0.0","name":"TriggerMessage"},{"addr":"Q1.0","name":"uscita"},{"addr":"DB2,I24","name":"Allarmi_1"},{"addr":"DB2,I26","name":"Allarmi_2"},{"addr":"DB2,I28","name":"Allarmi_3"},{"addr":"DB2,I30","name":"Allarmi_4"},{"addr":"DB2,I32","name":"Allarmi_5"},{"addr":"DB2,I34","name":"Allarmi_6"},{"addr":"DB2,I36","name":"Allarmi_7"},{"addr":"DB2,I38","name":"Allarmi_8"},{"addr":"DB2,I40","name":"Allarmi_9"},{"addr":"DB2,I42","name":"Allarmi_10"},{"addr":"DB2,I44","name":"Allarmi_11"},{"addr":"DB2,I46","name":"Allarmi_12"},{"addr":"DB2,I48","name":"Allarmi_13"},{"addr":"DB2,I50","name":"Allarmi_14"},{"addr":"DB2,I52","name":"Allarmi_15"},{"addr":"DB2,I54","name":"Allarmi_16"},{"addr":"DB2,I56","name":"Allarmi_17"},{"addr":"DB2,I58","name":"Allarmi_18"},{"addr":"DB2,I60","name":"Allarmi_19"},{"addr":"DB2,I62","name":"Allarmi_20"},{"addr":"DB2,I64","name":"Allarmi_21"}]},{"id":"a114e290.f4417","type":"ui_tab","z":"","name":"History","icon":"dashboard","disabled":false,"hidden":false}]
I get only change of state (from 0 to 1, and from 1 to 0) but 32 output and 32 rbe for me isn't good.