Change a msg.payload in a function node without continuing flow

Hello,

I am putting together a scheduler in the dashboard using the later node. The first part of the schedule is to choose a TV channel from a dropdown list and then to set the time you wish to change channel. In order to avoid the channel changing immediately and ignoring the later time request I need the TV channel (IR code) to simply populate the function node and nothing more. Then when the desired schedule time has been met, to continue the flow. Is there a way to do this please?

Thanks in advance

Glenn

Assuming you are only talking about one channel change you could use the delay node.
Where you can pass a message with the delay time set (msg.delay) and it will output the message after that delay. So as you know the present time and the time you want to change channels you can calculate the delay and use that.

I've tried that. All that does is send the msg.payload on after the delay has lapsed. I want the msg.payload to be "registered" only in the function node and then the later node to act to continue the flow at the future point in time set by the user in the dashboard.

I think you need to not think of this as 'continuing the flow'. Instead, you want to store the desired channel and then a separate flow that is triggered at the desired time is able to retrieve the requested channel.

You could use Context to store the value - https://nodered.org/docs/user-guide/context - more specifically Flow Context. So your first flow will store the desired channel as a flow context value. Your second, time-triggered flow, can then look up that flow context value and pass it on as needed.

Thanks Nick,

Will this only work in a global context with the context stored via localfilesystem?

It depends if you want the values to survive restarts of Node-RED, or if you can live with the values only being held in memory (the default).

Sounds like you want a join node (in "manual" mode), set to create a "key/value object" using the msg.topic as the key. Then set it to send the msg after 2 parts are received, so it waits for both the "time" and "channel" topic msgs to arrive before it "continues" the flow...

Of course, your dropdown node will need to send the msg with topic: "channel", while the time picker will have to use topic: "time" for this to work.

Hello,

I've tried your suggestion and I keep getting the message "Message missing key property 'msg.time' - cannot add to object. I have tried changing the msg.payload to msg.time as well as setting both topics as described.

The question I have is around the "join" element. Is it that the two messages are joined rather than one message being sent once another message (later) has happened?

Thanks in advance

You need to use the value of msg.topic as the "key" -- then, each of your ui elements needs to send the string "time" or "channel" in the msg.topic property.

Yes, the purpose is to combine the two input msgs into one payload with 2 properties:

{
  msgid: "2f833b95.f9c674",
  topic: "time",
  payload: {
    time: "18:30",
    channel: "12"
  }
}