Looking for something to happen within a time range

Hi. Impressed with Node Red, but can't get my mind round how to do this -
I want to trigger an event if the kettle (monitored by POW2) has not been used between 06:00 and 08:00 - that would be an anomaly.
Any guidance / ideas please?

To achieve that I would keep track of each time the kettle is used (probably I would save the last time in a function node's context) then at 0800 use an inject node to trigger a check on when it was last used. If that is more than two hours ago then send a message to take appropriate action.

1 Like

Thanks Colin, hadn't thought of the logic in that way, I'll give it a go.

Looking at function node, can't see how to save last time in context? Could you expand on this please Colin?

Have a look at the docs on writing functions, in particular the section on storing data (but read all the rest if you have not already done so). The current date/time is available using something like
let now = new Date()
You can use different values of topic to distinguish between kettle operations and the input from the inject node.

1 Like

Thanks Colin. That's my Christmas project sorted. Need some strong coffee and quiet time.

1 Like

Different way of thinking.

  • At 6AM set a flag to warning (perhaps an mqtt topic called node-red/flag)
  • Any time the kettle is used the set the flag to normal
  • Check flag at 8AM if the flag is not normal set it to anomaly
  • Another flow can monitor flag (subscribe to node-red/flag). Perhaps a notification is set (email, tweet, txt, traffic light that follows the flag ...)

I use MQTT to allow multiple applications to use the information without interfering with each other.

Or....
At 6 fire a trigger node to send nothing right away, and its second output 2 hours later (8am). If the kettle is detected send a msg.reset to it to clear the waiting warning.

1 Like