From a mqtt message extract and modify two parameters to create a new one

hi, i have a mqtt messge object that is like this:

switch light off
{"Battery":255,"RSSI":12,"description":"topic=tasmota_mcp\npayload=MCPINT_D0=","dtype":"Light/Switch","hwid":"6","id":"000140FE","idx":174,"name":"mcp_luce1","nvalue":0,"stype":"Switch","svalue1":"0","switchType":"On/Off","unit":1}

or switch light on

{"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}

please note:
description:
topic=tasmota_mcp\npayload=MCPINT_D0=
and nvalue
1 or 0

from this i need to create a mqtt message like this

message topic =>> cmnd/tasmota_mcp/event
payload=>> MCPINT_D0=1 or 0 this value 1 or 0 is taken from nvalue

so the out mqtt message should be:
cmnd/tasmota_mcp/event MCPINT_D0=1
or
cmnd/tasmota_mcp/event MCPINT_D0=0

like @Andrei explain in another post i try to make the flow, but i not succeed in two things:

  1. how to split the payload, where first part is inside description field and another part is in nvalue field

  2. how to divive the description fild and address one part in payload and one part in topic

this is my flow
[{"id":"414b2538.26bf1c","type":"inject","z":"250fdc05.cea3b4","name":"luce OFF","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\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":100,"wires":[["27269e92.bcea52"]]}]

thanks for help me

ps. of course the description field is free to change if there are more confortable and clever way to rapresent topic and payload

Your flow contains only a single insert node

sorry may not export in a proper way:

[{"id":"250fdc05.cea3b4","type":"tab","label":"luci_tasmota_mcp","disabled":false,"info":""},{"id":"414b2538.26bf1c","type":"inject","z":"250fdc05.cea3b4","name":"luce OFF","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\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":100,"wires":[["27269e92.bcea52"]]},{"id":"1c2650ef.d27fc7","type":"inject","z":"250fdc05.cea3b4","name":"luce ON","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":190,"y":160,"wires":[["27269e92.bcea52"]]},{"id":"27269e92.bcea52","type":"switch","z":"250fdc05.cea3b4","name":"","property":"payload.description","propertyType":"msg","rules":[{"t":"cont","v":"MCPINT","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":220,"wires":[["465a33be.278204","7cfc743f.45f66c"],[]]},{"id":"465a33be.278204","type":"debug","z":"250fdc05.cea3b4","name":"switch MCP","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":120,"wires":[]},{"id":"bbbb7cce.636cd8","type":"mqtt in","z":"250fdc05.cea3b4","name":"","topic":"domoticz/out","qos":"2","datatype":"json","broker":"f0a64cae.6413e","x":230,"y":40,"wires":[[]]},{"id":"15a19111.be99b7","type":"mqtt out","z":"250fdc05.cea3b4","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":750,"y":220,"wires":[]},{"id":"7cfc743f.45f66c","type":"change","z":"250fdc05.cea3b4","name":"JSONata","rules":[{"t":"set","p":"part1","pt":"msg","to":"payload.description","tot":"jsonata"},{"t":"set","p":"part2","pt":"msg","to":"$replace(part1,\"\\n\", \"/event\")","tot":"jsonata"},{"t":"set","p":"part3","pt":"msg","to":"$replace(part2,\"topic=\", \"cmnd/\")","tot":"jsonata"},{"t":"set","p":"topic_first","pt":"msg","to":"$split(part3, \"payload=\")\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"topic_first","tot":"jsonata"},{"t":"set","p":"payload_end","pt":"msg","to":"payload.nvalue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":220,"wires":[["435d34f4.55b4e4","1f1b20a0.520687","ec882e8.23642d"]]},{"id":"435d34f4.55b4e4","type":"debug","z":"250fdc05.cea3b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":630,"y":340,"wires":[]},{"id":"1f1b20a0.520687","type":"debug","z":"250fdc05.cea3b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":620,"y":420,"wires":[]},{"id":"ec882e8.23642d","type":"split","z":"250fdc05.cea3b4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":320,"wires":[["b39e77ba.1b797","d1c27cc4.e97dc8"]]},{"id":"b39e77ba.1b797","type":"change","z":"250fdc05.cea3b4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"payload_end","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":380,"wires":[["d7c28836.be152","d79a960b.204508","5c17d0cf.94dbc8"]]},{"id":"d1c27cc4.e97dc8","type":"debug","z":"250fdc05.cea3b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":380,"y":540,"wires":[]},{"id":"d7c28836.be152","type":"debug","z":"250fdc05.cea3b4","name":"Connect to the MQTT out node","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":630,"y":500,"wires":[]},{"id":"d79a960b.204508","type":"debug","z":"250fdc05.cea3b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":590,"y":540,"wires":[]},{"id":"5c17d0cf.94dbc8","type":"debug","z":"250fdc05.cea3b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":580,"wires":[]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

i try to create another flow...
now i succeed on having topic like: cmnd/tasmota_mcp/event

and payload like: MCPINT_D0=0

but there comes from two different line and when i combine to connect mqtt out i receive an error.
this is the log:

20/3/2020, 21:55:19[node: 2095d260.787b0e](http://192.168.0.105:1880/#)

cmnd/tasmota_mcp/event : msg.topic : string[22]

"cmnd/tasmota_mcp/event"

20/3/2020, 21:55:19[node: b47806c4.7b80f8](http://192.168.0.105:1880/#)msg.payload : string[11]

"MCPINT_D0=0"

20/3/2020, 21:55:19[node: 7b401d4f.46369c](http://192.168.0.105:1880/#)msg : string[23]

"Invalid topic specified"

this is the flow:

[{"id":"2019e3ca.87d34c","type":"tab","label":"luci_tasmota_mcp","disabled":false,"info":""},{"id":"3c739ac.2ddd366","type":"inject","z":"2019e3ca.87d34c","name":"luce OFF","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\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["142125ce.f1cc3a"]]},{"id":"6e8e29a.faa99d8","type":"inject","z":"2019e3ca.87d34c","name":"luce ON","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":110,"y":180,"wires":[["142125ce.f1cc3a"]]},{"id":"142125ce.f1cc3a","type":"switch","z":"2019e3ca.87d34c","name":"","property":"payload.description","propertyType":"msg","rules":[{"t":"cont","v":"MCPINT","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":140,"wires":[["7b3326f8.5483a8","3fc88044.4f7a78"],[]]},{"id":"7b3326f8.5483a8","type":"debug","z":"2019e3ca.87d34c","name":"switch MCP","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":60,"wires":[]},{"id":"7a721d7b.0371b4","type":"mqtt in","z":"2019e3ca.87d34c","name":"","topic":"domoticz/out","qos":"2","datatype":"json","broker":"f0a64cae.6413e","x":110,"y":60,"wires":[[]]},{"id":"7b401d4f.46369c","type":"mqtt out","z":"2019e3ca.87d34c","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":610,"y":320,"wires":[]},{"id":"3fc88044.4f7a78","type":"change","z":"2019e3ca.87d34c","name":"JSONata","rules":[{"t":"set","p":"payload_end","pt":"msg","to":"payload.nvalue","tot":"jsonata"},{"t":"set","p":"part1","pt":"msg","to":"payload.description","tot":"jsonata"},{"t":"set","p":"part2","pt":"msg","to":"$replace(part1,\"\\n\", \"/event\")","tot":"jsonata"},{"t":"set","p":"part3","pt":"msg","to":"$replace(part2,\"topic=\", \"cmnd/\")","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"part3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":140,"wires":[["32cceaba.1acb1e"]]},{"id":"32cceaba.1acb1e","type":"split","z":"2019e3ca.87d34c","name":"","splt":"payload=","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"exit","x":650,"y":140,"wires":[["14f7deac.c757b1"]]},{"id":"bf959fb9.d60908","type":"change","z":"2019e3ca.87d34c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":280,"wires":[["2095d260.787b0e","7b401d4f.46369c"]]},{"id":"14f7deac.c757b1","type":"switch","z":"2019e3ca.87d34c","name":"","property":"payload","propertyType":"jsonata","rules":[{"t":"cont","v":"cmnd","vt":"str"},{"t":"cont","v":"MCPINT","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":110,"y":320,"wires":[["bf959fb9.d60908"],["5e30d7ea.97b4d8"]]},{"id":"5e30d7ea.97b4d8","type":"change","z":"2019e3ca.87d34c","name":"","rules":[{"t":"set","p":"uno","pt":"msg","to":"msg.payload","tot":"jsonata"},{"t":"set","p":"due","pt":"msg","to":"msg.payload_end","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":380,"wires":[["13cbba17.7bd4be"]]},{"id":"13cbba17.7bd4be","type":"template","z":"2019e3ca.87d34c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{uno}}}{{due}}","output":"str","x":460,"y":380,"wires":[["b47806c4.7b80f8","7b401d4f.46369c"]]},{"id":"2095d260.787b0e","type":"debug","z":"2019e3ca.87d34c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":560,"y":240,"wires":[]},{"id":"b47806c4.7b80f8","type":"debug","z":"2019e3ca.87d34c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":420,"wires":[]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Change your debug nodes to display 'Complete msg object' and see what shows up.

20/3/2020, 23:10:06[node: e4577416.203558](http://192.168.0.105:1880/#)

cmnd/tasmota_mcp/event : msg : Object

{ topic: "cmnd/tasmota_mcp/event", payload_end: 1, part1: "topic=tasmota_mcp↵payload=MCPI…", part2: "topic=tasmota_mcp/eventpayload…", part3: "cmnd/tasmota_mcp/eventpayload=…" … }

20/3/2020, 23:10:06[node: e4577416.203558](http://192.168.0.105:1880/#)MCPINT_D0= : msg : Object

{ topic: "MCPINT_D0=", payload_end: 1, part1: "topic=tasmota_mcp↵payload=MCPI…", part2: "topic=tasmota_mcp/eventpayload…", part3: "cmnd/tasmota_mcp/eventpayload=…" … }

i do not undertand why if i use the complete msg object i have this output
but if i look at msg.topic and msg.payload
it seams that i have the output that i need

i change also a bit the flow but nothing change....i'm getting frustrated :frowning:

[{"id":"2019e3ca.87d34c","type":"tab","label":"luci_tasmota_mcp","disabled":false,"info":""},{"id":"3c739ac.2ddd366","type":"inject","z":"2019e3ca.87d34c","name":"luce OFF","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\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["142125ce.f1cc3a"]]},{"id":"6e8e29a.faa99d8","type":"inject","z":"2019e3ca.87d34c","name":"luce ON","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":110,"y":180,"wires":[["142125ce.f1cc3a"]]},{"id":"142125ce.f1cc3a","type":"switch","z":"2019e3ca.87d34c","name":"","property":"payload.description","propertyType":"msg","rules":[{"t":"cont","v":"MCPINT","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":140,"wires":[["7b3326f8.5483a8","3fc88044.4f7a78"],[]]},{"id":"7b3326f8.5483a8","type":"debug","z":"2019e3ca.87d34c","name":"switch MCP","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":60,"wires":[]},{"id":"7a721d7b.0371b4","type":"mqtt in","z":"2019e3ca.87d34c","name":"","topic":"domoticz/out","qos":"2","datatype":"json","broker":"f0a64cae.6413e","x":110,"y":60,"wires":[[]]},{"id":"7b401d4f.46369c","type":"mqtt out","z":"2019e3ca.87d34c","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":710,"y":300,"wires":[]},{"id":"3fc88044.4f7a78","type":"change","z":"2019e3ca.87d34c","name":"JSONata","rules":[{"t":"set","p":"payload_end","pt":"msg","to":"payload.nvalue","tot":"jsonata"},{"t":"set","p":"part1","pt":"msg","to":"payload.description","tot":"jsonata"},{"t":"set","p":"part2","pt":"msg","to":"$replace(part1,\"\\n\", \"/event\")","tot":"jsonata"},{"t":"set","p":"part3","pt":"msg","to":"$replace(part2,\"topic=\", \"cmnd/\")","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"part3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":140,"wires":[["32cceaba.1acb1e"]]},{"id":"32cceaba.1acb1e","type":"split","z":"2019e3ca.87d34c","name":"","splt":"payload=","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"exit","x":650,"y":140,"wires":[["14f7deac.c757b1"]]},{"id":"14f7deac.c757b1","type":"switch","z":"2019e3ca.87d34c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"cmnd","vt":"str"},{"t":"cont","v":"MCPINT","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":110,"y":320,"wires":[["11b99d73.257573","e1b382bb.0e1558"],["5e30d7ea.97b4d8","977f056c.4b2768"]]},{"id":"5e30d7ea.97b4d8","type":"change","z":"2019e3ca.87d34c","name":"","rules":[{"t":"set","p":"uno","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"due","pt":"msg","to":"payload_end","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":380,"wires":[["13cbba17.7bd4be","d05c91a8.4818a8","f0ed70ca.f4748"]]},{"id":"13cbba17.7bd4be","type":"template","z":"2019e3ca.87d34c","name":"","field":"union","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{uno}}}{{due}}","output":"str","x":420,"y":380,"wires":[["b47806c4.7b80f8","e1b382bb.0e1558"]]},{"id":"2095d260.787b0e","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":560,"y":240,"wires":[]},{"id":"b47806c4.7b80f8","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"union","targetType":"msg","x":490,"y":460,"wires":[]},{"id":"e1b382bb.0e1558","type":"change","z":"2019e3ca.87d34c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"union","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":300,"wires":[["825ef097.f90f2","e4577416.203558","2095d260.787b0e"]]},{"id":"825ef097.f90f2","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":660,"y":380,"wires":[]},{"id":"e4577416.203558","type":"debug","z":"2019e3ca.87d34c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":460,"wires":[]},{"id":"977f056c.4b2768","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":200,"y":540,"wires":[]},{"id":"11b99d73.257573","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":270,"y":280,"wires":[]},{"id":"d05c91a8.4818a8","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"uno","targetType":"msg","x":270,"y":460,"wires":[]},{"id":"f0ed70ca.f4748","type":"debug","z":"2019e3ca.87d34c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"due","targetType":"msg","x":270,"y":500,"wires":[]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Well you have changed things in your current flow and it is NOT causing the "Invalid topic specified" error message anymore

Yes, i try to change to solve the issue... But now i do not understand why i have this message when i use the debug with total message.
If i look at msg.topic and msg.payload they seams to be ok.
Why it generate a total mqtt message so wrong?!?
Getting me crazy...
I also do not know if there is an easy way to do this.. Maybe i complicated the flow

Also the description field can be filled using something different that can make easy the flow.
I'm opening to every kind of suggestions.
description fielled in the way that i showed is just my proposal to get the parameter of payload and topic that i need but i can change if it make easy the flow

When you use a debug node, it defaults to displaying a portion of the entire msg, the payload part.
When you use a debug node and tell it to display the 'Complete msg object' it is showing you the entire msg instead of just a part of it.

Ok, but why the message generate is not the sum of topic + payload?
If i debug only msg.topic and msg.paylod i have the correct value. Or i'm wrong?
Thanks

from the documentation:


Message

Messages are what pass between the nodes in a flow. They are plain JavaScript objects that can have any set of properties. They are often referred to as msg within the editor.

By convention, they have a payload property containing the most useful information.


'topic' is another property. You can add properties to messages. If you use a change node and set 'msg.bannana' to a text string of 'apple' it will now be part of the msg for the rest of the flow (unless it is removed from the msg.you will see that)

I hope that clears things up. You should spend time reading about javaScript objects to get a handle on them.

thanks for explanation.
this is pretty much clear,but i'm still lost on where my messages didn't get the correct properties
and i do not understand if the way that i'm using to manipulate them is correct or not
thanks

Let's go back to the beginning. You want to check the incoming msg for two things
1 - if msg.payload.desctiption contains MCPINT_D0=
and you are already doing that with your switch node. So only msgs that meet that condition get passed on. Next you want to chedk if msg.payload.nvalue is 1 or 0 - so use another switch node and test that out.

now you will have two branched flows - one for the 1 condition and one for the 0 condition. so, in each flow, build your response msg that you want to send and at the end connect both flows to the MQTT-out node and you should be done.

no, i filter only with: MCPINT
becuase the mqtt output that i can build can have for example:
cmnd/tasmota_mcp/event MCPINT_D0=0
cmnd/tasmota_mcp/event MCPINT_D0=1
cmnd/tasmota_mcp/event MCPINT_D3=0
cmnd/tasmota_mcp/event MCPINT_D3=1
cmnd/light_kitchen/event MCPINT_D4=1
cmnd/light_kitchen/event MCPINT_D4=0
cmnd/bathroom_2/event MCPINT_D6=0
cmnd/bathroom_2/event MCPINT_D6=1
and so on....
all words written in bold can change

for example we can consider:
cmnd/tasmota_mcp/event MCPINT_D0=1 (number after = can be 1 or 0 and this come from nvalue)
as i wrote, words in bold can be different from a description field to another.
these bold parameters are written inside description field and referring to the example the descriptio fileld will be:
topic=tasmota_mcp
payload=MCPINT_D0=
or in a json format: topic=tasmota_mcp\npayload=MCPINT_D0=
the number after = will taken from nvalue (that could be 1=on 0=off)

ok i have to record this parameter and save, because it will be placed after the = of MCPINT_D0=

no, here come my main difficulties, i have to divide what i have inside description filed that is:
topic=tasmota_mcp\npayload=MCPINT_D0=
and i have to divide it to have a mqtt message that should be:
cmnd/tasmota_mcp/event MCPINT_D0=1
note the space between event and MCPINT
cmnd/tasmota_mcp/event => topic
MCPINT_D0=1 => payload
1 after the = is coming from nvalue

So if I understand you, you will get a msg.payload like

{
  "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
}

and the end result is to sent a response to the MQTT-out node with (in this case)
msg.topic = cmnd/tasmota_mcp/event
and
msg.payload = MCPINT_D0=1

if the description was

{
  "Battery" : 255,
  "RSSI" : 12,
  "description" : "topic=light_kitchen\npayload=MCPINT_D4=",
  "dtype" : "Light/Switch",
  "hwid" : "6",
  "id" : "000140FE",
  "idx" : 174,
  "name" : "mcp_luce1",
  "nvalue" : 0,
  "stype" : "Switch",
  "svalue1" : "0",
  "switchType" : "On/Off",
  "unit" : 1
}

you would want
msg.topic = cmnd/light_kitchen/event
msg.payload = MCPINT_D4=0

Correct?

It would probably be esaiest to do this in a function node.

yes, you understand 100% correctly
sorry if i made confusion on explain, but you understand correctly!
please take into account that if you would like to change the sturcture of description field just to make the function that you propose more simple, i can change the description field writing the parameters needed in the way that you prefer

if using function become more simple, for example we can use inside description filed a json notation, example:
{ "topic" : " light_kitchen", "payload" : "MCPINT_D4=" }

that will give as output:
msg.topic = cmnd/light_kitchen/event
msg.payload = MCPINT_D4=0 (where the 0 after the = coming always from nvalue in the example below was "nvalue" : 0

so inside description filed we can write the data in the way that is more easy to manipulate

So do you control the topic and payload being sent to NR? If s, please put a debug node (set to display complete msg object) and run it.

In the debug sidebar, hover your mouse in the debug till you see this icon:
Screen Shot 2020-03-21 at 4.13.04 AM
clicking on it will copy the entire debug. Paste that here using the code </> button.

this is the dubg set as complete msg object that is put at the end of the flow.
i receive:
{"topic":"cmnd/tasmota_mcp/event","payload_end":1,"part1":"topic=tasmota_mcp\npayload=MCPINT_D0=","part2":"topic=tasmota_mcp/eventpayload=MCPINT_D0=","part3":"cmnd/tasmota_mcp/eventpayload=MCPINT_D0=","parts":{"id":"94d4911b.ae57a","type":"string","ch":"payload=","index":0,"count":2},"_msgid":"93636837.391f28"}
and
{"topic":"MCPINT_D0=","payload_end":1,"part1":"topic=tasmota_mcp\npayload=MCPINT_D0=","part2":"topic=tasmota_mcp/eventpayload=MCPINT_D0=","part3":"cmnd/tasmota_mcp/eventpayload=MCPINT_D0=","parts":{"id":"94d4911b.ae57a","type":"string","ch":"payload=","index":1,"count":2},"_msgid":"1083342f.591abc","uno":"MCPINT_D0=","due":1,"payload":"MCPINT_D0=1"}

this is one example of json injected, where, if you would like to implement a function node, i can write in a different way the description field to pass to NodeRed value in a different way that can make easy implement the function
{"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}

this is the flow with attached also the debug used and the injection flow on and off.
i think that i make too much complicate the flow tring to manipulate the description filed...maybe i have to change the approach

[{"id":"e8abadf6.0af268","type":"tab","label":"luci_tasmota_mcp","disabled":false,"info":""},{"id":"1b72beb2.950b01","type":"inject","z":"e8abadf6.0af268","name":"luce OFF","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\":0,\"stype\":\"Switch\",\"svalue1\":\"0\",\"switchType\":\"On/Off\",\"unit\":1}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["7baccf6f.34fed"]]},{"id":"3001c820.f32988","type":"inject","z":"e8abadf6.0af268","name":"luce ON","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":110,"y":180,"wires":[["7baccf6f.34fed"]]},{"id":"7baccf6f.34fed","type":"switch","z":"e8abadf6.0af268","name":"","property":"payload.description","propertyType":"msg","rules":[{"t":"cont","v":"MCPINT","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":140,"wires":[["3da211e6.294ff6","29bb36a7.aba402"],[]]},{"id":"3da211e6.294ff6","type":"debug","z":"e8abadf6.0af268","name":"switch MCP","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":60,"wires":[]},{"id":"88458d05.3bb168","type":"mqtt in","z":"e8abadf6.0af268","name":"","topic":"domoticz/out","qos":"2","datatype":"json","broker":"f0a64cae.6413e","x":110,"y":60,"wires":[[]]},{"id":"354a9518.d5a8ba","type":"mqtt out","z":"e8abadf6.0af268","name":"","topic":"","qos":"","retain":"","broker":"f0a64cae.6413e","x":710,"y":300,"wires":[]},{"id":"29bb36a7.aba402","type":"change","z":"e8abadf6.0af268","name":"JSONata","rules":[{"t":"set","p":"payload_end","pt":"msg","to":"payload.nvalue","tot":"jsonata"},{"t":"set","p":"part1","pt":"msg","to":"payload.description","tot":"jsonata"},{"t":"set","p":"part2","pt":"msg","to":"$replace(part1,\"\\n\", \"/event\")","tot":"jsonata"},{"t":"set","p":"part3","pt":"msg","to":"$replace(part2,\"topic=\", \"cmnd/\")","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"part3","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":140,"wires":[["6ea782cb.746b34"]]},{"id":"6ea782cb.746b34","type":"split","z":"e8abadf6.0af268","name":"","splt":"payload=","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"exit","x":650,"y":140,"wires":[["cfc59d08.02d298"]]},{"id":"cfc59d08.02d298","type":"switch","z":"e8abadf6.0af268","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"cmnd","vt":"str"},{"t":"cont","v":"MCPINT","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":110,"y":320,"wires":[["499bd46e.8e3a44","3e4b7dfc.22e642"],["d89ddbfc.35c1e8","b7699cec.cdf1d"]]},{"id":"d89ddbfc.35c1e8","type":"change","z":"e8abadf6.0af268","name":"","rules":[{"t":"set","p":"uno","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"due","pt":"msg","to":"payload_end","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":380,"wires":[["133b3620.a1ded2","cf87192.6628e68","7c88c9e1.69df08"]]},{"id":"133b3620.a1ded2","type":"template","z":"e8abadf6.0af268","name":"","field":"union","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{uno}}}{{due}}","output":"str","x":420,"y":380,"wires":[["12320b06.6152bd","3e4b7dfc.22e642"]]},{"id":"3608b2c4.c9ec26","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","x":560,"y":240,"wires":[]},{"id":"12320b06.6152bd","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"union","targetType":"msg","x":490,"y":460,"wires":[]},{"id":"3e4b7dfc.22e642","type":"change","z":"e8abadf6.0af268","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"},{"t":"move","p":"union","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":300,"wires":[["a8394405.0d81e8","5ece7020.f7f9c","3608b2c4.c9ec26"]]},{"id":"a8394405.0d81e8","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":660,"y":380,"wires":[]},{"id":"5ece7020.f7f9c","type":"debug","z":"e8abadf6.0af268","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":460,"wires":[]},{"id":"b7699cec.cdf1d","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":200,"y":540,"wires":[]},{"id":"499bd46e.8e3a44","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":270,"y":280,"wires":[]},{"id":"cf87192.6628e68","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"uno","targetType":"msg","x":270,"y":460,"wires":[]},{"id":"7c88c9e1.69df08","type":"debug","z":"e8abadf6.0af268","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"due","targetType":"msg","x":270,"y":500,"wires":[]},{"id":"f0a64cae.6413e","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.105","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

What/how are you creating the topic of the incoming message?
Can you control how the topic is created?

sorry, not sure that i understand well you question.
the description field is coming from devices on domoticz.
when i press the device on domoticz, it send out using mqtt a json. inside this json there is also the description field.
the description field can be manage by me inside domoticz writing what i want.
so, my idea, was to put inside this field some informations usefull to build the output command with nodered that should manipulate description field received to buld the output command to tasmota device in the way that explained:

for example:
cmnd/ tasmota_mcp /event MCPINT_ D0 = 0
cmnd/ tasmota_mcp /event MCPINT_ D0 = 1
cmnd/ tasmota_mcp /event MCPINT_ D3 = 0
cmnd/ tasmota_mcp /event MCPINT_ D3 = 1
cmnd/ light_kitchen /event MCPINT_ D4 = 1
cmnd/ light_kitchen /event MCPINT_ D4 = 0
cmnd/ bathroom_2 /event MCPINT_ D6 = 0
cmnd/ bathroom_2 /event MCPINT_ D6 = 1
and so on....
all words written in bold can change

starting from a domoticz json received by nodered, i should use nodered to elaborate the description field received and create the example of commands above

i don't know if i answered at your question.