| title | Complete sensor data processing |
|---|---|
| category | Example |
| version | 2.0.0 |
| last_updated | 2026-08-17 |
| description | Validated LoT for JSON sensors — action, model, rule, and optional OpenSearch |
Official docs: LoT introduction · Working with JSON · Alarms
A concrete line you can deploy. Raw JSON arrives on sensors/+/raw. The action extracts fields (1-based topic position), publishes a collapsed model, and raises an alarm when temperature is out of range. A rule locks alerts/#. An optional OpenSearch route indexes the validated JSON.
The previous version of this page used WHILE, JSON.stringify, 0-based TOPIC POSITION, and an OpenSearch ADD MAPPING / MQTT_CONFIG that the parser does not accept. Those constructs are gone.
DEFINE MODEL ValidatedSensor COLLAPSED
ADD STRING "sensor_id"
ADD DOUBLE "temperature"
ADD DOUBLE "pressure"
ADD STRING "quality"
ADD STRING "timestamp"
DEFINE ACTION ProcessSensorRaw
ON TOPIC "sensors/+/raw" DO
SET "sensor_id" WITH TOPIC POSITION 2
SET "temperature" WITH (GET JSON "temperature" IN PAYLOAD AS DOUBLE)
SET "pressure" WITH (GET JSON "pressure" IN PAYLOAD AS DOUBLE)
SET "quality" WITH "ok"
IF {temperature} < -50 OR {temperature} > 150 THEN
SET "quality" WITH "bad_temperature"
PUBLISH TOPIC "alerts/" + {sensor_id} + "/temperature" WITH {temperature}
PUBLISH MODEL ValidatedSensor TO "sensors/validated/" + {sensor_id} WITH
sensor_id = {sensor_id}
temperature = {temperature}
pressure = {pressure}
quality = {quality}
timestamp = TIMESTAMP "UTC"
For sensors/oven-7/raw, position 2 is oven-7.
DEFINE RULE AlertsPublish WITH PRIORITY 20 FOR Publish TO TOPIC "alerts/#"
IF USER HAS "AllowedSystemAlerts" OR USER IS "root" THEN
ALLOW
ELSE
DENY
DEFINE ROUTE SensorIndex WITH TYPE OPENSEARCH
ADD OPENSEARCH_CONFIG
WITH BASE_URL GET ENV "OPENSEARCH_URL"
WITH USERNAME GET ENV "OPENSEARCH_USER"
WITH PASSWORD GET SECRET "OPENSEARCH_PASSWORD"
WITH USE_SSL true
ADD EVENT IndexValidated
WITH SOURCE_TOPIC "sensors/validated/+"
WITH QUERY "CLEAN:{index: sensor-validated; body: {value.json}}"
Publish to sensors/oven-7/raw:
{"temperature": 25.5, "pressure": 101.3}Expect sensors/validated/oven-7 as one JSON object. Publish {"temperature": 200, "pressure": 101.3} and also expect alerts/oven-7/temperature.
Uploadable notebook-free copies: ProcessSensorRaw.lot, ValidatedSensor.lot
Related: Factory line with a PLC, Edge to cloud and database