Turn light On after motion detected 3 times within 5 mins

I want to use a MQTT motion sensor to turn ON a light BUT only after it has detected 3 motion triggers within a 5 minute period. If no 3 triggers within the 5 mins, then reset and start again. How can this be done in Nodered? Thanks.

What have you tried so far?
Where are you having an issue?

I'd probably use a flow variable that was an object so you could store a start time and a count. When a msg comes thru I'd get the flow variable and check if the current time is greater than five munites fron the saved time. If it is, I's store the current time and set the counter to 1 and save it and end.

If it was less than 5 minutes, I'd add one to the count and check if it was less than 3. If it is, I'd end the flow. If it was 3 I send a msg on to turn on the light.

But how long will you leave it on? What if the light is already on? Will there be a manual switch to turn it on? If so, how will you send an indication that it is on? Does that effct the count?

I could probaqbly go on, but that should give you something to think about :grin:

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