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
}
- Account-scoped. Connectors are available to every space of that account.
- The credential is write-only.
GET /api/connectorsreturnshasToken, never the value. authandauthNameare returned; they are configuration, not secrets.kindis informational today (gree,homeassistantorhttp); the proxy behaviour is the- same.
- The URL is the bridge/service root. The widget supplies a relative path.
Credentials
A connector authenticates in one of five ways, chosen when it is added:
auth | Sends | Fields |
|---|---|---|
bearer (default) | Authorization: Bearer <token> | token |
header | <authName>: <token> | header name + value |
basic | Authorization: Basic base64(user:password) | username + password |
query | ?<authName>=<token>, URL-encoded | parameter name + value |
oauth | Authorization: Bearer <access token>, refreshed automatically | provider |
none | nothing | — |
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:
- key from
Bento:SecretKey(base64, 32 bytes) when configured - otherwise a
0600key is generated atApp_Data/private/master.keyand a warning is logged - the master key must be backed up separately and kept out of archives
- files live under
App_Data/private/secrets/{userId}/ - losing the key means re-entering the tokens
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" }
}
}
}
BaseUrlis the API origin, not a subpath. Connector paths are absolute, like everywhere else- (
/gmail/v1/users/me/...). - The connectors dialog lists every configured provider. Connect leaves for the provider and the
- callback lands back on
/api/connectors/oauth/callback. - State is random, single use and expires in ten minutes; PKCE
S256is used even where providers - ignore it. The state record binds the callback to the account, so no cookie is needed on the way
- back.
- The code exchange and every refresh run server-side, so the client secret never reaches the
- browser. Access and refresh tokens are two separate AES-GCM entries; the connector stores only the
- expiry and scope.
- The proxy refreshes when the access token is within 60 s of expiring. A failed refresh answers
502 oauth_reconnect, so the card can say “Reconnect” instead of failing silently.- The redirect URI is derived from the request (
{origin}/api/connectors/oauth/callback) because it - must match what the provider registered; set
OAuth:RedirectBasebehind a proxy.
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:
- looks up the connector for the signed-in account
- allows only
GETandPOST - accepts only a relative path that stays on the connector origin
- adds the connector's credential — bearer, a custom header, basic auth or a query parameter —
- when one is stored
- sends no cookies, follows no redirects, times out after 8 s, caps the response at 256 KB
- parses JSON (
application/jsonor+json) and otherwise returns text - refuses link-local/metadata addresses even when private networks are allowed
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.
GET /api/connectors/healthreads the cache and never touches the bridgePOST /api/connectors/healthchecks all connectors in parallel and returns fresh rows- a manual Test on the standard path updates the same row; a Home Assistant connector is
- checked against
/api/ GET /api/connectorsincludes each connector's cachedhealth- deleting a connector prunes its row; the cache is capped and labelled “Online · 2 min ago”
- the dialog refreshes rows older than
ttlSeconds(five minutes) once per open, so a - read-only account or an offline bridge just keeps the last reading
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
- the bridge has its own bearer token (
BRIDGE_API_TOKEN) - each child has an internal token; child ports are not published
- a child failure marks that device unavailable, not the whole bridge
devices.jsonis mounted read-only; the bridge does not discover or rewrite it- the Bento Spaces connector stays one URL + one token
- the widget lists
/api/devicesand stores{ connectorId, deviceId }
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" }
}
- The bridge starts the command on boot, waits up to 30 s for the child's
/api/health - (sending the device token) and then proxies to
urlexactly as before. - A child that exits is restarted with a 1 s backoff that doubles to 30 s; a command that cannot
- start is retried every 30 s and never takes the bridge down.
- On shutdown the bridge kills the whole process tree, so no orphan keeps a port.
commandis argv, never a shell string: arguments travel as a list, env keys must look like- shell names, and each value is a string — quote numbers (
"8501"). devices.jsonis trusted local config. It is mounted read-only and never fetched, which is why a- command in it is acceptable at all.
- The child binary must be inside the image; the bridge cannot install it. Extend the Dockerfile
- with a
COPY --from=from the child's image and pointcommandat it. devices.single.example.json+docker-compose.single.example.ymlare the template.
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:
docker-compose.yml— supervisor plus onegree-acchild per device; optionalcloudflaredservice for a Cloudflare Tunneldevices.json— one child URL/AC_*_TOKENplaceholder per device.env—BRIDGE_*/BENTO_*values, the pairing code and per-AC host/token placeholders
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:
- sizes
2x1,2x2,4x2 - reads
/api/connectorsand auto-binds when there is exactly one connector - shows a connector picker when there are several
- in edit mode its gear opens the connector list, so the wiring is configurable from the board
- calls
GET /api/statethrough the connector - lists
/api/devices; auto-binds one, shows a picker for several and storesdeviceId - falls back to
/api/statefor a legacy single-device bridge - shows power, target temperature and current temperature
- toggles through
POST /api/powerand refreshes the state - polls every 60 s; clears its timer on unmount
- shows “Private connector” in a shared/view session; connectors are account-only
- renders a private placeholder in the HTML export, never a live AC snapshot
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:
- set
entity(light.kitchen) and an optional title; the friendly name is the fallback - reads
GET /api/states/{entity}and shows the state plusunit_of_measurement - lights, switches, fans and input booleans get one toggle that posts
POST /api/services/homeassistant/toggle{ entity_id }and re-reads- scenes and scripts get a Run button (
scene.turn_on,script.turn_on); buttons get - Press (
button.press). Their state reads asReady,Running/IdleandPress - instead of Home Assistant's internal timestamp
- up to two useful attributes sit under the value: brightness as a percentage, colour
- temperature in kelvin, current/set temperature, battery and humidity
- auto-binds the only Home Assistant connector, offers a picker when there are several
- polls every 60 s, keeps the last state when a poll fails and disables the control
- the control is usable again as soon as the command returns, not on the next poll
- shared views and exports get “Private connector”
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:
pathdefaults to/api/state; oneGETthrough the connector proxy- fields are
Label = dotted.pathlines (readings.0.value,attributes.unit) - with no fields, it reads the first six primitive leaves of the response
- templates map fields for Home Assistant (
state,attributes.*), Gree AC and - Pi-hole; a custom field list always wins
- auto-binds the only connector, shows a picker when there are several, and polls every 60 s
- keeps its last reading on a failed poll and shows
offline - shared views, exports and signed-out sessions get “Private connector”
- values are escaped; an object renders as compact JSON, never as HTML
Setup
- Deploy the bridge (the generated compose stack) or run one
gree-acper AC. The reference - child is
georgevgs/gree-ac(MIT), one AC per process. On Docker Desktop for macOS publish 8481:8481and do not usenetwork_mode: host; on Linux host networking is more reliable- for discovery. With an explicit
AC_HOST, broadcast discovery is not needed. - 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.
- Test the connection.
- Add a Gree AC widget to a container.
- 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.