# Send command to mqtt output after a function node

**URL:** https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302
**Category:** General
**Tags:** function-node, node-red-dashboard, mqtt
**Created:** [6 May 2022 16:00 UTC](https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302 "2022-05-06T16:00:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mgfeal](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mgfeal](https://discourse.nodered.org/u/mgfeal)
#### Post date: [6 May 2022 16:00 UTC](https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302/1 "2022-05-06T16:00:04Z")

</div>

Hi,

I need to process the msg.consumototal that my function receives.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10b90188b7108812dcc813ce5171753930ee0135.png)

I read and process the msg.consumototal value and I want to send a different mqtt command depending on the value that msg has.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b650a43a82e0d22087fb6436f5ce29e956e9c56.png)

MQTT commands:  
shellies/shellyplug1/relay/0/command/on  
shellies/shellyplug1/relay/0/command/off

Thanks

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [6 May 2022 16:25 UTC](https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302/2 "2022-05-06T16:25:08Z")

</div>

Firstly, you've taken out the bit that will actually send a message on to the next node. `return msg`

Next, you need to understand that the "commands" you list are MQTT "topics". Node-RED makes using MQTT easy because it mostly follows the same conventions.

So you can set `msg.topic = 'shellies/shellyplug1/relay/0/command'` and `msg.payload = 'on'`.

---

<div class="post-metadata">

### Author: ![mgfeal](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@mgfeal](https://discourse.nodered.org/u/mgfeal)
#### Post date: [6 May 2022 16:30 UTC](https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302/3 "2022-05-06T16:30:36Z")

</div>

> [@TotallyInformation](#):
>
> msg.payload = 'on'

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1cb974992dbf7bf95c60f7f5888edba4c553679c.png)

It works!!  
Many thanks!!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [20 May 2022 16:30 UTC](https://discourse.nodered.org/t/send-command-to-mqtt-output-after-a-function-node/62302/4 "2022-05-20T16:30:58Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
