Search code examples
mqttnode-redhome-automation

How to get the time of a received mqtt-message in node-red?


Can somenoe tell me how to get the publish-time of a mqtt message in node-red?

I have a retained message on my broker which gets fed to node-red via mqtt. The message is from a homematic wall-button which is hooked up to my broker via homegear.

The problem now is, that homegear retains all messages which is obviously good for sensors and so on. But the "true" message of the button - if pressed - also retains in it's topic. On deploy or restart of node-red it will receive the retained message and act if when the message just arrived.

Till homegear will put a "false" in the topic after the button is pressed, I have to check if the message in the topic is not an old one. Any chance?

The mqtt help of node-red tells me there are only four properties from mqtt: msg.topic, msg.payload, msg.qos, msg.retain.

Thanks for you help!

Cheers, Patrik


Solution

  • Unfortunately there is no way to get the time the message was actually published, the fields you are getting (qos, retained, topic and payload) are the only data in the whole message (MQTT is specifically designed to be as light as possible so has the absolute minimum data in the headers).

    The only way to get the time is for the publisher to include it in the message payload.