Sensors
A sensor is anything that raises alerts and checks in: a motion sensor, a door contact, a camera, a radar. One that goes quiet is treated as an event, because a cut or jammed sensor is a warning in itself.
The sensor object
Ochio keeps one record per sensor. It works out the zone from the location, and the status from the check-ins.
Attributes., _ and -, up to 64 characters.motion, door, camera, radar.{"lat", "lon"}.null outside the operating area.ok or degraded.true for the sandbox's simulated sensors.api, site (part of the site's setup) or replay.{
"id": "east-gate-pir-02",
"name": "East gate motion sensor 2",
"type": "motion",
"location": {
"lat": 38.5005,
"lon": -97.995
},
"zone_id": "east-gate",
"checkin_interval_s": 10.0,
"missed_checkins_allowed": 2,
"status": "online",
"last_seen": "2026-10-19T21:33:03.876Z",
"expires_at": "2026-10-19T21:33:23.876Z",
"battery_pct": 87.0,
"reported_status": "ok",
"simulated": false,
"origin": "api",
"created_at": "2026-10-19T21:33:02.764Z",
"updated_at": "2026-10-19T21:33:03.876Z"
}Check-ins and statuses
A sensor proves it's alive by checking in every checkin_interval_s seconds. Any alert it sends counts too. Each check-in moves expires_at to now plus checkin_interval_s × missed_checkins_allowed. With the defaults, 10 seconds and 2, a sensor turns silent 20 seconds after Ochio last heard from it.
| Status | Means | Event when it starts |
|---|---|---|
pending | Registered, but hasn't checked in yet. Not watched until it does. | sensor.registered |
online | Checking in on time. | sensor.online the first time, sensor.recovered after a silence |
silent | Missed its check-ins. A rule can send a drone to it. | sensor.silent |
A silent sensor stays silent until it checks in again. Mission Control and your systems hear about each change through events.
{
"id": "generator-yard-door-01",
"name": "Generator yard door",
"type": "door",
"location": {
"lat": 38.4979,
"lon": -98.0047
},
"zone_id": "generator-yard",
"checkin_interval_s": 10.0,
"missed_checkins_allowed": 2,
"status": "silent",
"last_seen": "2026-10-19T21:39:43.634Z",
"expires_at": "2026-10-19T21:40:03.634Z",
"battery_pct": null,
"reported_status": null,
"simulated": true,
"origin": "site",
"created_at": "2026-10-19T21:30:10.072Z",
"updated_at": "2026-10-19T21:40:03.755Z"
}Register a sensor
Adds a sensor and gives it its secret. The answer is the only time Ochio shows the secret: give it to the sensor, which signs its requests with it.
Body., _ and -, up to 64 characters, starting with a letter or digit.motion.201 with the sensor and its secret. The sensor starts pending, and a sensor.registered event goes out.
| Status | Code | When |
|---|---|---|
409 | sensor_exists | A sensor with this id exists. To give it a new secret, rotate it instead. |
400 | invalid_request | A field is missing or out of range. |
curl -X POST "$OCHIO_URL/v1/sensors" \
-H "Authorization: Bearer $OCHIO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"id": "east-gate-pir-02",
"name": "East gate motion sensor 2",
"type": "motion",
"location": {
"lat": 38.5005,
"lon": -97.995
},
"checkin_interval_s": 10,
"missed_checkins_allowed": 2
}'import os
import requests
r = requests.post(
f"{os.environ['OCHIO_URL']}/v1/sensors",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
json={
"id": "east-gate-pir-02",
"name": "East gate motion sensor 2",
"type": "motion",
"location": {
"lat": 38.5005,
"lon": -97.995
},
"checkin_interval_s": 10,
"missed_checkins_allowed": 2
},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors`, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OCHIO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
id: "east-gate-pir-02",
name: "East gate motion sensor 2",
type: "motion",
location: {
lat: 38.5005,
lon: -97.995
},
checkin_interval_s: 10,
missed_checkins_allowed: 2
}),
});
console.log(res.status, await res.json());{
"id": "east-gate-pir-02",
"name": "East gate motion sensor 2",
"type": "motion",
"location": {
"lat": 38.5005,
"lon": -97.995
},
"zone_id": "east-gate",
"checkin_interval_s": 10.0,
"missed_checkins_allowed": 2,
"status": "pending",
"last_seen": null,
"expires_at": null,
"battery_pct": null,
"reported_status": null,
"simulated": false,
"origin": "api",
"created_at": "2026-10-19T21:33:02.764Z",
"updated_at": "2026-10-19T21:33:02.764Z",
"secret": "ssk_test_example_secret_000000000001"
}{
"error": {
"code": "sensor_exists",
"message": "A sensor with id 'east-gate-pir-02' already exists. POST /v1/sensors/east-gate-pir-02/rotate-secret issues a new secret."
}
}Check in
The sensor's regular sign of life, signed with its secret. Send it every checkin_interval_s seconds. An alert from the sensor counts as a check-in too.
v1= and the hex HMAC-SHA256 of the timestamp, a dot and the raw body, keyed with the sensor's secret. See Signing sensor requests.The body is optional. Send {} or nothing if the sensor has nothing to report.
ok, degraded.200 with the sensor's status, next_checkin_by (when the next one is due) and expires_at (when it turns silent without one). A repeat of a request Ochio already counted answers "repeat": true and doesn't count again.
| Status | Code | When |
|---|---|---|
401 | invalid_signature | The signature doesn't match. See Signing. |
404 | unknown_sensor | A signed check-in for a sensor that isn't registered. |
404 | not_found | The same, sent with an API key. |
BODY='{"battery_pct":87,"status":"ok"}'
TS=$(date +%s)
SIG=$(printf '%s.%s' "$TS" "$BODY" | openssl dgst -sha256 -hmac "$SENSOR_SECRET" | awk '{print $NF}')
curl -X POST "$OCHIO_URL/v1/sensors/east-gate-pir-02/heartbeat" \
-H "Content-Type: application/json" \
-H "Ochio-Timestamp: $TS" \
-H "Ochio-Signature: v1=$SIG" \
-d "$BODY"import hashlib, hmac, json, os, time
import requests
secret = os.environ["SENSOR_SECRET"]
body = json.dumps({
"battery_pct": 87,
"status": "ok"
}).encode()
ts = str(int(time.time()))
sig = hmac.new(secret.encode(), f"{ts}.".encode() + body, hashlib.sha256).hexdigest()
r = requests.post(f"{os.environ['OCHIO_URL']}/v1/sensors/east-gate-pir-02/heartbeat", data=body, headers={
"Content-Type": "application/json",
"Ochio-Timestamp": ts,
"Ochio-Signature": f"v1={sig}",
})
print(r.status_code, r.json())import crypto from "node:crypto";
const body = JSON.stringify({
battery_pct: 87,
status: "ok"
});
const ts = Math.floor(Date.now() / 1000).toString();
const sig = crypto.createHmac("sha256", process.env.SENSOR_SECRET).update(`${ts}.${body}`).digest("hex");
const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors/east-gate-pir-02/heartbeat`, {
method: "POST",
headers: { "Content-Type": "application/json", "Ochio-Timestamp": ts, "Ochio-Signature": `v1=${sig}` },
body,
});
console.log(res.status, await res.json());{
"sensor_id": "east-gate-pir-02",
"status": "online",
"next_checkin_by": "2026-10-19T21:33:12.770Z",
"expires_at": "2026-10-19T21:33:22.770Z"
}{
"sensor_id": "east-gate-pir-02",
"status": "online",
"next_checkin_by": "2026-10-19T21:33:12.770Z",
"expires_at": "2026-10-19T21:33:22.770Z",
"repeat": true
}List sensors
Every registered sensor, with its status.
Querypending, online or silent.{"data": [...]} with a sensor for each.
curl "$OCHIO_URL/v1/sensors?status=silent" \
-H "Authorization: Bearer $OCHIO_API_KEY"import os
import requests
r = requests.get(
f"{os.environ['OCHIO_URL']}/v1/sensors",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
params={
"status": "silent"
},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors?status=silent`, {
headers: { Authorization: `Bearer ${process.env.OCHIO_API_KEY}` },
});
console.log(res.status, await res.json());{
"data": [
{
"id": "generator-yard-door-01",
"name": "Generator yard door",
"type": "door",
"location": {
"lat": 38.4979,
"lon": -98.0047
},
"zone_id": "generator-yard",
"checkin_interval_s": 10.0,
"missed_checkins_allowed": 2,
"status": "silent",
"last_seen": "2026-10-19T21:39:43.634Z",
"expires_at": "2026-10-19T21:40:03.634Z",
"battery_pct": null,
"reported_status": null,
"simulated": true,
"origin": "site",
"created_at": "2026-10-19T21:30:10.072Z",
"updated_at": "2026-10-19T21:40:03.755Z"
}
]
}Get a sensor
One sensor, by id.
PathThe sensor.
Errors| Status | Code | When |
|---|---|---|
404 | not_found | No sensor with this id. |
curl "$OCHIO_URL/v1/sensors/east-gate-pir-02" \
-H "Authorization: Bearer $OCHIO_API_KEY"import os
import requests
r = requests.get(
f"{os.environ['OCHIO_URL']}/v1/sensors/east-gate-pir-02",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors/east-gate-pir-02`, {
headers: { Authorization: `Bearer ${process.env.OCHIO_API_KEY}` },
});
console.log(res.status, await res.json());{
"id": "east-gate-pir-02",
"name": "East gate motion sensor 2",
"type": "motion",
"location": {
"lat": 38.5005,
"lon": -97.995
},
"zone_id": "east-gate",
"checkin_interval_s": 10.0,
"missed_checkins_allowed": 2,
"status": "online",
"last_seen": "2026-10-19T21:33:03.876Z",
"expires_at": "2026-10-19T21:33:23.876Z",
"battery_pct": 87.0,
"reported_status": "ok",
"simulated": false,
"origin": "api",
"created_at": "2026-10-19T21:33:02.764Z",
"updated_at": "2026-10-19T21:33:03.876Z"
}Rotate a sensor's secret
Gives the sensor a new secret. The old one stops working at once, so update the sensor right after. Use it when a secret may have leaked, or when you replace the device.
Path200 with sensor_id and the new secret, shown once.
| Status | Code | When |
|---|---|---|
404 | not_found | No sensor with this id. |
curl -X POST "$OCHIO_URL/v1/sensors/east-gate-pir-02/rotate-secret" \
-H "Authorization: Bearer $OCHIO_API_KEY"import os
import requests
r = requests.post(
f"{os.environ['OCHIO_URL']}/v1/sensors/east-gate-pir-02/rotate-secret",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors/east-gate-pir-02/rotate-secret`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.OCHIO_API_KEY}` },
});
console.log(res.status, await res.json());{
"sensor_id": "east-gate-pir-02",
"secret": "ssk_test_example_secret_000000000002"
}Remove a sensor
Removes the sensor. Its alerts stay, and its secret stops working. A sensor.removed event goes out.
200 with {"id", "deleted": true}.
| Status | Code | When |
|---|---|---|
404 | not_found | No sensor with this id. |
curl -X DELETE "$OCHIO_URL/v1/sensors/east-gate-pir-02" \
-H "Authorization: Bearer $OCHIO_API_KEY"import os
import requests
r = requests.delete(
f"{os.environ['OCHIO_URL']}/v1/sensors/east-gate-pir-02",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/sensors/east-gate-pir-02`, {
method: "DELETE",
headers: { Authorization: `Bearer ${process.env.OCHIO_API_KEY}` },
});
console.log(res.status, await res.json());{
"id": "east-gate-pir-02",
"deleted": true
}