Bento Spaces docs

Bento Spaces documentation

Connectors

Status: account connectors, encrypted tokens, the connector proxy, the Gree AC, HTTP card and Home Assistant widgets, the multi-device Bento Bridge, the setup wizard, one-time pairing, generated deploy files, OAuth and a one-container bridge are built.

A connector is a base URL plus an optional bearer token, configured once per account. Widgets never own the URL or the token; they reference a connector and a path.

Model

{
  "id": "c_…",
  "name": "Living AC",
  "url": "http://192.168.0.110:8481",
  "kind": "gree",
  "auth": "bearer",
  "authName": "",
  "hasToken": true
}

Credentials

A connector authenticates in one of five ways, chosen when it is added:

authSendsFields
bearer (default)Authorization: Bearer <token>token
header<authName>: <token>header name + value
basicAuthorization: Basic base64(user:password)username + password
query?<authName>=<token>, URL-encodedparameter name + value
oauthAuthorization: Bearer <access token>, refreshed automaticallyprovider
nonenothing—

authName is 1–40 letters, digits, - or _; a username may not contain :, and a credential may not contain a line break, because a header value is written verbatim. An unknown mode or a missing name is a 422.

Values are stored in the SecretStore, encrypted with AES-256-GCM:

There is no endpoint that returns a secret. Connector deletion removes its token.

OAuth

Some APIs only accept OAuth. A provider is configuration, not code:

"OAuth": {
  "Providers": {
    "google": {
      "ClientId": "…",
      "ClientSecret": "…",
      "AuthorizationUrl": "https://accounts.google.com/o/oauth2/v2/auth",
      "TokenUrl": "https://oauth2.googleapis.com/token",
      "BaseUrl": "https://gmail.googleapis.com",
      "Scopes": ["https://www.googleapis.com/auth/gmail.readonly"],
      "AuthorizationParams": { "access_type": "offline", "prompt": "consent" }
    }
  }
}

Google is the expensive provider. gmail.readonly is a restricted scope, and an External app in Testing mode issues a refresh token that dies after seven days. Publishing means verification and, for server-side storage, a security assessment. Spotify (non-restricted scopes) and the local mock exercise the same flow without any of that.

A worked example: Spotify

Its scopes are not restricted, so it is the cheapest real provider to try:

"spotify": {
  "ClientId": "…",
  "ClientSecret": "…",
  "AuthorizationUrl": "https://accounts.spotify.com/authorize",
  "TokenUrl": "https://accounts.spotify.com/api/token",
  "BaseUrl": "https://api.spotify.com",
  "Scopes": ["user-read-currently-playing"]
}

Register {origin}/api/connectors/oauth/callback as a redirect URI in the Spotify app, connect from Settings → Connectors, then install Now playing from the Examples registry. An OAuth connector's kind is the provider id, so the card can name it: "connectorKind": "spotify". The card itself is pure JSON:

"data": {
  "mode": "connector",
  "connectorKind": "spotify",
  "connector": "/v1/me/player/currently-playing",
  "path": "item.name"
}

Nothing playing answers 204, so the card reads — instead of breaking.

Proxy

POST /api/connectors/{id}/request
{ "method": "GET", "path": "/api/state" }

POST /api/connectors/{id}/request
{ "method": "POST", "path": "/api/power", "body": { "on": true } }

The server:

Connectors:AllowPrivate defaults to true, because a self-hosted Bento Spaces must reach a LAN bridge. A multi-user cloud deployment must set it to false, or expose only public/tunnel URLs.

POST /api/connectors/{id}/test calls /api/health by default (/api/ for a homeassistant connector); a body may supply another path.

Health

Every check calls /api/health through the same proxy (token, allowlist, 8 s timeout) and records { ok, status, error, latencyMs, checkedAt } under private/health/{userId}.json.

Multi-device Bento Bridge

The per-AC gree-ac bridge is still the protocol worker. The supervisor gives one public bridge for many ACs:

Bento connector  →  bento-bridge:8481
                       ├── ac-110:8481  (gree-ac child)
                       ├── ac-118:8481
                       └── …

source/Bento.Bridge/ is an ASP.NET supervisor. It loads devices.json, keeps one child URL/token per AC and exposes:

GET  /api/devices                 → { devices: [{ id, name }] }
GET  /api/devices/{id}/state
POST /api/devices/{id}/power      { "on": true }
POST /api/devices/{id}/request    { "method", "path", "body" }
GET  /api/health

Example stack: source/Bento.Bridge/docker-compose.example.yml. It ships one child per known unit (ac-110, ac-113, ac-118, ac-120, ac-121, ac-122). Copy devices.example.json to devices.json, copy .env.example to .env and give every child its own AC_*_TOKEN, build the gree-ac child image once (cd ~/Projects/gree-ac && docker compose up -d --build), then:

docker compose -f docker-compose.example.yml up -d --build

On Docker Desktop for macOS, keep the bridge port published (8481:8481); children stay on the compose network and do not publish ports. A single-device gree-ac still works: the widget falls back to /api/state.

One container

A device may carry a command instead of a URL somebody else started:

{
  "id": "living",
  "name": "Living AC",
  "url": "http://127.0.0.1:8501",
  "token": "child-token",
  "command": "/opt/child/start",
  "args": ["--port", "8501"],
  "env": { "AC_HOST": "192.168.0.110", "API_TOKEN": "child-token", "PORT": "8501" }
}

Devices without command keep working exactly as before, so a mixed stack is fine.

Pairing and generated deploy files

Copying a URL and token by hand is optional. Settings → Connectors → Pair a new bridge mints a one-time code (ABCD-EFGH, ten minutes, single use) bound to the signed-in account. Set it in the bridge's environment and the bridge registers itself:

BENTO_URL=http://bento-host:5080
BENTO_PAIRING_CODE=ABCD-EFGH
BRIDGE_PUBLIC_URL=http://bento-host:8481
BRIDGE_API_TOKEN=<long random string>

On startup the bridge posts { code, url, name, token, kind } to POST /api/connectors/pair. Bento Spaces stores the connector and the token, and the bridge logs Paired with Bento Spaces. A lost response is harmless: the code is spent, the connector still exists. If BRIDGE_API_TOKEN is empty the bridge generates one for that run and logs a warning to pin it in .env.

Show deploy files generates, from the devices the bridge reported:

Nothing is written to the Bento Spaces host; the text is copied into the user's bridge folder. The flow is covered by api-smoke and the connectors browser suite, and the bridge client was exercised end to end against a disposable server.

Gree AC widget

The built-in Gree AC widget:

The bridge state shape expected by the widget:

{
  "online": true,
  "power": true,
  "mode": "cool",
  "targetTemp": 24,
  "currentTemp": 25,
  "fanSpeed": "auto"
}

That is the shape exposed by the gree-ac / Ewpe local bridge and by the mock used in tests.

Home Assistant

Home Assistant's REST API fits the connector model: a base URL, a long-lived bearer token and JSON. Add a connector with kind Home Assistant; its health and Test use GET /api/ and the token is encrypted like any other.

The built-in Home Assistant widget (ha) shows one entity:

Sensors expose their state without a control. Anything beyond these attributes (full attribute trees, camera streams) is a good fit for the HTTP card's custom fields.

HTTP card widget

The built-in HTTP card turns any connector path into a few labelled values:

Setup

  1. Deploy the bridge (the generated compose stack) or run one gree-ac per AC. The reference
  2. child is georgevgs/gree-ac (MIT), one AC per process. On Docker Desktop for macOS publish
  3. 8481:8481 and do not use network_mode: host; on Linux host networking is more reliable
  4. for discovery. With an explicit AC_HOST, broadcast discovery is not needed.
  5. Settings → Connectors…:
    • Set up a Bento Bridge adds an existing bridge, checks health and lists devices, or
    • Pair a new bridge mints a code the bridge redeems at startup, or
    • use the plain connector form below.
  6. Test the connection.
  7. Add a Gree AC widget to a container.
  8. The widget auto-binds the only connector, or shows a picker.

For .110 the connector URL is http://192.168.0.110:8481 once the bridge is running. Do not expose the bridge on a raw public IP; use Tailscale/Cloudflare Tunnel for remote access.

Automations

Connector devices can be driven by climate rules: profiles, seasonal windows and weather brackets over the same proxy. See 16 — Automations.

Built so far

The bridge discovery wizard, one-time pairing and the generated compose/devices/.env files are built: Settings → Connectors → Set up a Bento Bridge adds and inspects an existing bridge, Pair a new bridge self-registers one, and Show deploy files emits the stack. The bridge also launches its own children, every credential mode and OAuth are supported, and declarative widgets can read and act through a connector.

Nothing in this scope is left on the backlog; see Open work for the current list.