Build a connection

Updated 16 November 2026

A connection gives widgets data from a device or service: a hub, a media server, a meter or a service on the internet. tvbliz knows none of them in advance. Anyone can build one in the app store, try it in their own home and publish it.

How it fits together

  • The manifest. Where the device is, how to sign in, and the kinds of things it has.
  • The adapter. A small script the home’s TVs run. It talks to the device and gives widgets its things.
  • The home. Whoever sets up a widget finds the device and signs in on tvbliz.com. The sign-in is kept encrypted and sent only to the home’s TVs.
  • Widgets. Data and top-bar widgets show its things without code; HTML widgets use tvbliz.connection(id).

Build it under App store › Build your own › Connect to a device or service on the home network, or with the MCP tool create_widget and kind: "connection".

The manifest

{
  "logo": "<svg …>…</svg>",
  "color": "#1A9BDB",
  "homepage": "https://example.com",
  "find": [
    {"type": "mdns", "service": "_example._tcp", "scheme": "http"},
    {"type": "scan", "scheme": "http", "port": 8080, "probe": "/api/info", "match": "Example"},
    {"type": "manual", "scheme": "http", "port": 8080, "hint": "192.168.1.20:8080"}
  ],
  "login": {"type": "token", "label": "API key", "help": "Settings › API on the device"},
  "groups": {"sensor": "Sensors", "light": "Lights"},
  "adapter": "(function () { … tvbliz.adapter({…}); })();"
}
  • logo, color, homepage. An SVG logo, a colour and an https address.
  • base or find. A fixed address, or how a TV finds it (below).
  • login. How a home signs in (below). Without a sign-in: {"type": "none"}.
  • groups. The groups its things belong to, with a name. The website uses them when people pick a value.
  • adapter. The script, at most 100 kB.

Finding it

A connection may have several ways. People can always type the address too.

  • scan. A TV tries every address on its network on port and keeps those whose probe page contains match.
  • mdns. A TV asks the network for the service type, e.g. _example._tcp (mDNS/DNS-SD). probe and match work here too.
  • manual. People type the address; hint is shown as an example, and port and scheme are filled in when missing.
  • base. A fixed https address, for a service on the internet. Nothing is found then.
{
  "base": "https://api.example.com",
  "login": {
    "type": "oauth-cloud",
    "authorizeUrl": "https://example.com/oauth/authorize",
    "tokenUrl": "https://example.com/oauth/token",
    "scopes": "read write",
    "clientId": "tvbliz"
  },
  "groups": {"sensor": "Sensors"},
  "adapter": "…"
}

Signing in

{"type": "none"}
{"type": "token", "label": "API key", "help": "…", "header": "Authorization", "prefix": "Bearer "}
{"type": "basic", "help": "…"}
{"type": "pairing", "prompt": "Press the link button on the bridge",
 "request": {"method": "POST", "path": "/api", "body": {"devicetype": "tvbliz"}},
 "tokenFrom": "0.success.username", "seconds": 60}
{"type": "oauth-local", "authorize": "/auth/authorize", "token": "/auth/token", "clientId": "site"}
{"type": "oauth-cloud", "authorizeUrl": "https://…", "tokenUrl": "https://…", "scopes": "…", "clientId": "…"}
  • none. The address is all.
  • token. People paste a key on tvbliz.com. label and help say where to find it. With auth: true, tvbliz.fetch() sends it as a header (by default Authorization: Bearer …).
  • basic. A username and password. With auth: true they are sent as Basic.
  • pairing. People press a button on the device. A TV sends request every two seconds until the answer has a value at tokenFrom, for at most seconds seconds. That value becomes the key.
  • oauth-local. People sign in on the device’s own page. The website’s address is the client id; a TV exchanges the code for a refresh token and fetches new access tokens itself.
  • oauth-cloud. People sign in with a provider on the internet. The redirect address is https://tvbliz.com/api/oauth/callback, and the client secret is stored with set_widget_secret or in the app store. tvbliz keeps and refreshes the tokens; the TV asks for a fresh one.

Keys, passwords and tokens are kept encrypted by tvbliz, never shown on the website again, and sent only to the home’s TVs, for this connection’s adapter.

The adapter

The adapter runs on every TV in a home that has connected it, in a hidden page whose address is the connection’s. So fetch, XHR and WebSocket to the device are on the page’s own address.

tvbliz.base                 // the address: "http://192.168.1.20:8080" or the manifest's base
tvbliz.login                // the login type: "none", "token", "basic", "pairing", "oauth-local", "oauth-cloud"
tvbliz.token()              // Promise<string>: the key (token, pairing) or a fresh access token (oauth-*)
tvbliz.credentials()        // Promise<{username, password}> (basic)
tvbliz.fetch(url, options)  // Promise<{status, ok, headers, body, json(), text()}>
                            //   url relative to base; options {method, headers, body, auth: true}
tvbliz.emit({id: state})    // new values; null removes an item
tvbliz.log(text)            // to the TV's log
tvbliz.adapter({start, items, read, call, history, query})

What the adapter gives

  • start(). Called when the page is ready. Connect, and send values with emit.
  • items(). Everything people can pick on the website: [{id, name, group, unit?, kind?, area?, value?}]. The TV sends the list to the website now and then.
  • read(ids). The latest values: {id: state}; all of them when ids is empty.
  • call(action, data). An action, e.g. "light.toggle". Widgets may only call actions in their permissions.services.
  • history(ids, hours). Numbers for the last hours: {id: [number, …]}.
  • query(name, args). Anything else, e.g. a weather forecast.

Each may answer with a value or a Promise. An answer takes at most a minute.

// a state
{"v": 21.5, "u": "°C", "n": "Living room", "a": {"device_class": "temperature"}}

// an item, from items()
{"id": "sensor.living", "name": "Living room", "group": "sensor", "unit": "°C", "kind": "temperature", "area": "Living room", "value": 21.5}

An example

(function () {
  var states = {};

  function poll() {
    tvbliz.fetch('/api/sensors', {auth: true})
      .then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); })
      .then(function (list) {
        var changed = {};
        list.forEach(function (s) {
          states[s.id] = {v: s.value, u: s.unit, n: s.name, a: {}};
          changed[s.id] = states[s.id];
        });
        tvbliz.emit(changed);
      })
      .catch(function (e) { tvbliz.log(e.message); });
  }

  tvbliz.adapter({
    start: function () { poll(); setInterval(poll, 30000); },
    items: function () {
      return Object.keys(states).map(function (id) {
        return {id: id, name: states[id].n, group: 'sensor', unit: states[id].u, value: states[id].v};
      });
    },
    read: function (ids) {
      var out = {};
      (ids && ids.length ? ids : Object.keys(states)).forEach(function (id) { if (states[id]) out[id] = states[id]; });
      return out;
    },
    call: function (action, data) {   // "light.toggle", {id: "light.hall"}
      return tvbliz.fetch('/api/' + action.replace('.', '/'), {method: 'POST', body: data, auth: true})
        .then(function (r) { return r.ok; });
    },
    history: function (ids, hours) { return {}; },
    query: function (name, args) { return Promise.reject(new Error('Unknown: ' + name)); },
  });
})();

Widgets

A widget names the connection in its manifest. Data and top-bar widgets show its things without code. An HTML widget gets it through tvbliz.connection:

// manifest of an HTML widget
{"connections": ["my-device"], "permissions": {"services": ["light.toggle"]}, "html": "…"}

// in the widget's page
var c = tvbliz.connection('my-device');
c.state('sensor.living');                      // {state, unit, name, attributes}
c.call('light.toggle', {id: 'light.hall'});    // only actions in permissions.services
c.history(['sensor.living'], 24);              // {id: [numbers]}
c.query('forecast', {id: 'weather.home'});
c.items();

Try it and publish

  • Private. A new connection can only be used in its author’s own homes. Try it there.
  • Published. Switch on «Share in the app store», and anyone can connect to it. TVs always get the latest version.
  • What the adapter may do. It sees only its own connection’s sign-in and none of tvbliz’s other data. It may be at most 100 kB.
  • Trust. Connections from authors tvbliz hasn’t verified get a note on their page and when signing in. Official connections are marked.

Questions: [email protected].