Count function reset daily

I got the follow function code:

var count=context.get('count') || 1;
count +=1;
msg.payload = count;
context.set('count', count);
return msg;

Now i want it to count the amount daily. So every day it starts at 0. How could i get this?

Hi @Carloj

You could use an Inject node configured to trigger at midnight every day. Use that to trigger a flow that does whatever you want with that day's count and then resets the count value in context.

As @knolleary said a trigger node but set it's topic to something like "reset" then add code to your function block to reset your counter when msg.topic == "reset"

I understand it, but the device is offline in the night (no power) it's getting power in the morning. Does the trigger still does it job when it starts at like 08:00 in the morning? (it could also start before or after that time.