# If and return messages from mqtt

**URL:** <https://discourse.nodered.org/t/if-and-return-messages-from-mqtt/64839>\
**Category:** General\
**Tags:** function-node, mqtt\
**Created:** [8 July 2022 13:23 UTC](https://discourse.nodered.org/t/if-and-return-messages-from-mqtt/64839 "2022-07-08T13:23:15Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 July 2022 17:09 UTC](https://discourse.nodered.org/t/if-and-return-messages-from-mqtt/64839/4 "2022-07-08T17:09:58Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

I edited your post to fix it.

In a `function` node you could do something like this:

```auto
if (msg.payload == 'Liga') {
    msg.payload = true;
}
if (msg.payload == 'Desliga') {
    msg.payload = 1;
}

return msg;

```

I'm unsure if you want the scond one to be a 1 or 0

---

_[View the full topic](https://discourse.nodered.org/t/if-and-return-messages-from-mqtt/64839)._
