Send only one message to a MQTT topic

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).

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

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

and

// 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?

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

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

1 Like

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