Flow:
[{"id":"b547cf96.056ee","type":"gate","z":"90af3ff8.12c38","name":"","controlTopic":"control","defaultState":"closed","openCmd":"true","closeCmd":"false","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":950,"y":4380,"wires":[["5c666fdc.2eb2e","861b9315.c94d8"]]},{"id":"c93c82dd.53a28","type":"inject","z":"90af3ff8.12c38","name":"Boolean 2 (true)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"true","payloadType":"bool","x":600,"y":4540,"wires":[["b547cf96.056ee"]]},{"id":"7495c612.68d4d8","type":"inject","z":"90af3ff8.12c38","name":"Boolean 2 (false)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"false","payloadType":"bool","x":600,"y":4580,"wires":[["b547cf96.056ee"]]},{"id":"d9ae4233.58c7a","type":"delay","z":"90af3ff8.12c38","name":"1 msg/5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":780,"y":4380,"wires":[["b547cf96.056ee"]]},{"id":"5c666fdc.2eb2e","type":"debug","z":"90af3ff8.12c38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":4300,"wires":[]},{"id":"5aefc719.74e888","type":"change","z":"90af3ff8.12c38","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":4640,"wires":[["b547cf96.056ee"]]},{"id":"ecd0df9.42dcc2","type":"s7 in","z":"90af3ff8.12c38","endpoint":"","mode":"single","variable":"","diff":true,"name":"","x":630,"y":4640,"wires":[["5aefc719.74e888"]]},{"id":"f7074c41.888a1","type":"inject","z":"90af3ff8.12c38","name":"Boolean 1 (true)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"true","payloadType":"bool","x":600,"y":4440,"wires":[[]]},{"id":"bb72b6c8.fcb848","type":"inject","z":"90af3ff8.12c38","name":"Boolean 1 (false)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"false","payloadType":"bool","x":600,"y":4480,"wires":[[]]},{"id":"c0480be8.ad28b8","type":"s7 in","z":"90af3ff8.12c38","endpoint":"","mode":"single","variable":"","diff":true,"name":"","x":630,"y":4380,"wires":[["d9ae4233.58c7a"]]},{"id":"861b9315.c94d8","type":"function","z":"90af3ff8.12c38","name":"Add time","func":"var date;\ndate = new Date(); \ndate = (date.getDate() + '-' + (date.getMonth()+1) + '-' + date.getFullYear() + ' om ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds());\nmsg.payload.date = date; \nreturn msg;\n\n// Your other function needs to be added. ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1120,"y":4380,"wires":[["2e300b1d.62e874"]]},{"id":"2e300b1d.62e874","type":"csv","z":"90af3ff8.12c38","name":"Create CSV","sep":";","hdrin":false,"hdrout":"none","multi":"one","ret":"\\r\\n","temp":"Set it up like you want.","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":1310,"y":4380,"wires":[[]]}]
This still needs adjustments, such as the csv node, your function and PLC nodes.
Arne