Build your first widget
You’ll make Room climate: a tile with a room’s temperature that opens its history when you tap it. Each step adds a little to the same widget, with a preview you can edit and a download of the widget as it is by then.
Before you start
You need some HTML and CSS. The previews on this page run on made-up readings, so you don’t need a Homey until the last step. Putting the widget on a dashboard needs a Tiledash account; Free is enough, publishing included.
A tile is a box on a dashboard. A widget is what draws it: the same widget can be on many tiles, each with its own device and settings. A widget is a few files:
tiledash.json- The manifest: its name, which devices it fits, and its settings.
template.liquid- HTML with Liquid in it, to put readings and settings on the tile.
style.css- How it looks. It only styles this widget, never the rest of the dashboard.
client.js- JavaScript, only if you need it. This tutorial doesn’t.
1. Show a reading
Room climate starts from Tiledash’s Climate widget, so a tile picks any device that measures temperature. The template reads that device as device, and its readings ascap, by capability: cap.measure_temperature. Itsvalue is the number as Homey reports it; the temp filter rounds it to one decimal and adds a degree sign, written the way the viewer’s region writes numbers.
<p class="name">{{ device.name }}</p><p class="reading">{{ cap.measure_temperature.value | temp: 1 }}</p>The style sets the number as large as the tile has room for. :host is the tile itself, and the --hd-… variables come from the dashboard’s theme, so the widget fits in light and dark themes alike.
:host { display: grid; align-content: center; gap: 4px; padding: 12px; container-type: size;}p { margin: 0;}.name { font: 600 13px var(--hd-font-ui); color: var(--hd-text-muted);}.reading { font: var(--hd-number-weight) clamp(24px, 40cqh, 56px) / 1 var(--hd-font-display); color: var(--hd-text);}<p class="name">{{ device.name }}</p><p class="reading">{{ cap.measure_temperature.value | temp: 1 }}</p>Try changing temp: 1 to temp: 0 in the preview’s template.
2. Add a setting and an action
Settings are what each tile chooses for itself. This one gets a label, for when the device’s name isn’t what you want on the tile. They’re listed in the manifest:
[ { "type": "text", "name": "label", "label": "Label", "required": false, "default": "" }]The template reads it as settings.label, and falls back to the device’s name when it’s empty. The number becomes a button: data-hd-on-click runs an action when it’s tapped, here openHistory for the last 24 hours. Actions are a small, fixed list, written in the template; you don’t need JavaScript for them. The humidity line only shows on a device that has humidity.
<p class="name">{{ settings.label | default: device.name }}</p><button class="reading" data-hd-on-click="openHistory('measure_temperature', '24h')"> {{ cap.measure_temperature.value | temp: 1 }}</button>{% if cap.measure_humidity %} <p class="extra">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }} humidity</p>{% endif %}/* A button that looks like the number it shows. */ justify-self: start; padding: 0; text-align: start; background: none; border: 0; cursor: pointer;}.extra { font-size: 13px; color: var(--hd-text-muted);}<p class="name">{{ settings.label | default: device.name }}</p><button class="reading" data-hd-on-click="openHistory('measure_temperature', '24h')"> {{ cap.measure_temperature.value | temp: 1 }}</button>{% if cap.measure_humidity %} <p class="extra">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }} humidity</p>{% endif %}Actions don’t run in these previews; on a dashboard, the tap opens the history.
3. Handle missing readings
A sensor can go offline, and a new one has no reading yet. Without a value the tile would show an empty space, so this step says what’s going on instead. Choose Away in the preview to see it.
Test for nil, never for a value being “there”: 0° and 0% humidity are real readings and must still show. device.available is false while Homey can’t reach the device.
{%- assign temperature = cap.measure_temperature.value -%}<p class="name">{{ settings.label | default: device.name }}</p>{% if device.available == false %} <p class="state">Unavailable</p>{% elsif temperature == nil %} <p class="state">No reading yet</p>{% else %} <button class="reading" data-hd-on-click="openHistory('measure_temperature', '24h')"> {{ temperature | temp: 1 }} </button> {% if cap.measure_humidity.value != nil %} <p class="extra">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }} humidity</p> {% endif %}{% endif %}.state { font: 600 17px var(--hd-font-ui); color: var(--hd-text-muted);}{%- assign temperature = cap.measure_temperature.value -%}<p class="name">{{ settings.label | default: device.name }}</p>{% if device.available == false %} <p class="state">Unavailable</p>{% elsif temperature == nil %} <p class="state">No reading yet</p>{% else %} <button class="reading" data-hd-on-click="openHistory('measure_temperature', '24h')"> {{ temperature | temp: 1 }} </button> {% if cap.measure_humidity.value != nil %} <p class="extra">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }} humidity</p> {% endif %}{% endif %}4. Check sizes, themes and the keyboard
People put tiles in all sizes and themes. The number already grows with the tile’s height (40cqh is 40% of it). On a small tile the humidity line goes, so the temperature keeps its room. The button gets a clear outline when it’s reached with the keyboard.
.reading:focus-visible { outline: 2px solid var(--hd-accent); outline-offset: 4px; border-radius: 4px;}/* A small tile keeps the temperature and drops the rest. */@container (height < 110px) { .extra { display: none; }}{%- assign temperature = cap.measure_temperature.value -%}<p class="name">{{ settings.label | default: device.name }}</p>{% if device.available == false %} <p class="state">Unavailable</p>{% elsif temperature == nil %} <p class="state">No reading yet</p>{% else %} <button class="reading" data-hd-on-click="openHistory('measure_temperature', '24h')"> {{ temperature | temp: 1 }} </button> {% if cap.measure_humidity.value != nil %} <p class="extra">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }} humidity</p> {% endif %}{% endif %}Switch the preview’s theme to see it in light and dark.
5. Put it on your dashboard
- In the app, open Workshop, choose New →Widget, then Start from a widget and pickClimate. Name it Room climate.
- On the Settings tab, choose JSON and paste the settings from step 2. On Template and Style, paste the finished files.
- The editor checks it against its demo devices and says when there are no problems. ChooseSave.
- On your dashboard, choose Add a widget; yours is on theMy own tab. Pick a sensor for the tile, and a label if you like.
The same steps with screenshots are in theMake your own widget tutorial.
6. Publish it
Anyone can install a widget you publish to the Community, on Free as well as Pro. From the editor, choose Publish to the community…; thepublishing tutorial walks through it. Or publish from the command line: unzip the finished widget into a folder namedroom-climate, replace your-handle in its tiledash.jsonwith your name in the Community, and run:
npx tiledash auth loginnpx tiledash publish room-climateRaise version in tiledash.json each time you publish again. More inPublishing from the command line.
What next
Liquid · Settings · Actions · Widget popups · Styling · JavaScript · Examples