# Send only one message to a MQTT topic

**URL:** <https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929>\
**Category:** General\
**Created:** [28 January 2021 13:48 UTC](https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929 "2021-01-28T13:48:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [28 January 2021 13:48 UTC](https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929/1 "2021-01-28T13:48:28Z")

</div>

Hi,

I have a flow for a Settopbox which gets the status of the box in a JSON string. This is Injected every second (at the moment I have turned repeat off).

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

The goal is to SYNC the remotes ON/OFF button (which is a Toggle button) with an ON/OFF switch in Domoticz (domotics software)

One of the attributes of the JSON string is the **msg.payload.setopboxState**  
This has 2 Values: ONLINE\_RUNNING (box is ON) and ONLINE\_STANDBY (box is Off)

I have created 2 function nodes to publish an MQTT message to topic: **domoticz/in**

```auto
// Turn ON domoticz device when payload is ONLINE_RUNNING
 
if (msg.payload.setopboxState == 'ONLINE_RUNNING') {
    msg.payload = {
        "idx": 385,
        "nvalue": 1,
    }
    return msg;
}

```

and

```auto
// Turn OFF domoticz device when payload is ONLINE_RUNNING
 
if (msg.payload.setopboxState == 'ONLINE_STANDBY') {
    msg.payload = {
        "idx": 385,
        "nvalue": 0,
    }
    return msg;
}

```

The problem is the **domoticz/in** topic also receives every second the msg.payload.  
How do I publish only one msg.payload: when the **msg.payload.setopboxState** value changes?

---

<div class="post-metadata">

**Author:** ![hugobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hugobox/32/2948_2.png) [@hugobox](https://discourse.nodered.org/u/hugobox)\
**Post date:** [28 January 2021 14:14 UTC](https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929/2 "2021-01-28T14:14:50Z")

</div>

Hi!  
Try to add the RBE node between your functions and MQTT out.

---

<div class="post-metadata">

**Author:** ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)\
**Post date:** [28 January 2021 14:57 UTC](https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929/3 "2021-01-28T14:57:51Z")

</div>

Thanx, that did the trick!

I also removed the switch node (there is no need to split the status value up because that was already handled in the Function node) and created one Function Node with IF/Else IF statements....that is more efficient

---

<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:** [11 February 2021 14:58 UTC](https://discourse.nodered.org/t/send-only-one-message-to-a-mqtt-topic/39929/4 "2021-02-11T14:58:00Z")

</div>

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