API Correct Timestamp Get Sensors API Call

I’m looking at using the Purple Air API call Get Sensors Data to pull sensor data.

The field last_seen states “The UNIX time stamp of the last time the server received data from the device.”

I’m assuming this is the time that corresponds with the measured data (ex pm1.0, pm2.5, etc.) correct? Every sensor returned shows a slightly different value which makes sense.

As this is just a number, if I convert in python datetime.fromtimestamp(last_seen) I get a time that is in the timezone of the computer I’m running the code on (it seems to be within a few minutes of when I ran the query to the API).

Is this timestamp in UTC, the time of the sensor, or some other time?

Should I be using last_seen for this, or something else?


The field last_seen returns most recent time that the sensor reported to the database. Sensors report every two minutes, so assuming the sensor is actively reporting, the timestamp you’ll get will be less than two minutes old. That’s why you’re seeing that the time returned is within a few minutes of querying.

This will return in your time. If you’re looking to retrieve the time in UTC, you can use datetime.utcfromtimestamp().