# Know when a reading crosses the line.

> Get phone alerts from your IoT sensors. An ESP32, Raspberry Pi, or Home Assistant makes one HTTP POST to Pocket Alert when a threshold trips. No MQTT broker.

<!-- source: https://pocketalert.app/use-cases/iot-sensor-alerts -->

A temperature, humidity, water-leak, motion, door, power, or battery sensor crosses a threshold and the reading lands on your phone — from an ESP32, a Raspberry Pi, Home Assistant, or Node-RED. No broker and no MQTT bridge required.

## Three steps to sensor alerts

1. **Get a token or URL** — Create an API key, or copy an application webhook URL for a room or device.
2. **Fire on a threshold** — Add the POST to your Arduino HTTPClient sketch, MicroPython script, Pi cron, or HA rest_command.
3. **Read it on your phone** — Trip the sensor and your phone buzzes in under a second, in the application for that board.

## Push alerts from any sensor

You wired the sensor yourself. Give it one HTTP call and a threshold reaches your phone without a monitoring stack in the middle.

- **Fits a microcontroller** — A plain HTTP POST fits an ESP32 or ESP8266 with room left over. No broker, no bridge.
- **A channel per sensor** — One application per board lets a water-leak alert read loud while a battery notice stays calm.
- **Per-device channels** — One application per room or device keeps garage, fridge, and greenhouse in separate channels.
- **Map your own payload** — GJSON field mapping pulls the sensor name and value out of the JSON your firmware already sends.
- **Works with your setup** — Arduino, MicroPython, a Pi curl, a Home Assistant automation, or a Node-RED flow all reach the same endpoint.
- **Sub-second delivery** — A threshold trips and the push lands in under a second, before a leak spreads or a freezer thaws.

## Connect a sensor

### 1. Create an API key

Create a key on the [API Keys](https://pocketalert.app/account/apikeys) page. Your board sends it in the `Token` header on every POST to the messages API.

### 2. POST when a threshold trips

```
curl -X POST "https://api.pocketalert.app/v1/messages" \
  -H "Token: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"Freezer warm","message":"garage freezer at 4.2C","application_id":"qm47b9pzxzxg"}'
```

### 3. On an ESP32 or ESP8266 (Arduino)

```
#include <WiFiClientSecure.h>
#include <HTTPClient.h>

WiFiClientSecure client;
client.setInsecure(); // or client.setCACert(rootCA);

HTTPClient http;
http.begin(client, "https://api.pocketalert.app/v1/messages");
http.addHeader("Token", "YOUR_API_KEY");
http.addHeader("Content-Type", "application/json");
http.POST("{\"title\":\"Water leak\",\"level\":\"critical\",\"message\":\"basement sensor wet\"}");
http.end();
```

### 4. Or from Home Assistant

```
rest_command:
  pocketalert:
    url: "https://api.pocketalert.app/v1/messages"
    method: POST
    headers:
      Token: "YOUR_API_KEY"
    content_type: "application/json"
    payload: '{"title":"{{ title }}","message":"{{ message }}"}'
```

Call `rest_command.pocketalert` from an automation, or wire up an MQTT-to-REST flow in Node-RED. Read the [docs](https://info.pocketalert.app/getting-started.html) for the full message API.

## FAQ

### How do I send an alert from a sensor?

Your board makes one HTTP POST to the messages API when a reading crosses a threshold. On an ESP32 or ESP8266 that is a few lines of Arduino with HTTPClient or MicroPython; on a Raspberry Pi it is a curl. The payload carries a title and a message, with the API key in a Token header.

### Do I need MQTT or a broker?

A plain HTTPS call fits inside an ESP32 with memory to spare. No MQTT broker and no bridge container to babysit. Home Assistant rest_command and Node-RED still work if you already run them.

### Can urgent readings stand out from routine ones?

Give each board its own application so the freezer, the greenhouse, and the leak sensor land in separate channels. Word the title so a water leak reads loud at a glance, while a battery-low notice stays calm in its own app.

### How do I keep rooms and devices apart?

Make one application per room or device. The garage, the fridge, and the greenhouse each land in their own channel, so you read the alert without squinting at which board sent it.

### Can it read my existing sensor payload?

Point GJSON field mapping at the keys your firmware already sends. The sensor name and the reading slot straight into the title and message without reshaping the JSON on the board.

### Will a water leak alert get through Do Not Disturb at night?

Yes. Add "level":"critical" to the POST and Android delivers it on a dedicated notification channel that bypasses Do Not Disturb — you grant DND access once. On iPhone, high and critical arrive as time-sensitive notifications that break through Focus modes. Send a battery-low notice as level silent instead: no sound or vibration, it just sits in the history. On the free plan critical is delivered as high — still instant, without the DND override.
