How can I get current time and compare it with last received time

I’d like to write a workflow that get current time and compare it with the last received time. If it’s more that 5 minutes, I will change the state of an attribute. Any suggestion? Thanks in advance.

I attached an example that uses a timer to accomplish this. You should be able to use this as a starting point. Check out the docs on how to import the workflow.

This workflow is triggered every minute. It then uses the Gauge Query node to get the most recent reported state, which includes the time it was reported. A conditional node is then used to check the current time, which is always put on the payload by the trigger, to the time on the gauge query result. If it’s more than 5 minutes, it takes the true path where you can update the device attribute.

The conditional node expression looks like this:

{{ time }} - {{ data.lastPoint.time }} > 5 * 60 * 1000

The time variable is put on the payload by the timer trigger. data.lastPoint.time is from the gauge query result. When you do math on date objects, they are automatically converted to milliseconds. We can then compare that result to 5 minutes in milliseconds: 5 * 60 * 1000.

example.flow (1.6 KB)