How a widget works
The three parts of a widget, how Tiledash draws and updates one, and why a widget of your own can’t harm your dashboard.
Every tile on a dashboard is drawn by a widget. The built-in widgets and the ones you make are built the same way, from the same parts, so anything a built-in widget does, yours can do too.
If you know a little HTML and CSS you already know most of what you need. The rest is a small template language for putting your Homey’s values into the page. If you would rather not write it yourself, your AI assistant can build widgets for you.
The three parts
A widget is made of three things:
- A manifest says what the widget is: its name, which devices it fits, how big a tile can be and which settings each tile can change.
- A template says what the widget shows. It is HTML with Liquid in it, which fills in values such as the device’s name or the temperature.
- A style says how it looks. It is plain CSS.
Here is a template and a style that show a room’s temperature:
<p class="name">{{ device.name }}</p><p class="big">{{ cap.measure_temperature.value | temp: 1 }}</p>.name { font: 500 13px var(--hd-font-ui); color: var(--hd-text-muted);}.big { font: var(--hd-number-weight) 48px var(--hd-font-display);}device.name is the name of the tile’s device in Homey.
cap.measure_temperature.value is its temperature, and temp: 1 writes it with one decimal and a degree sign.
The style reads the theme’s fonts and colours through --hd-* variables, so the widget looks right in every theme.
You don’t write the manifest by hand in the app. When you make a widget, the editor builds it for you: the name you give it, the settings you add on the Settings tab, and the devices and tile sizes of the widget you started from. The manifest reference lists every field if you want to know what is behind it.
How a widget is drawn
When a tile needs drawing, Tiledash does four things:
- It collects what the widget can read: the tile’s device and its readings, what the tile’s settings are set to, the time and so on. The context reference lists all of it.
- It runs your template through Liquid with that data. Every value that Liquid writes out is escaped, so a device called
<b>Lamp</b>shows exactly that. - It cleans the result with DOMPurify against a fixed list of elements and attributes. Anything else is removed.
- It puts what is left into the tile’s own Shadow DOM, next to your style.
When something changes, a reading from Homey, a setting, or something the widget keeps in its own state, steps 2 to 4 run again. The new HTML is merged into the elements that are already there instead of replacing them. That is why a bulb keeps fading, a chart keeps its line and a focused button keeps its focus while the values underneath it move.
A widget that reads the clock (now, since(), until() or isToday()) is drawn again every minute.
One that doesn’t holds no timer at all.
The hd-* elements, such as hd-bulb, hd-slider and hd-sparkline, do the moving parts.
You write them in the template like any HTML element, and they animate, draw charts and send changes back to Homey on their own.
The components reference lists them all with their attributes.
What a widget can and can’t do
A widget is code from someone who isn’t Tiledash, even when that someone is you. So it is held to a short list of rules, checked every time you save:
- Output is escaped. Anything Liquid writes into the page is turned into plain text first. The
rawfilter exists in Liquid, but here it can’t undo that. - Only listed HTML. Templates can use a fixed set of HTML elements and the
hd-*components. There are no scripts, links,<img>elements, forms or<style>elements, andidisn’t an allowed attribute. See the HTML reference. An inlinestyleattribute can only set custom properties, such asstyle="--fill: 62%". - No JavaScript. When something is tapped, a short line in a small expression language runs. It is read by a parser and carried out by Tiledash, never handed to JavaScript, and it can only call a fixed list of actions.
- Actions are checked. Before anything reaches your Homey, Tiledash checks that the device is on this Homey, that the reading can be changed and that the value fits. A refused action changes nothing and says why in a message.
- CSS can’t load anything.
url(),@importand@font-facearen’t allowed, so a style can’t fetch an image or a font from elsewhere. - Limits. A template or a style can be 20,000 characters long. A template may take 50,000 steps of work to draw (every tag, value and loop round counts, partials included), and a widget can render at most three levels of partials.
- Only its own data. A template reads the data it is given and nothing else. It can’t reach the rest of the page or other tiles, and it can’t run code that fetches things. Pictures and video come in through the
hd-imageandhd-cameracomponents, which fetch them without cookies or a referrer.
When you save, the editor draws your widget with demo devices in several states, including a device that is unavailable and settings left empty, and refuses a save that fails. Write the template so that it copes with a reading that is missing.
Your own widgets are free
Making widgets and partials of your own is free on every plan, and so is changing how a built-in widget looks: the Style panel on any tile, with saved presets and CSS for a single tile, is open to everyone.
Where to start in the app
The Workshop in the sidebar lists everything you have made, with New for a widget or a partial; Make a widget… in the widget picker and Make this widget yours… in a tile’s menu open the same editor. Start from a widget copies a built-in or one of yours, which is the easiest way to learn; Start empty gives you a widget with no device of its own, for things you build from settings.
The editor has a Template, a Style and a Settings tab, panels that list what a template can read and do, and a preview that draws your widget with demo devices, your own or test devices as you type. The widget editor is a tour of it, from the preview to going back to an earlier save.
Ready to build one? The tutorial Make your own widget takes you through it, from New widget to a tile on your dashboard.
Where to go next
- Make your own widget builds one step by step, with a picture of each step.
- Liquid and Expressions cover the template language.
- Taps and handlers, Settings and Partials cover what makes a widget interactive and reusable.
- Styling and Layout blocks cover how it looks.
- Widgets in widgets draws other widgets inside yours, such as a room card.