# Adding a topic to payload?

**URL:** <https://discourse.nodered.org/t/adding-a-topic-to-payload/6691>\
**Category:** General\
**Created:** [11 January 2019 10:42 UTC](https://discourse.nodered.org/t/adding-a-topic-to-payload/6691 "2019-01-11T10:42:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)\
**Post date:** [11 January 2019 10:42 UTC](https://discourse.nodered.org/t/adding-a-topic-to-payload/6691/1 "2019-01-11T10:42:16Z")

</div>

Im trying to controll the Gate node with a normal payload but to actualy controll the gate its self, u need to add the Topic : ''control' to actually control the Gate instead of the payload to just go through the Gate

but I dont want to use the inject node, just the payload from a button.  
Is the a way i can add the topic to the buttons payload? I cant figure it out.  
.  
.  
.

more in how the gate node works and download

> **[node-red-contrib-simple-gate](https://flows.nodered.org/node/node-red-contrib-simple-gate)**
>
> A gate node for node-RED

My code :

```
[{"id":"91685e52.5f062","type":"function","z":"e4d8382f.f4813","name":"","func":"if (msg.topic === \"banana\") {\n return [null, msg];\n} else {\n return [msg, null];\n}\n","outputs":1,"noerr":0,"x":270,"y":240,"wires":[["d1469461.699a7"]]},{"id":"499c52b6.db221c","type":"inject","z":"e4d8382f.f4813","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["91685e52.5f062"]]},{"id":"d1469461.699a7","type":"change","z":"e4d8382f.f4813","name":"Open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"control","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":130,"y":280,"wires":[["b8635022.3cbd4"]]},{"id":"b8635022.3cbd4","type":"gate","z":"e4d8382f.f4813","name":"gate","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":410,"y":320,"wires":[["847b3d34.ebacf"]]},{"id":"847b3d34.ebacf","type":"debug","z":"e4d8382f.f4813","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":320,"wires":[]}]

```

.  
How its mean't to be used by the maker :

```
[{"id":"4405e5fa.2576d4","type":"gate","z":"5c82144c.a24d2c","name":"gate demo","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","x":310,"y":100,"wires":[["f2454fca.a69808"]]},{"id":"31a144c3.58ab6c","type":"inject","z":"5c82144c.a24d2c","name":"input","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["4405e5fa.2576d4"]]},{"id":"286fcfb6.811e08","type":"inject","z":"5c82144c.a24d2c","name":"open","topic":"control","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["4405e5fa.2576d4"]]},{"id":"d70ab41.582e248","type":"inject","z":"5c82144c.a24d2c","name":"close","topic":"control","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["4405e5fa.2576d4"]]},{"id":"f46bc39.5974c4","type":"inject","z":"5c82144c.a24d2c","name":"toggle","topic":"control","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":240,"wires":[["4405e5fa.2576d4"]]},{"id":"b044faad.785378","type":"inject","z":"5c82144c.a24d2c","name":"reset","topic":"control","payload":"default","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":280,"wires":[["4405e5fa.2576d4"]]},{"id":"f2454fca.a69808","type":"debug","z":"5c82144c.a24d2c","name":"output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":470,"y":100,"wires":[]}]

```

.  
Thanks in advance,

Ivar

.  
.  
P.S. I'm unexperienced in node-red

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [11 January 2019 10:46 UTC](https://discourse.nodered.org/t/adding-a-topic-to-payload/6691/2 "2019-01-11T10:46:20Z")

</div>

Do you mean add topic to the message? i.e. the message passed between nodes contains  
`msg.payload` and `msg.topic` ?

One easy way to do it would be to add a change node after the button  
Configure the change node to:  
`set` `msg.topic`  
`to` `<what you want it set to>`

---

<div class="post-metadata">

**Author:** ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)\
**Post date:** [11 January 2019 10:58 UTC](https://discourse.nodered.org/t/adding-a-topic-to-payload/6691/3 "2019-01-11T10:58:04Z")

</div>

ye that worked ,  
thank you
