Trigger node expected behavior

Hey,

I'm having a problem with the trigger node and I'm not quite sure if it's the way it's meant to work or a bug.

The functionality I'm trying to achieve is:

  • forward all messages
  • if no message has arrived for 5 mins, set offline mode

Does the trigger node swallow all messages (except the first one) or should it always forward the input message when configured to send the input message?

[{"id":"50923526.944fbc","type":"trigger","z":"60e86883.187908","name":"","op1":"","op2":"{\"online\": false}","op1type":"pay","op2type":"json","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":550,"y":140,"wires":[["2600df68.b08ce"]]},{"id":"540ee0c9.953ba","type":"function","z":"60e86883.187908","name":"Map","func":"return {\n    payload: {\n        on: msg.payload.state === 'ON',\n        online: true,\n    },\n    topic: msg.topic,\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":140,"wires":[["50923526.944fbc","398563bd.8873ec"]]},{"id":"c1e5338b.31e34","type":"mqtt in","z":"60e86883.187908","name":"","topic":"zigbee2mqtt/light/+","qos":"2","datatype":"json","broker":"f569d34c.8c7ed","nl":false,"rap":true,"rh":0,"x":150,"y":140,"wires":[["540ee0c9.953ba"]]},{"id":"2600df68.b08ce","type":"debug","z":"60e86883.187908","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":140,"wires":[]},{"id":"398563bd.8873ec","type":"debug","z":"60e86883.187908","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":80,"wires":[]},{"id":"f569d34c.8c7ed","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"node-red","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Cheers!

The wait 5 min then do something part works (when I add in an inject and shorten time for testing)... you should see a blue dot under the Trigger node as it is counting down, and yes, it passes on the msg that "triggered" it.

It is the something that you want done that is confusing to me. What exactly do you want to go "offline"?

The problem is that if you inject multiple times (within those 5 mins) the message is not forwarded anymore, it just disappears... I'm not sure if that's the intended behavior or a bug.

The trigger node does not forward messages received after the first one (until the trigger resets). If you want all messages forwarded then connect them as you have wired the top debug node in your flow. That will receive all messages and the bottom one should see just the offline message.

1 Like

I take it literally... as in it "Waits" until time or override.

image

1 Like

Set the trigger to not pass the initial payload, . Then bypass the trigger with a wire
e.g.

[{"id":"1e9edc1d.fb0d8c","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload.state","v":"ON","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test/test","x":140,"y":3140,"wires":[["540ee0c9.953ba"]]},{"id":"540ee0c9.953ba","type":"function","z":"c74669a0.6a34f8","name":"Map","func":"return {\n    payload: {\n        on: msg.payload.state === 'ON',\n        online: true,\n    },\n    topic: msg.topic,\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":3140,"wires":[["50923526.944fbc","2600df68.b08ce"]]},{"id":"50923526.944fbc","type":"trigger","z":"c74669a0.6a34f8","name":"","op1":"","op2":"{\"online\": false}","op1type":"nul","op2type":"json","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":470,"y":3180,"wires":[["2600df68.b08ce"]]},{"id":"2600df68.b08ce","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":3140,"wires":[]}]

I set the trigger to 5 seconds for testing

2 Likes

Cool, thanks for the help!

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