Timestamp variable type

Request for a new variable type: “timestamp”.

I see reference to an experimental variable - $context.event.timestamp - but I don’t think that addresses my use case.

I have a rule that captures the daily minimum value of a particular device’s parameter into a number type variable. I later report (via notification) the min for the day. I would like to also capture/report the time at which that minimum occurs. In my case the evaluation resets each day, so only a timestamp type of variable is needed - but I could see similar cases where capturing the full date might be useful too.

Hi @GeorgeH - thanks for the feedback.

As you alluded to, you can accomplish this by using the experimental $context.event.timestamp or by snapshotting your own timestamp when the event is received eg. now()

In your example, anytime you snapshot the value which you determine is the minimum, you could also snapshot the $context.event.timestamp – then whenever you want to use the timestamp in a notification, you could wrap it in a call to formatDate() to parse and display it as you like.

The screenshot above shows the key concepts of how to snapshot an event value and the timestamp of the event, then using formatDate($minimumValueTimestamp, "LT") to parse and format the timestamp back into a local time-only timestamp.

Of course you would layer that into your existing logic where you are determining the minimum value for the day and resetting things accordingly.

So defining (in your example) the variable “$miniumValue” as the type “number” is all that is needed? Guess I wrongly assumed a date/time type for the variable would be needed.

You would define two variables.

  • $minimumValue (Number)
  • $minimumValueTimestamp (Text)

In my example, I was just simulating what the actions would look like so you could see them in a sample screenshot, but I’m actually using a switch as the trigger so my $minimumValue is a Text type as I was just mocking up the generic concept of storing an event value in a variable.

Just to reiterate: this was just to show the concept around storing the value+timestamp and how you could format the timestamp… it doesn’t include any of your actual logic around determining the minimum value as I assumed you already had that logic in place and it was outside the scope of this particular request (timestamps).

Of course if you are using numeric values (like temperature), you could use the Number type as noted above.