i'm very very very luck about your borin saturaday night !!!!
joke apart, thanks for your help!
it's a very usefull sugestion, it woks at 90%
but i got the way, and i become it working at 100%
i have some question when you have time....
perfectly understand the meening, very celar explanation!
the outpunt commadn should be:
msg.topic = cmnd/light_kitchen/event
and
msg.payload = MCPINT_D6=0
so i modify the firts instruction like:
// make the topic part after the equal sign of the first part
msg.topic = "cmnd/" + parts[0].split("=")[1] + "/event";
that's make your code working form 90% to 100%
but joke apart, i apreciate very much your help, you understand 100% correctly, and give me a way to learn a lot!
now...just to learn more, i complicate a bit
with this example as description:
"description": "topic=tasmota_mcp\nMCPINT=D0",
i want an output like:
topic => cmnd/tasmota_mcp/sensor29
payload => 0,1
i modify your code, (function2) and i succeed on it. no question here.
now again a modification, want to modify a bit again.
with this example as description:
"description": "topic=tasmota_mcp\npayload=MCPINT=D0",
i want an output like:
topic => cmnd/tasmota_mcp/sensor29
payload => 0,1
i modify again your code (function3) but here i miss one command:
of course i can use :
// grab the MCP part of the payload line
var p = parts[1].split("D")[2];
instead of
// grab the MCP part of the payload line
var p = parts[1].split("=")[2];
but is it possible use:
// grab the MCP part of the payload line
var p = parts[1].split("=")[2];
and then a function that delete the carachter "D" to have only the number that is following the letter "D" ?
last question, i added at function3 outupt a debug node, because i want for example to see what there is inside var p
i do not suceed on monitoring var p
in debug, what i should do?
here your flow modificated by me.
[{"id":"936b5343.1e99d","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"82b683b2.f2eaf","type":"inject","z":"936b5343.1e99d","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=tasmota_mcp\\npayload=MCPINT_D0=\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce1\",\"nvalue\":1,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":80,"wires":[["d4e444fc.b3f35"]]},{"id":"4e914d81.f30d1c","type":"function","z":"936b5343.1e99d","name":"function2","func":"\n// split the description into two parts\nvar parts = msg.payload.description.split('\\n');\n\n\n// make the topic part after the equal sign of the first part\nvar topic_middle = parts[0].split(\"=\")[1];\n\n//build message topic adding cmnd/<topic>/sensor29\nmsg.topic = \"cmnd/\" + topic_middle + \"/sensor29\"\n\n// grab the MCP part of the payload line\nvar p = parts[1].split(\"D\")[1];\n\n// rebuild the payload and append the nvalue\nmsg.payload = p + \",\" + msg.payload.nvalue;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":220,"wires":[["32fb53f1.1e7ef4","1755afce.ad7c9"]]},{"id":"32fb53f1.1e7ef4","type":"debug","z":"936b5343.1e99d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":160,"wires":[]},{"id":"a46b1be5.29c708","type":"inject","z":"936b5343.1e99d","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=light_bathroom\\npayload=MCPINT_D3=\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce2\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":120,"wires":[["d4e444fc.b3f35"]]},{"id":"47e1a706.c33258","type":"inject","z":"936b5343.1e99d","name":"","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=light_kitchen\\npayload=MCPINT_D6=\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce3\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":160,"wires":[["d4e444fc.b3f35"]]},{"id":"1755afce.ad7c9","type":"debug","z":"936b5343.1e99d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":510,"y":260,"wires":[]},{"id":"7a77a3b.55d7ddc","type":"inject","z":"936b5343.1e99d","name":"MCPINT=D8","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=light_kitchen\\nMCPINT=D8\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce3\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":340,"wires":[["4e914d81.f30d1c"]]},{"id":"d4e444fc.b3f35","type":"function","z":"936b5343.1e99d","name":"function1","func":"\n// split the description into two parts\nvar parts = msg.payload.description.split('\\n');\n\n// make the topic part after the equal sign of the first part\nmsg.topic = \"cmnd/\" + parts[0].split(\"=\")[1] + \"/event\";\n\n// grab the MCP part of the payload line\nvar p = parts[1].split(\"=\")[1];\n\n// rebuild the payload and append the nvalue\nmsg.payload = p + \"=\" + msg.payload.nvalue;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":120,"wires":[["32fb53f1.1e7ef4","1755afce.ad7c9"]]},{"id":"8daa3ea6.ea5fc8","type":"inject","z":"936b5343.1e99d","name":"MCPINT=D0","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=tasmota_mcp\\nMCPINT=D0\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce1\",\"nvalue\":1,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":280,"wires":[["4e914d81.f30d1c"]]},{"id":"bfab8271.beee8","type":"inject","z":"936b5343.1e99d","name":"payload=MCPINT=D0","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=tasmota_mcp\\npayload=MCPINT=D0\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce1\",\"nvalue\":1,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":420,"wires":[["85ca653c.32746"]]},{"id":"801aa26f.b6cb58","type":"inject","z":"936b5343.1e99d","name":"payload=MCPINT=D8","topic":"","payload":"{\"Battery\":255,\"RSSI\":12,\"description\":\"topic=light_kitchen\\npayload=MCPINT=D8\",\"dtype\":\"Light/Switch\",\"hwid\":\"6\",\"id\":\"000140FE\",\"idx\":174,\"name\":\"mcp_luce3\",\"nvalue\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":480,"wires":[["85ca653c.32746"]]},{"id":"85ca653c.32746","type":"function","z":"936b5343.1e99d","name":"function3","func":"\n// split the description into two parts\nvar parts = msg.payload.description.split('\\n');\n\n\n// make the topic part after the equal sign of the first part\nvar topic_middle = parts[0].split(\"=\")[1];\n\n//build message topic adding cmnd/<topic>/sensor29\nmsg.topic = \"cmnd/\" + topic_middle + \"/sensor29\"\n\n// grab the MCP part of the payload line\nvar p = parts[1].split(\"=\")[2];\n\n// rebuild the payload and append the nvalue\nmsg.payload = p + \",\" + msg.payload.nvalue;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":360,"wires":[["32fb53f1.1e7ef4","1755afce.ad7c9","9072d9ed.d64a2"]]},{"id":"9072d9ed.d64a2","type":"debug","z":"936b5343.1e99d","name":"var p","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"var p","targetType":"jsonata","x":500,"y":420,"wires":[]},{"id":"181806e1.fc7ac9","type":"comment","z":"936b5343.1e99d","name":"","info":" with this function i have as output example:\nmsg.topic = `cmnd/light_kitchen/event`\nand\nmsg.payload = `MCPINT_D6=0`\n\n","x":300,"y":60,"wires":[]},{"id":"3bab5363.81024c","type":"comment","z":"936b5343.1e99d","name":"","info":" with this function i have as output example:\nmsg.topic = `cmnd/light_kitchen/sensor29`\nand\nmsg.payload = `6,0`\n\n\n\nfor description example please see the injection nodes that i modify","x":300,"y":180,"wires":[]},{"id":"fb2536fd.f5271","type":"comment","z":"936b5343.1e99d","name":"","info":" with this function i have as output example:\nmsg.topic = `cmnd/light_kitchen/sensor29`\nand\nmsg.payload = `6,0`\n\n\n\nfor description example please see the injection nodes that i modify adding payload=.....","x":320,"y":320,"wires":[]}]