> For the complete documentation index, see [llms.txt](https://docs.irs.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.irs.systems/iot/device-onboarding/shelly-3em-pro.md).

# Shelly 3EM Pro

### Onboard via Shelly Web UI

1. Open the device in the Shelly Web UI.
2. Go to **Scripts**.
3. Click **Add script**.
4. Paste the onboarding script.
5. Set `INGEST_INTERVAL_MS` and `API_KEY`.
6. Save the script.
7. Start the script.
8. Check the logs for a successful request.

```javascript

let INGEST_URL = "https://api.irs.systems/functions/v1/iot-ingest-telemetry";
let API_KEY = "dk_3230af..";
let INGEST_INTERVAL_MS = 600000;  // 10 minutes

Timer.set(INGEST_INTERVAL_MS, true, function () {
    Shelly.call("EM.GetStatus", { id: 0 }, function (emResult, emError) {
        if (emError) {
            print("Error reading EM:", emError);
            return;
        }

        Shelly.call("EMData.GetStatus", { id: 0 }, function (edResult, edError) {
            if (edError) {
                print("Error reading EMData:", edError);
                return;
            }

            let payload = {
                timestamp: new Date().toISOString(),
                total_power: emResult.total_act_power,
                total_energy: edResult.total_act,
                device_mac: Shelly.getDeviceInfo().mac,
            };

            Shelly.call(
                "HTTP.Request",
                {
                    method: "POST",
                    url: INGEST_URL,
                    headers: {
                        "Content-Type": "application/json",
                        "x-api-key": API_KEY,
                    },
                    body: JSON.stringify(payload),
                },
                function (res, err) {
                    if (err) {
                        print("HTTP Error:", err);
                    } else {
                        print("Sent to Supabase:", res.code);
                    }
                }
            );
        });
    });
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.irs.systems/iot/device-onboarding/shelly-3em-pro.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
