IOT Core rules to map timestamp to timestream


I'm trying out IoT core. I have data going into a topic, and a rule is being triggered to write that data to timescale. The input data is JSON and it contains a field 'timestamp' at the top level, it's a standard ISO8660 string.

The part I'm having trouble with is understanding how to set up the Rule to tell timestream to get the time from a property of my json rather than the default ${timestamp()}. Since my data is an ISO8660 string I know I need to parse it, so I can

   fields.rms0 as rms0,
   fields.rms1 as rms2,
   parse_time(timestamp) as ts

but adding it as 'ts' doesn't do what I want. What do I put in the rule box, ${ts} is my first guess, but I don't want ts to also end up as a metric, and I'm not sure how to prevent that.

For reference, my input format is this:

   measurement: "something",
   timestamp: "2022-01-01T00:00:00Z",
   fields: {
        "rms0": 1.23456,
       /* more fields */
   tags: {
       /* some other stuff */
profile picture
asked 2 years ago763 views
1 Answer
Accepted Answer

Hi. You should use the time_to_epoch() function in the Timestamp value of the Rule Action. In your case:


Please see the discussion of time_to_epoch() here:

I don't want ts to also end up as a metric, and I'm not sure how to prevent that.

Please change your rule query statement to:

SELECT fields.rms0 as rms0, fields.rms1 as rms1 FROM 'foo/bar'
profile pictureAWS
answered 2 years ago
  • So you are saying it will pull the attribute named 'timestamp' out of my JSON even though it's not part of the SELECT?

  • I am indeed saying that. And I tested it before saying that. :-)

  • Thank you very much. It works great!!!

  • Thankyou for posting this, but what do I put as the Timestamp unit ?

  • time_to_epoch() returns the epoch time in milliseconds.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions