Conditional state
Pick a word and a colour from the temperature: cool, comfortable or warm.
{%- assign temperature = cap.measure_temperature.value -%}<p class="name">{{ device.name }}</p>{% if temperature == nil %} <p class="state">No reading yet</p>{% else %} {%- if temperature < 19 -%} {%- assign tone = 'cool' -%} {%- assign word = 'Cool' -%} {%- elsif temperature > 24 -%} {%- assign tone = 'warm' -%} {%- assign word = 'Warm' -%} {%- else -%} {%- assign tone = 'ok' -%} {%- assign word = 'Comfortable' -%} {%- endif -%} <p class="reading">{{ temperature | temp: 1 }}</p> <p class="feel" data-tone="{{ tone }}">{{ word }}</p>{% endif %}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
if, elsif and else choose a word and a tone from the reading. The tone goes into a data-tone attribute, and the style colours each tone with the theme’s own colours, so it works in light and dark.
The limits (19° and 24°) are fixed in the template; a setting could make them adjustable.
Files
{%- assign temperature = cap.measure_temperature.value -%}<p class="name">{{ device.name }}</p>{% if temperature == nil %} <p class="state">No reading yet</p>{% else %} {%- if temperature < 19 -%} {%- assign tone = 'cool' -%} {%- assign word = 'Cool' -%} {%- elsif temperature > 24 -%} {%- assign tone = 'warm' -%} {%- assign word = 'Warm' -%} {%- else -%} {%- assign tone = 'ok' -%} {%- assign word = 'Comfortable' -%} {%- endif -%} <p class="reading">{{ temperature | temp: 1 }}</p> <p class="feel" data-tone="{{ tone }}">{{ word }}</p>{% endif %}:host { display: grid; align-content: space-between; gap: 4px; padding: 16px; 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, 36cqh, 52px) / 1 var(--hd-font-display);}.feel { font: 600 15px var(--hd-font-ui);}.feel[data-tone='cool'] { color: var(--hd-cool);}.feel[data-tone='warm'] { color: var(--hd-warn);}.state { font: 600 15px var(--hd-font-ui); color: var(--hd-text-muted);}{ "id": "@your-handle/conditional-state", "title": "Conditional state", "summary": "Pick a word and a colour from the temperature: cool, comfortable or warm.", "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.