Comfort word with expressions
The conditional example written with let and the ternary operator.
{% let temp = cap.measure_temperature.value %}{% let humidity = cap.measure_humidity.value %}{% let tone = temp < 19 ? 'cool' : temp > 24 ? 'warm' : 'ok' %}{% let feel = temp < 19 ? 'Cool' : temp > 24 ? 'Warm' : 'Comfortable' %}<header class="head">{{ device.name }}</header><p class="big">{{= round(temp, 1) }}°</p><p class="feel" data-tone="{{ tone }}">{{ feel }}</p><p class="sub"> {{= round(temp * 9 / 5 + 32) }} °F {% if humidity > 60 and temp > 22 %}· muggy{% endif %}</p>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.
Files
{% let temp = cap.measure_temperature.value %}{% let humidity = cap.measure_humidity.value %}{% let tone = temp < 19 ? 'cool' : temp > 24 ? 'warm' : 'ok' %}{% let feel = temp < 19 ? 'Cool' : temp > 24 ? 'Warm' : 'Comfortable' %}<header class="head">{{ device.name }}</header><p class="big">{{= round(temp, 1) }}°</p><p class="feel" data-tone="{{ tone }}">{{ feel }}</p><p class="sub"> {{= round(temp * 9 / 5 + 32) }} °F {% if humidity > 60 and temp > 22 %}· muggy{% endif %}</p>:host { display: flex; flex-direction: column; gap: 4px;}.head { font: 500 11px var(--hd-font-mono); letter-spacing: var(--hd-label-tracking); text-transform: var(--hd-label-transform); color: var(--hd-text-muted);}.big { margin: auto 0 0; font: var(--hd-number-weight) 56px / 1 var(--hd-font-display);}.feel { margin: 0; font: 600 15px var(--hd-font-ui);}.feel[data-tone='cool'] { color: var(--hd-cool);}.feel[data-tone='warm'] { color: var(--hd-warn);}.sub { margin: 0; font: 13px var(--hd-font-ui); color: var(--hd-text-muted);}p { margin-block: 0;}{ "id": "@your-handle/comfort-word", "title": "Comfort word with expressions", "summary": "The conditional example written with let and the ternary operator.", "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: Expressions · Liquid