Skip to content

Responsive layout

Readings sit side by side on a wide tile and stack on a tall one; a small tile keeps only the temperature.

Several readings
<div class="readings">  <p class="main">    <span class="label">Temperature</span>    <span class="value">{{ cap.measure_temperature.value | temp: 1 }}</span>  </p>  {% if cap.measure_humidity.value != nil %}    <p>      <span class="label">Humidity</span>      <span class="value">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }}</span>    </p>  {% endif %}  {% if cap.measure_co2.value != nil %}    <p>      <span class="label">CO₂</span>      <span class="value">{{ cap.measure_co2.text }} {{ cap.measure_co2.unit }}</span>    </p>  {% endif %}</div>

The preview runs on a made-up sensor.climate device, so you don’t need a Homey. Edit the template or style to try something; actions don’t reach a device here.

How it works

container-type: size on :host lets the style ask how big the tile is. One @container rule puts the readings in a row when the tile is wide; another keeps only the temperature when it’s small. cqh units size the main number to the tile’s height.

Readings the device doesn’t have are left out, so the grid can have fewer columns filled.

Files

Download the package

template.liquid
<div class="readings">  <p class="main">    <span class="label">Temperature</span>    <span class="value">{{ cap.measure_temperature.value | temp: 1 }}</span>  </p>  {% if cap.measure_humidity.value != nil %}    <p>      <span class="label">Humidity</span>      <span class="value">{{ cap.measure_humidity.text }}{{ cap.measure_humidity.unit }}</span>    </p>  {% endif %}  {% if cap.measure_co2.value != nil %}    <p>      <span class="label">CO₂</span>      <span class="value">{{ cap.measure_co2.text }} {{ cap.measure_co2.unit }}</span>    </p>  {% endif %}</div>
style.css
:host {  display: block;  padding: 16px;  container-type: size;}p {  margin: 0;}.readings {  display: grid;  gap: 12px;  height: 100%;  align-content: start;}.label {  display: block;  font: 600 12px var(--hd-font-ui);  color: var(--hd-text-muted);}.value {  font: var(--hd-number-weight) 22px / 1.2 var(--hd-font-display);}.main .value {  font-size: clamp(28px, 30cqh, 48px);}/* A wide tile puts the readings side by side. */@container (width > 360px) {  .readings {    grid-template-columns: 2fr 1fr 1fr;    align-content: end;  }}/* A small tile keeps only the temperature. */@container (width <= 360px) and (height < 160px) {  .readings > :not(.main) {    display: none;  }}
tiledash.json
{  "id": "@your-handle/reading-layout",  "title": "Responsive layout",  "summary": "Readings sit side by side on a wide tile and stack on a tall one; a small tile keeps only the temperature.",  "version": "1.0.0",  "licence": "MIT",  "tags": [],  "kind": "widget",  "widget": {    "kind": "device",    "match": {      "requires": [        "measure_temperature"      ],      "optional": [        "measure_humidity",        "measure_co2",        "measure_battery",        "alarm_battery"      ]    },    "size": {      "default": [        3,        4      ],      "min": [        1,        1      ],      "max": [        6,        8      ]    },    "align": {      "y": "end"    },    "settings": [      {        "name": "tileTap",        "label": "The tile",        "required": false,        "group": "tap",        "type": "tap",        "gesture": "tap",        "default": {          "type": "none"        },        "hold": {          "type": "device"        },        "double": {          "type": "none"        },        "allow": [          "toggle",          "device",          "dashboard",          "flow",          "mood",          "variable",          "request"        ]      },      {        "name": "temperatureTap",        "label": "Temperature",        "required": false,        "group": "tap",        "type": "tap",        "gesture": "tap",        "default": {          "type": "none"        },        "hold": {          "type": "none"        },        "double": {          "type": "none"        },        "allow": [          "toggle",          "device",          "history",          "dashboard",          "flow",          "mood",          "variable",          "request"        ],        "capability": "measure_temperature"      },      {        "name": "humidityTap",        "label": "Humidity",        "required": false,        "group": "tap",        "type": "tap",        "gesture": "tap",        "default": {          "type": "none"        },        "hold": {          "type": "none"        },        "double": {          "type": "none"        },        "allow": [          "toggle",          "device",          "history",          "dashboard",          "flow",          "mood",          "variable",          "request"        ],        "capability": "measure_humidity"      }    ],    "basedOn": "sensor.climate"  }}

Use it

In the editor, start from the widget it’s based on and paste the template and style; or unzip the package, replace your-handle with your name in the Community and publish it. Build your first widget walks through both.

Read more: Styling · Liquid