The DELAY node. Not doing what I want

#1

Sorry folks, I’m at it again.

I am wanting a “delay” and the DELAY node seems the right one for it.

I have read that it can be adjusted with msg.delay and I am trying to set it with a slider.

But it doesn’t seem to want to work.

[{"id":"b9ea90e8.3238e8","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":500,"wires":[["522c2349.6c1c3c"]]},{"id":"7b1feec2.732638","type":"ui_slider","z":"e9882c4e.450a6","name":"","label":"Wipe Delay2","group":"d8f7708b.e6a3b","order":0,"width":"5","height":"1","passthru":true,"topic":"msg.delay","min":0,"max":"20","step":1,"x":390,"y":560,"wires":[["b9ea90e8.3238e8"]]},{"id":"8755038.67b138","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":500,"wires":[["b9ea90e8.3238e8"]]},{"id":"522c2349.6c1c3c","type":"debug","z":"e9882c4e.450a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":500,"wires":[]},{"id":"d8f7708b.e6a3b","type":"ui_group","z":"","name":"Group 1","tab":"cf397e02.acf53","order":1,"disp":true,"width":"10"},{"id":"cf397e02.acf53","type":"ui_tab","z":"","name":"Message CTL","icon":"dashboard","order":3}]

I can’t seem to see the elephant.

P.S.
Ok, multiply it by 1000.

It still doesn’t seem to change the value when I slide the slider.

0 Likes

Variable delay (again) Yeah, sorry
#2

You are setting msg.topic to msg.delay and leaving the value in msg.payload. You need to set msg.delay to the value. You can do this by inserting a change node after the slider set to Move msg.payload to msg.delay. However the variable delay only works for the message that has that property set, so what you actually need to do is to add msg.delay from the slider into your ‘banana’ message. One way is to write a function node that receives the values from the slider and from the inject node, saves the current slider value to the node context, and when the banana message is received adds the delay property into the message and passes it on. Ask again if you don’t know how to do that.

0 Likes

#3

Yeah, thanks.

I think I was wanting something it isn’t supposed to do.

Though I now get the idea that I can send a message with a different delay than the one set.

So that works for THAT message.

I was wanting to adjust/change the time for ALL messages and not needing to alter their msg.delay value.

I have now (since posting) got the idea, and although I now have it working… It isn’t doing what I wanted.

What I think I will have to do is include a couple of function nodes: 1 to set the delay value and one to add it to messages passing through it to the delay node and doing it via the msg.delay value.

Just seems a bit of a haphazard way of doing it. Though I guess that is only for THIS occasion.

Live and learn.

Thanks though.

0 Likes

#4

This is what I have made - since:

But I’m stuck with dropping the msg.delay “payloads” not being passed on.

var delay_ = msg.delay;

//  I need to make this happen ONLY if the entire package
//  is a valid message package and not one adjusting the 
//  delay time.
var msg_ = msg.payload;
msg = {payload:msg_, delay:delay_};
return msg;
//  end of condition.
0 Likes

#5

As I said, the function node will need to save the delay in the node context in order to add it to the data message, however, this should do it just using standard nodes. The top two inject nodes are simulating your slider (set the topic to delay in the slider) and the lower one is the data message you want to delay, make sure the topic for these messages is value.

[{"id":"2a1b2d80.adafb2","type":"delay","z":"6dc690a3.1abc88","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":593,"y":595,"wires":[["eefd1ddd.b713b"]]},{"id":"3edc9f5b.5cfea","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"delay","payload":"2000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":105,"y":503,"wires":[["d1525802.84e74"]]},{"id":"a87e4f8f.a642d8","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"value","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":112,"y":616,"wires":[["d1525802.84e74"]]},{"id":"d1525802.84e74","type":"join","z":"6dc690a3.1abc88","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":276,"y":546,"wires":[["7a3b6d4d.88cda4","7bb27fba.c5b48"]]},{"id":"576f49c1.902ee","type":"change","z":"6dc690a3.1abc88","name":"","rules":[{"t":"move","p":"payload.delay","pt":"msg","to":"delay","tot":"msg"},{"t":"move","p":"payload.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":405,"y":596,"wires":[["2a1b2d80.adafb2"]]},{"id":"7bb27fba.c5b48","type":"switch","z":"6dc690a3.1abc88","name":"Pass value msgs","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"value","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":445,"y":546,"wires":[["576f49c1.902ee"]]},{"id":"88eab954.f85478","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"delay","payload":"3000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":106,"y":541,"wires":[["d1525802.84e74"]]},{"id":"eefd1ddd.b713b","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":584,"y":649,"wires":[]}]
0 Likes

#6

Ok.

While you were doing that, I was making this:

[{"id":"8755038.67b138","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":740,"wires":[["2687224f.5a0a9e"]]},{"id":"2687224f.5a0a9e","type":"function","z":"e9882c4e.450a6","name":"","func":"context.delay_ = msg.delay;\n//  START\n//  only if valid message\nvar msg_ = msg.payload;\nmsg = {payload:msg_, delay:context.delay_};\nreturn msg;\n//  END","outputs":1,"noerr":0,"x":690,"y":740,"wires":[["b9ea90e8.3238e8"]]},{"id":"b9ea90e8.3238e8","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":740,"wires":[["522c2349.6c1c3c"]]},{"id":"33b2cea6.90bb22","type":"inject","z":"e9882c4e.450a6","name":"","topic":"msg.delay","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":320,"y":840,"wires":[["e62fa1f0.d7b41","e7efcbb9.3d718","2687224f.5a0a9e"]]},{"id":"522c2349.6c1c3c","type":"debug","z":"e9882c4e.450a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":740,"wires":[]}]

Yes, work in progress with the function node.

It isn’t that I am posting here wanting people to work it out for me. Sorry if that was implied.
I want to learn. It is just I get stuck sometimes and just can’t nut it out.

Shall look at your code now.

0 Likes

#7

You are again getting confused about topic, payload and other properties. In your inject node you are setting msg.payload to the string “msg.delay” and msg.payload to 2000. You are not setting msg.delay to 2000. However the more fundamental problem is that the two messages will come in separately to your function node, so you would need to detect which sort of message each one is, if it is a delay message then save that in the node context and if it is a value message get the delay from the node context and add it to the message (as msg.delay).

1 Like

#8

Thanks much Colin.

Thanks too in that you explained that I am STILL mixing up the injection point.

I thought that if I put the value of 2000 into it and set the topic as “delay” then the entire message package would be:
msg.delay would be set to 2000.

When actually it is more like:
msg.topic = msg.delay and a value of 2000 is in the payload — Right?

So I need to learn/work out how to set that up first.

To do that I will need to … I won’t “stall” this post. I’ll go away and try to clarify what I am doing and post updates.

Again: Thanks for pointing out the silly mistake I was doing.

On to the second part where the node will have to be smart:
Yes. That’s right.
I thought I had done that before with my control nodes where I block messages passing if a certain message is received and allowed if another is.
The “actual” message isn’t changed. Just controlled flow by the control message.

Alas that is easier to do, as the control signal is easier (?) to identify.
In this case it won’t be as easy - I fear.

More learning needed.

Or a slight re-think of how I am doing it.

Not offence to what you showed me, but your example needs the message and time to be paired.
Mine accepts an overall time delay and applies it to all messages until a new delay time is received.

0 Likes

#9

That should not be the case. Once a delay and value message have been received then each value message should be delayed by the time specified by the latest delay message.

0 Likes

#11

Colin,

(Dunno why the quote isn’t working)

Ok, but still your flow wanted two inputs before it on-sent the message.

In my flow the only time a new time would be set is when I want to change it.

Anyway… I’m nearly there. I hope.

How is this:

[{"id":"8755038.67b138","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":740,"wires":[["2687224f.5a0a9e"]]},{"id":"33b2cea6.90bb22","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":840,"wires":[["e62fa1f0.d7b41","e7efcbb9.3d718","2687224f.5a0a9e"]]},{"id":"cb7d83ff.37a39","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"9000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":900,"wires":[["2687224f.5a0a9e"]]},{"id":"2687224f.5a0a9e","type":"function","z":"e9882c4e.450a6","name":"","func":"context.delay_ = msg.delay;\ncontext.msg_ = msg.payload;\nif (context.msg_ > 0)\n{\n    context.set('delay_',msg.delay);\n    node.status({fill:\"yellow\",shape:\"dot\",text:\"value\"});\n}\nelse\n{\n    msg.payload = context.msg_;\n    msg.delay = context.delay_;\n//    msg = {payload:msg.payload, delay:msg.delay};\n    node.status({fill:\"green\",shape:\"dot\",text:\"message\"});\n    return msg;\n}\n","outputs":1,"noerr":0,"x":690,"y":740,"wires":[["b9ea90e8.3238e8","7f916ac2.ae7bcc","eaebfbfa.76676"]]},{"id":"b9ea90e8.3238e8","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":740,"wires":[["522c2349.6c1c3c"]]},{"id":"522c2349.6c1c3c","type":"debug","z":"e9882c4e.450a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":740,"wires":[]}]

The function node indicates what is going on.
Press the 1000 node and you get a YELLOW blip. (Indicating it has a stored value)
Then when you press the banana button, it turns green.
Indicating the message is received.

That is then combined and sent to the delay node.
Alas it always gets 0 and I don’t know why the value isn’t being put into/onto the outgoing packet of the function node.

0 Likes

#12

There’s something wrong with something.

Indulge me:

[{"id":"2e93a8b5.1f22d8","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":640,"wires":[["920c54cd.f416b"]]},{"id":"920c54cd.f416b","type":"function","z":"e9882c4e.450a6","name":"Fast track","func":"//          var msg2 = { payload:\"N/C\" };\nmsg = {payload:\"Payload\", delay:1000};\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":640,"wires":[["b9ea90e8.3238e8"]]},{"id":"8755038.67b138","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":740,"wires":[["2687224f.5a0a9e"]]},{"id":"33b2cea6.90bb22","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":840,"wires":[["e62fa1f0.d7b41","e7efcbb9.3d718","2687224f.5a0a9e"]]},{"id":"2687224f.5a0a9e","type":"function","z":"e9882c4e.450a6","name":"","func":"context.delay_ = msg.topic;\ncontext.msg_ = msg.payload;\n//if (context.msg_ > 0)\nif (msg.payload > 0)\n{\n    context.set('delay_',msg.payload);\n    node.status({fill:\"yellow\",shape:\"dot\",text:\"value\"});\n    return msg.delay;\n}\nelse\n{\n//    msg.payload = context.msg_;\n//    msg.delay = context.delay_;\n//    msg = {payload:msg.payload, delay:msg.delay};\n    msg = {payload:context.msg_, delay:context.delay_};\n    node.status({fill:\"green\",shape:\"dot\",text:\"message\"});\n    return msg;\n}\n","outputs":1,"noerr":0,"x":690,"y":740,"wires":[["b9ea90e8.3238e8","7f916ac2.ae7bcc","eaebfbfa.76676"]]},{"id":"b9ea90e8.3238e8","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":740,"wires":[["522c2349.6c1c3c"]]},{"id":"522c2349.6c1c3c","type":"debug","z":"e9882c4e.450a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":740,"wires":[]}]

Press the top “banana” node. That goes through a “fast track” node. This sets the time to 1000 ms.

That goes down to the delay node. That shows 1 second. It works.

Given that it has 1 second now, if you press the delay 1000 button (ok, you will see the yellow indicator activate on the function node) and then the lower “banana” button, you will see the green indicator.
The delay node becomes active, but it is 6 seconds.

Sorry, but that goes against what you said previously:
That should not be the case. Once a delay and value message have been received then each value message should be delayed by the time specified by the latest delay message.

Blank look.

Oh, just to declare:
Yes, I know: in the latter example, the “fast track” makes it 1 second.
Pressing the button marked 1000 (further down) also sets it to 1 second.
But when you press the banana button and it goes through the function node I wrote, it somehow becomes 6 seconds…

Just so it can’t be said I was being silly using the same value twice. Irrispective, with my function block it somehow becomes a 6 second delay.

0 Likes

#13

It does require one of each before the first message will be sent out, but only the first time. Thereafter each value message will be delayed by the time from the most recent delay message. I assumed that the slider will send a message on startup so that would be ok. If it doesn’t then add an inject node set to inject once on startup with the default delay time you want. So on my sample flow just change one of the delay injectors to inject on startup.

0 Likes

#14

If you want to use a function you don’t need anything as complex as you have. Something like this should do it

[{"id":"3edc9f5b.5cfea","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"delay","payload":"2000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":683,"wires":[["33116ffe.769ba8"]]},{"id":"a87e4f8f.a642d8","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":104,"y":797,"wires":[["33116ffe.769ba8"]]},{"id":"88eab954.f85478","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"delay","payload":"3000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":101,"y":721,"wires":[["33116ffe.769ba8"]]},{"id":"eefd1ddd.b713b","type":"debug","z":"6dc690a3.1abc88","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":584,"y":649,"wires":[]},{"id":"33116ffe.769ba8","type":"function","z":"6dc690a3.1abc88","name":"Set delay","func":"if (msg.topic === \"delay\") {\n    context.set(\"delay\", msg.payload);\n    msg = null;\n} else {\n    delay = context.get(\"delay\");\n    if (delay === undefined) delay = 1000;  // default delay ms\n    msg.delay = delay;\n}\nreturn msg;","outputs":1,"noerr":0,"x":303,"y":744,"wires":[["78252539.d7ae4c"]]},{"id":"78252539.d7ae4c","type":"delay","z":"6dc690a3.1abc88","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":486,"y":746,"wires":[["81ccddb.13174a"]]},{"id":"81ccddb.13174a","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":647,"y":746,"wires":[]}]
0 Likes

#15

Thanks Colin.

While we were both working on the “problem”, I got this:

Excuse the mess. But it works.

I wouldn’t mind getting rid of the extra junk in the function block, but that’s work in progress.

[{"id":"522c2349.6c1c3c","type":"debug","z":"e9882c4e.450a6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":740,"wires":[]},{"id":"b9ea90e8.3238e8","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":740,"wires":[["522c2349.6c1c3c"]]},{"id":"2687224f.5a0a9e","type":"function","z":"e9882c4e.450a6","name":"","func":"var delay_ = msg.delay;\ncontext.payload_ = msg.payload;\ncontext.topic_ = msg.topic;\nif (context.topic_ == 'delay')\n{\n    node.status({fill:\"yellow\",shape:\"dot\",text:\"value\"});\n    context.set('delay_',msg.payload);\n}\nelse\n{\n    node.status({fill:\"green\",shape:\"dot\",text:\"message\"});\n    delay_ = context.get('delay_');\n    msg.delay = delay_;\n    return msg;\n}\n","outputs":1,"noerr":0,"x":690,"y":740,"wires":[["b9ea90e8.3238e8","7f916ac2.ae7bcc","eaebfbfa.76676","eed09f63.06b3c"]]},{"id":"8755038.67b138","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":740,"wires":[["2687224f.5a0a9e"]]},{"id":"33b2cea6.90bb22","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"1000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":840,"wires":[["e62fa1f0.d7b41","e7efcbb9.3d718","2687224f.5a0a9e"]]},{"id":"cb7d83ff.37a39","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"9000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":900,"wires":[["2687224f.5a0a9e"]]}]

I WILL look at yours out of respect.

Thanks.

Would you mind looking at that last effort?

Questions are pending, but I want to look at your version first.

0 Likes

#16

I like your way better.

I was NEARLY there with what I was doing.

I am still (will I ever?) not confident about the conditional stuff how you did it.

Ok to ask my questions now?
As we seem both to have written the same function in that node.

0 Likes

#17

Yes, we have ended up with similar results, a case of parallel evolution I think. I don’t think the first three lines of your function are necessary, use msg.topic in line 4 instead. Also I am not sure what effect passing an undefined value to the delay node will be (as is the case if you send the first value message before a delay message).
On a point of style I would never put a return anywhere other than at the end, I have seen to many bugs caused by code being added later not being executed because of the early return. However not everyone will agree with me on that one.

1 Like

#18

Great to hear we are similar in our thinking.

I seem to be (still ?) confused with what the context.blah and var things.

My thinking is:
(excuse the rant)
The message comes in.
The delay is in msg.delay
If the msg.delay is “valid” store this. From what I get this has to be via CONTEXT, as it has to survive the node’s reiteration.

Alas this is done by looking at the msg.topic and if it equals ‘delay’ then…

ELSE
(meaning that it wasn’t a delay message)
get the stored value and construct the new message.
That is done by getting this message’s payload and add the msg.delay to it.

I have the first three lines because I need to get the topic, payload (to store if it is a delay) and …
You are probably right. I shall delete them.

There seems to be a flaw with my structural understanding of what is what.

Again: Not wanting to dismiss your efforts, this is the boiled down version I got with a mixture of what you have and what I had.

Now, also there are a few things which are “different” to the original request and were left out only to keep it simple.

I haven’t included the extra input nodes as this is only to get the idea working.
Oh, the idea:
A message is received and a .sh (bash) script is run to then execute an .py (python) script.
This gets around the problem about parsing the message to the script. (another thread.)

It is displayed and after a certain (set) time, it is wiped.
It is wiped by running another .sh script. Which is where the delay comes in.
So please don’t fret about what the scripts do and how they do it.
I busted a lot of time getting them to work and take multiple words as parameters.
This is done by wrapping them in “quotes”.

[{"id":"2dfc598e.d9a4ee","type":"ui_slider","z":"e9882c4e.450a6","name":"","label":"Wipe Delay","group":"d8f7708b.e6a3b","order":0,"width":"5","height":"1","passthru":true,"topic":"delay","min":0,"max":"20000","step":"1000","x":110,"y":180,"wires":[["d6716a43.917c88","e4ae8879.587a6","e9bf5a2f.345b3","ffec291e.484cc"]]},{"id":"4851ca4d.bbe0dc","type":"inject","z":"e9882c4e.450a6","name":"","topic":"","payload":"Banana","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":220,"wires":[["9f112d7f.e7a9d8","e9bf5a2f.345b3"]]},{"id":"e9bf5a2f.345b3","type":"function","z":"e9882c4e.450a6","name":"Set delay","func":"if (msg.topic === \"delay\") \n{\n    node.status({fill:\"yellow\",shape:\"dot\",text:\"value\"});\n    context.set(\"delay\", msg.payload);\n//    msg = null;\n} \nelse \n{\n    node.status({fill:\"green\",shape:\"dot\",text:\"message\"});\n    delay = context.get(\"delay\");\n    if (delay === undefined) delay = 1000;  // default delay ms\n    msg.delay = delay;\n    return msg;\n}\n","outputs":1,"noerr":0,"x":300,"y":220,"wires":[["315aeaa0.3c51ce","11f395d8.d4035a","f2b49294.ac6ce8"]]},{"id":"ffec291e.484cc","type":"function","z":"e9882c4e.450a6","name":"/1000","func":"var j = msg.payload;\nvar x = j / 1000;\nmsg.payload = x;\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":180,"wires":[["cf4017e3.973d7"]]},{"id":"6ecb508b.ca1f1","type":"inject","z":"e9882c4e.450a6","name":"","topic":"delay","payload":"4000","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":"2","x":110,"y":280,"wires":[["e9bf5a2f.345b3"]]},{"id":"cf4017e3.973d7","type":"ui_text","z":"e9882c4e.450a6","group":"d8f7708b.e6a3b","order":0,"width":"5","height":"1","name":"","label":"Seconds Delay = ","format":"{{msg.payload}}","layout":"row-center","x":490,"y":180,"wires":[]},{"id":"315aeaa0.3c51ce","type":"delay","z":"e9882c4e.450a6","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":220,"wires":[["61300481.033ab4"]]},{"id":"9f112d7f.e7a9d8","type":"exec","z":"e9882c4e.450a6","command":"/home/pi/PiFace/LCD_message","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":790,"y":140,"wires":[["d59566e1.636b48","39f43c2a.58068c"],[],[]]},{"id":"61300481.033ab4","type":"exec","z":"e9882c4e.450a6","command":"/home/pi/PiFace/LCD_off","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Wipe display after a time","x":770,"y":220,"wires":[["9c1eb40a.bbea68","39f43c2a.58068c"],[],[]]},{"id":"d8f7708b.e6a3b","type":"ui_group","z":"","name":"Group 1","tab":"cf397e02.acf53","order":1,"disp":true,"width":"10"},{"id":"cf397e02.acf53","type":"ui_tab","z":"","name":"Message CTL","icon":"dashboard","order":3}]

There is also a “default time” node which sets the default time to 4 seconds so when I deploy the flows it isn’t some weird number.

0 Likes

#19

No, it is in msg.payload if msg.topic is delay.

You didn’t need the first lines because it set a variable to msg.delay, and msg.delay at this point is not set.
You didn’t need the second line because it wrote (using the obsolete context format) to a context variable called ‘payload’ which you never read back.
You didn’t need the third line because you can just use msg.topic directly in the next line.

The flow in your last post looks good, except that you don’t need the default delay node, you can set the default in line 11 in the function node which says ‘if you haven’t already set a delay time in the context then set it to this value’.

0 Likes

#20

Is it all working now?

0 Likes

#21

Yes, and again: Thanks for the help.

Ok, to re-cap:
You did what I did in another case where you sent the value in the payload - given - but tagged the message with the topic. I was mistaken for a long time that it was actually msg.delay which is what the node wants.

But you “cheated” and until the last second it was the topic and you moved the msg.topic -> msg.delay()

Got it.

I am really wanting to get out of using the old context format, but so many of my nodes have that in them and so when I am stuck and search my records I find a lot of them - rather than the new ones which are a lot smaller in occurrence.

Alas I am not doing a good job of documenting the progress of the nodes as they “grow” and become better. (Work in progress).

Ok, the “default time” part. Yes, ok, if the node has a default value. It is really academic as it shouldn’t really ever be in the state where there is no value set. But to be a good programmer, I probably should put it in there.

0 Likes

Invoke every user defined time