Ignore retained MQTT messages at restart

Hi there,

I'm facing an annoying problem with my node-red installation. The MQTT server and node-red are running on two different machines. In addition, I have Tasmota installed on a esp8266 device that measures temperature etc. and works as a Zigbee coordinator, too.
Now, if I restart node-red ghost switching occurs because the last Zigbee messages are read and they trigger some actions. I cannot turn off message retain because I need them for another application. Therefore, my question is: is it possible to make node-red ignore the retained (or all) messages at restart?

I think that if you turn off the clean start feature then you may not get them but I've never tried.

Alternatively, you would need a simple gate function to filter them out at startup. Use a gate node and block until a flag is set true. Use a trigger node with a delayed start to change the flag.


I tried without the clean session parameter but unfortunately this did not solve the issue.
Now, I added a gate and it works. If someone has the same problem, this is the simple solution:


You could use a function node that ignores the first message. Something like

let pastFirst = context.get("pastFirst") || false
if (!pastFirst) {
  context.set("pastFirst", true)
  msg = null
return msg

If you just want to ignore the retained messages, then a switch node which checks the msg.retain flag should suffice.

1 Like

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