# Smart home

Room temperature and humidity, with buttons for scenes. Droplet.ai can't control HomeKit itself: scene buttons run the user's Shortcuts, and event buttons reach your agent, which calls the user's smart-home API.

**Sizes:** small (temperature), medium and large (numbers and buttons)
**Interaction:** `url` buttons that run Shortcuts (work with no agent) and an event button answered by a listener

## Widget

```json
{
  "slug": "home",
  "title": "Home",
  "symbol": "house.fill",
  "accent": "#FF9F0A",
  "blocks": [
    { "type": "metric", "label": "Living room", "value": "22°C" },
    { "type": "metric", "label": "Humidity", "value": "48%" },
    { "type": "buttons", "items": [
      { "label": "TV", "symbol": "tv.fill", "url": "shortcuts://run-shortcut?name=Movie%20Time" },
      { "label": "Bed", "symbol": "bed.double.fill", "url": "shortcuts://run-shortcut?name=Bedtime" },
      { "label": "Away", "symbol": "lock.fill", "url": "shortcuts://run-shortcut?name=Leave%20Home" },
      { "label": "Fan", "id": "fan-toggle", "symbol": "fan.fill" }
    ] },
    { "type": "list", "items": ["Front door: locked", "Lights on: kitchen, hall", "Fan: off"] }
  ],
  "sizes": { "small": [0], "medium": [0, 1, 2], "large": [0, 1, 3, 2] },
  "lock": { "circular": 0, "inline": "Home 22°C" }
}
```

Medium: two numbers side by side (41 pt) above the pinned buttons (about 50 pt left there), so no `change` lines. The four buttons share the bottom row as equal tiles, so keep labels to one short word. Large adds what's on, so it isn't half empty.

## Shortcuts for scenes

The user makes one Shortcut per scene in the Shortcuts app (a "Control Home" action) with exactly the name in the URL. A tap opens Shortcuts and runs it. Tell them the names to use; until they exist, the tap shows an error in Shortcuts.

## Fan handler

```javascript
// home-handler.mjs, run by listen.mjs
import { readFileSync, writeFileSync, existsSync } from "node:fs";
const event = JSON.parse(readFileSync(0, "utf8"));
if (event.target !== "fan-toggle") process.exit(0);

const STATE = "/tmp/droplet-fan.json";
const on = !(existsSync(STATE) && JSON.parse(readFileSync(STATE, "utf8")).on);
await fetch("https://your-home-api.example.com/fan", { method: "POST", body: JSON.stringify({ on }) });
writeFileSync(STATE, JSON.stringify({ on }));

console.log(JSON.stringify({
  blocks: [
    { type: "metric", label: "Living room", value: "22°C" },
    { type: "metric", label: "Fan", value: on ? "On" : "Off" },
    { type: "buttons", items: [
      { label: "TV", symbol: "tv.fill", url: "shortcuts://run-shortcut?name=Movie%20Time" },
      { label: "Bed", symbol: "bed.double.fill", url: "shortcuts://run-shortcut?name=Bedtime" },
      { label: "Away", symbol: "lock.fill", url: "shortcuts://run-shortcut?name=Leave%20Home" },
      { label: on ? "Off" : "Fan", id: "fan-toggle", symbol: on ? "fan.slash" : "fan.fill" },
    ] },
    { type: "list", items: ["Front door: locked", "Lights on: kitchen, hall", `Fan: ${on ? "on" : "off"}`] },
  ],
}));
```

The reply changes a number ("Fan On") and the button's label, not only a colour, and keeps the button's `id` the same. It sends all four blocks in the same order, because sent `blocks` replace the whole list.
