hi .. the topic assignment looks fine .. the problem is that you are trying to return msg1
which doesnt exist. Rename it to msg
Test flow
[{"id":"af8adf79fb8227e0","type":"inject","z":"4895ea10b4ee9ead","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":270,"y":900,"wires":[["cfb9a2f47cfc443a"]]},{"id":"cfb9a2f47cfc443a","type":"function","z":"4895ea10b4ee9ead","name":"","func":"if (msg.payload == \"on\") {\n msg.topic = \"s7.1.DBs.DB1.Lüfter_an\";\n return [msg, null];\n}\nif (msg.payload == \"off\") {\n msg.topic = \"s7.1.DBs.DB1.Lüfter_aus\";\n return [null, msg]\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":940,"wires":[["17379cbce11f7c46"],["629eebe8d418a008"]]},{"id":"8a2507e4f47d623a","type":"inject","z":"4895ea10b4ee9ead","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":270,"y":1000,"wires":[["cfb9a2f47cfc443a"]]},{"id":"17379cbce11f7c46","type":"debug","z":"4895ea10b4ee9ead","name":"on","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":900,"wires":[]},{"id":"629eebe8d418a008","type":"debug","z":"4895ea10b4ee9ead","name":"off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":980,"wires":[]}]