Timer with queuing?

I could not think of a better title.

What am I trying to accomplish:

  • Start recording motion detection from webcamera,
  • keep it running at least 30 seconds and
  • as long as no "motion detection:off" has been received.

The problem with motion detection is that it goes: on...off, on..off, on.....off if you pass by the camera and I want to keep it running during that time.

My flow (the "Thuis" part is an occupancy check):

I tried to play with a delay node, the delay node will drop the messages in between including the last "off" message, doesn't seem to work.

How can I:

  • send the initial "on", run at least 30 seconds, ignore the "off" during that time,
  • if another "on" has been received in between, reset the 30 second timer,
  • if no "on" was received in that time, turn it off ?

Hi @bakman2

You can use the Trigger node to achieve this.

From the sounds of it, you only really care about the 'on' messages. So your flow can use a Switch node to only pass those ones on.

You can then use a Trigger node configured to pass on the initial message, then wait for 30 seconds, extending the delay if new messages arrive. Then send an 'off' message.

[{"id":"4dcbea6.cd50414","type":"inject","z":"24d928f3.3c58f8","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":175,"y":719,"wires":[["9a288da0.280c5"]]},{"id":"3e41d776.3cb308","type":"inject","z":"24d928f3.3c58f8","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":760,"wires":[["9a288da0.280c5"]]},{"id":"fa4c377a.4284a8","type":"trigger","z":"24d928f3.3c58f8","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"30","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":530,"y":720,"wires":[["496c3c1b.ad6d54"]]},{"id":"9a288da0.280c5","type":"switch","z":"24d928f3.3c58f8","name":"ignore off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":720,"wires":[["fa4c377a.4284a8"]]},{"id":"496c3c1b.ad6d54","type":"debug","z":"24d928f3.3c58f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":750,"y":720,"wires":[]}]

I see what you are saying and it seems to be working indeed.

As I am using an exec node that I want to kill once the trigger has finished, I try to "then send" {"kill":"SIGHUP"} as json but this gets encapsulated by a key/value of payload, is this correct ? eg:

{"payload":{"kill":"SIGINT"},"_msgid":"fc4c145e.fb36b8"}

Yes, the 'then send' field is specifying the payload the node sends. If you need other properties set on the message, add a Change node afterwards to set what you need besides the payload.

Got it! Change node didn't work for me, but function to the rescue.
Thanks for the quick response/help.

I don't want to butt in, but you last post is confusing:

It should.

Nick isn't the type to write faulty code.

For the sake of curiosity, could you elaborate on what is happening?

You are right and triggered me to check it again.
I have not used the change node before tbh.

I was using Set the other way around as:

set: msg.payload.kill
to: msg.kill

I read this as source > dest, but I should read it as set new prop from source, switched it and it works.

Thanks for the trigger.

No worries.

I have fallen for that trap myself a few times too. So don't fret on it too much.

:slight_smile: