# Shelly smoke alarm notifications on your phone

> Get a Highest-priority push notification when a Shelly Plus Smoke detector goes into alarm.

- Company: Shelly (https://www.justpush.io/recipes/shelly)
- Event: `smoke.alarm` (Smoke alarm)
- Tags: Smart home, Security
- Install: https://studio.justpush.io/recipes/shelly/smoke-alarm
- Web page: https://www.justpush.io/recipes/shelly/smoke-alarm

## Setup

1. Click Install in Studio and sign in. The recipe is added to your account and you get a personal webhook URL.
2. Open your Shelly device's web interface (browse to its IP address) or the Shelly Smart Control app and go to Actions.
3. Add a webhook action for the Smoke alarm event.
4. Use the URL from the setup notes below. Shelly fills in the ${…} parts itself when it calls it.
5. Save, then trigger the device once to send a real event.
6. Use this as the action URL:
7. ```
8. your webhook URL (shown in Studio after install)?event=smoke.alarm&device=${config.sys.device.name}
9. ```

## Code

Studio calls `handleRequest(request)` with the incoming webhook (`{ method, headers, body, query, raw }`) and sends the message object it returns. Returning `null` sends nothing.

```js
// Shelly → smoke alarm
// Fires when a Shelly Plus Smoke detector goes into alarm.
//
// Add a webhook action for the "smoke.alarm" event on the device, calling:
//   <integration URL>?event=smoke.alarm&device=${config.sys.device.name}

// Shelly webhooks are GET requests, so the data arrives as query parameters.
// Fall back to a JSON body so the recipe also works when POSTed (and in the Test runner).
function readParams(request) {
    const body = request.body && typeof request.body === "object" ? request.body : {}
    return { ...body, ...(request.query || {}) }
}

// Shelly fills an unset name in as "null"; treat that (and blanks) as missing.
function text(value) {
    const s = value == null ? "" : String(value).trim()
    return s === "" || s === "null" || s === "undefined" ? null : s
}

function handleRequest(request) {
    const params = readParams(request)

    // Guard: only handle smoke alarms, so other Shelly hooks on this integration stay quiet.
    if (params.event !== "smoke.alarm") {
        console.log(`Ignoring Shelly event "${params.event ?? "unknown"}" — not a smoke alarm`)
        return null
    }

    const device = text(params.device) ?? "Your Shelly smoke detector"

    return {
        title: "🔥 Smoke alarm",
        message: `${device} is sounding`,
        topic: "Shelly",
        priority: 2, // Highest — a life-safety alarm is going off
        // sound: "siren", // any of Studio's sounds, e.g. incoming, bugle, siren
    }
}
```

## Shelly smoke.alarm webhook payload (sample)

```json
{
  "event": "smoke.alarm",
  "device": "Hallway"
}
```

## FAQ

### Does this work on iPhone and Android?

Yes. Install the JustPush app from the App Store or Google Play and sign in. Every phone signed in to your account gets the notification.

### Do I need to write code?

No. Install the recipe in Studio, paste your webhook URL into Shelly and you are done. The code is there if you want to change the text, the sound or the buttons.

### Can I change what the notification says?

Yes. After install the recipe's code is yours. Edit it in Studio and test it against the sample payload before you save.

### What does it cost?

JustPush is free for 30 days. After that it's $19.99 a year, or $39.99 once. There is no extra charge for recipes.
