> ## Documentation Index
> Fetch the complete documentation index at: https://docs.assetinfinity.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Record meter readings

> Send meter and sensor readings in from another system, so usage-based maintenance falls due and alerts open on their own.

A meter counts something an asset does: running hours, kilometres, cycles. A sensor measures a condition,
such as vibration or temperature. Sending readings in from a building management system, a SCADA
historian or a telematics feed is how usage-based maintenance plans fall due without anybody typing a
number. The examples assume a token in `$TOKEN` ([Authentication](/api-reference/authentication)).

## Find the meter

Meters have codes, so filter by the one your system knows:

```bash theme={null}
curl "https://app.assetinfinity.ai/api/asset_meters?select=meter_id,code,name,current_reading,unit_of_measure&code=eq.P-102-HRS" \
  -H "Authorization: Bearer $TOKEN"
```

```json theme={null}
[{ "meter_id": "a5e81b84-aeee-49fd-820f-009ed959c89a", "code": "P-102-HRS", "name": "P-102 Running Hours",
   "current_reading": 7840.000000, "unit_of_measure": "HR" }]
```

Look the id up once and keep it. It does not change.

## Send a reading

```bash theme={null}
curl -X POST https://app.assetinfinity.ai/api/rpc/record_meter_reading \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"p_meter_id": "a5e81b84-aeee-49fd-820f-009ed959c89a", "p_reading": 7864}'
```

The answer is the meter as it now stands, with the rate the asset is running at:

```json theme={null}
{ "meter_id": "a5e81b84-aeee-49fd-820f-009ed959c89a", "current_reading": 7864.000000,
  "previous_reading": 7840.000000, "units_per_day": 140.9917, "reading_count": 14 }
```

The reading brings the meter forward, and any maintenance plan whose usage has fallen due raises its
work order straight away.

Send the time the reading was taken as `p_reading_at`, if it was not taken just now. A reading dated
earlier than the latest is kept in the history but does not move the meter back, so sending a backlog
in any order is safe.

## Readings that are refused

A meter that counts upwards cannot go down:

```json theme={null}
{ "message": "That reading is lower than the current one",
  "details": "{\"error_code\": \"READING_WENT_BACKWARDS\"}",
  "hint": "A meter that counts upwards cannot go down. Correct the reading, or set the meter's rollover value if the dial wraps." }
```

A counter that wraps back to zero is accepted once the meter has a rollover value. If the counter on
the asset was physically replaced, the asset gets a new meter and the old one is switched off, as
[Meters](/assets/meters#cumulative-meters-rollovers-and-replacements) describes. Send readings to the
new meter from then on.

## Read the history

```bash theme={null}
curl "https://app.assetinfinity.ai/api/meter_readings?select=reading,reading_at&meter_id=eq.a5e81b84-aeee-49fd-820f-009ed959c89a&order=reading_at.desc&limit=3" \
  -H "Authorization: Bearer $TOKEN"
```

## Sensor readings

Find the sensor's id from `/sensors?select=id,code,name&code=eq.<code>`, then send each value:

```bash theme={null}
curl -X POST https://app.assetinfinity.ai/api/rpc/record_sensor_reading \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"p_sensor_id": "63042f06-a5e7-4a83-8a5f-412b7b2d6407", "p_value": 4.2}'
```

The answer says what the reading set off: alerts opened or cleared against the sensor's thresholds,
and whether it also moved a meter.

```json theme={null}
{ "stored": true, "reading_id": "31d0e017-3084-4363-aaf5-c12467618c83", "synced_to_meter": true,
  "alerts": [{ "action": "cleared", "alert_id": "35365c0b-697e-4823-a82c-09fb88431557", "threshold": "Drive-end vibration above 7 mm/s" }] }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.