Timestamp on sensor readings

I have a bunch of mqtt sensors where the data arrives with quite a lag, but the mqtt message contains an accurate timestamp. Is there a way to have this timestamp used rather than the time the message arrived?

5 Likes

It depends on how you are using it.

Your post is pretty vague on what you mean by “used”.

Sorry, the mqtt packet contains a json object, such as this:

{"time_local":"2020-06-07T09:10:00+10:00","air_temperature":"3.2"}

This packet arrived at 9:14 so when it gets used in a graph the data point has that time (not the correct one from the data). Hope that make it a bit clearer.

I am not aware of any way that a graph card can modify it’s displayed time based on any data from a sensor. The graphs only use the time sequence based on when the data is entered into the db not the timestamp of the data itself.

At least as far as I know.

Thanks for that. I would actually prefer the timestamp in the message be used as the time_fired for the event in the database, rather than just inserting the current time. Imagine if you had a device that couldn’t connect for some reason and when it reconnected it sent through all its internally logged data. This would all get stored as occurring at the same point in time, not the actual time of the readings that is in the messages. I was hoping that the mqtt sensor could be configured to extract the timestamp from the message and use that to store in the event (something like a timestamp_template config item), but that doesn’t seem to exist.

2 Likes

That would be very useful for me as well. A similar thread also briefly discusses this, but no solution yet:

Any solution on this? I face the same issue.

I ended up using node-red to insert it into InfluxDB and using Grafana to do the graphing.

I ended up using node-red to insert it into InfluxDB and using Grafana to do the graphing.

Thanks for the update – I was wondering about that approach too!

Would you mind offering some details? For instance, did you create a separate database (and does that play well with Grafana)?