# What your firmware needs for Alexa control

Your firmware needs a **Warblet control client** and code that **sets and reads the output**. The Alexa skill runs through Warblet; it is not part of your firmware. Your device uses its existing Warblet credentials and needs no Amazon SDK, Amazon credentials, or direct connection to Amazon.

## 1. Maintain a control connection

The client repeatedly sends HTTPS requests to:

```text
POST https://https.warbletiot.com/ingest/{hwId}/control
```

Use the device’s hardware ID and its current security settings. Token and Signed modes require the corresponding device credentials. HTTP is also supported when TLS enforcement is off, but exposes messages and tokens and permits responses to be changed in transit.

This is a dedicated control exchange. Ordinary MQTT messages, sensor reporting, and generic downlink handling do not implement it.

The first `session-v1` exchange returns a session, configuration revision, and supported control definition, but no commands. Subsequent exchanges send the current `power` state and any pending command results, and receive at most one command with an explicit **ON** or **OFF** target.

Run these exchanges in a responsive background loop, separate from a slower sensor-reporting schedule. The supplied client handles the required timing, session validation, and command checks.

## 2. Apply the target and confirm the result

Your hardware code must set the requested state, then read what was actually applied. **ON** means “set on,” not “toggle”; receiving **ON** twice must leave the output on.

Pin readback confirms the pin state. Use hardware feedback if you need to confirm the load’s state.

The control client validates the command’s identity, session, revision, and deadline before your code acts. Keep its checks and duplicate protection when adapting the example.

**Conceptual flow — not runnable SDK code:**

```text
exchange current state and pending results with Warblet
if a command passes the control client's validation:
    set the output to the requested ON or OFF state
    read the actual output state
    queue the result for that command, including observed state
send the queued result in the next exchange
```

Receiving a command is not success. Report a successful result only when the observed state matches the target. Report local button changes too, so Warblet sees the current state.

## 3. Use one on/off control

**Set up Alexa** sets up the device’s on/off control. That control also appears on the dashboard and device page, with no extra spec edit or firmware confirmation. Dashboard actions and routine `power()` calls use the same control.

All three use the same command format: an explicit **ON** or **OFF** target, followed by the device’s result and observed state. Sending ordinary on/off text and decoding a field named `power` does not provide this exchange. Ordinary command controls, routine `send()` calls, and sensor reporting remain available.

Start with the [complete MicroPython control example](/alexa-on-off-micropython) and adapt its hardware set/read code. It includes the protocol handling.

Once compatible firmware is running, allow Alexa control on the device page. If Alexa setup is available on your account, link Warblet in Alexa, discover the output, and test both on and off.

<details>
<summary>Use on/off control without Alexa</summary>

An existing on/off control appears automatically on the dashboard and device page. No spec edit or Alexa account linking is needed.

To create a new on/off control, add a switch in your spec’s **Dashboard controls** and choose **On/off control**. Save it, then enable the control on the device page and confirm that its firmware supports Warblet on/off control. The example’s control ID is `power`.

</details>
