How to add a topic to the msg payload

Hi,
i want to change a incoming message (msg.payload) into a msg. payload AND a Topic.

I´m a newby ... so please give me an easy solution

Thanks in advance

This is an example for my actually node situation:

[{"id":"967e8805.289488","type":"inject","z":"d72bfd54.23bb3","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":220,"wires":[["a00f81b4.73cfe"]]},{"id":"a00f81b4.73cfe","type":"change","z":"d72bfd54.23bb3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"That is my message","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":220,"wires":[["b1f52ebe.dd367"]]},{"id":"5e389e1e.4d3","type":"comment","z":"d72bfd54.23bb3","name":"That´s an example for my Dashbutton with msg.payload only","info":"","x":300,"y":180,"wires":[]},{"id":"b1f52ebe.dd367","type":"debug","z":"d72bfd54.23bb3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":220,"wires":[]}]

You need to format your code properly.
edit your post and put three backticks ```
on a line before your code and again on a line after your code

```
code
```

1 Like

So you want to add msg.topic to the message object. You can do this is numerous different ways

In a function node:

msg.topic = "what ever you want"
return msg;

IN a change node:
Set msg.topic
to what ever you want

You can configure the debug node to "output" "complete message object" which will display the whole message object to check it has done what you want

6 Likes

ahhh... that´s easy. Thank you guys