Joining messages with different intervals

Using Node-Red to readout our smart- energy meter. Messages coming in through Mqtt.
Electricity info comes in once every second. Gas usage info comes once every 5 minutes.
I want to join only the last messages only once at the end of every day and insert them in a Sqlite database.
My question is which nodes to use for joining the messages and pass only the last messages at a specific time in a combined message (Array) .
Can someone put me on the right track?

Hello Max,

I do something similar writing to a database but my values come from Modbus energy meters (The source in not so importand but the steps)

  1. Use a Function node after each Mqtt node to save the latest value in Global or Flow Context.
    You can read more about the use of Context here

  2. Use a Cron-plus schedule node to trigger another Function node that reads the latest values from Context and prepares the sql Insert query which in turn will be wired to the Sqlite node to write the data in the db.

If you share your flow maybe we can recommend any additional steps.

1 Like

Thanks hou Andy. The Context function is new to me. I will study on it en let you know of the results in the coming week.

I guess the values from the meters are incremental. You can also subtract the new value from the last and get a more detailed view of the consumption.

Yes. It's working fine now. Exactly how I wanted it. Thank you very much for guiding me.


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