Read an external JSON feed
Fetch synthetic weather data from a declared host, validate the response and show an unavailable state on failure.
Reviewed demonstration
Synthetic weather data
16°CThis is the expected result from the synthetic feed. The script is shown below and does not run on this page.
Prerequisites and limitations
The feed is synthetic and sends no Homey data. One request is made when the widget loads. Real services need their own host declaration, usage limits and error handling. Never put a private API key in a public widget. Unsupported browsers show the template fallback.
Complete source
Download package (.zip)The package uses the placeholder your-handle. Replace it with your Community handle before publishing.
tiledash.json
{ "id": "@your-handle/external-data", "title": "Read an external JSON feed", "summary": "A reviewed Tiledash script example.", "version": "1.0.0", "licence": "MIT", "tags": [], "kind": "widget", "widget": { "kind": "free", "match": { "requires": [], "optional": [] }, "size": { "default": [ 3, 4 ], "min": [ 2, 2 ], "max": [ 8, 12 ] }, "settings": [], "script": { "libraries": [], "connect": [ "developer.tiledash.app" ], "images": [], "actions": [], "context": [] } }}template.liquid
<p>Weather</p><p class="forecast" data-script>Forecast unavailable</p>style.css
:host { display: flex; flex-direction: column; gap: 12px; padding: 16px; }.forecast { font: var(--hd-number-weight) 32px var(--hd-font-display); }client.js
const label = tiledash.root.querySelector('.forecast');async function update() { try { const response = await fetch('https://developer.tiledash.app/demo/weather-v1.json', { credentials: 'omit', }); if (!response.ok) throw new Error('Feed unavailable'); const data = await response.json(); if (typeof data.temperature !== 'number' || !Number.isFinite(data.temperature)) { throw new Error('Invalid temperature'); } if (label) label.textContent = data.temperature + '°C'; } catch { if (label) label.textContent = 'Forecast unavailable'; }}update();How it works
The host is declared in connect. The request omits credentials, checks the HTTP result and validates the temperature before updating the widget’s root. Failure leaves an explicit unavailable message.
Script lifecycle and browser support · Permissions · API reference