From 25f81ff96ce775d2b240344926a6cfe2131b38d7 Mon Sep 17 00:00:00 2001 From: AnasHost <41167157+Anashost@users.noreply.github.com> Date: Tue, 15 Sep 2026 18:13:30 +0200 Subject: [PATCH] Update climate_collection.md --- climate_collection.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/climate_collection.md b/climate_collection.md index fbeb4f1..c899f01 100644 --- a/climate_collection.md +++ b/climate_collection.md @@ -583,14 +583,30 @@ custom_fields: unique_id: temptrend_24h state: > {% set target = 'sensor.openweathermap_temperature' %} - {{ (state_attr(target, 'temperature') if target.startswith('weather.') else states(target)) | float(0) | round(1) }} + {% set raw_val = state_attr(target, 'temperature') if target.startswith('weather.') else states(target) %} + {% if is_number(raw_val) %} + {{ raw_val | float | round(1) }} + {% else %} + {{ this.state | default(0, true) }} + {% endif %} attributes: last_update: "{{ now().timestamp() }}" history: > {% set target = 'sensor.openweathermap_temperature' %} - {% set current = (state_attr(target, 'temperature') if target.startswith('weather.') else states(target)) | float(0) | round(1) %} - {% set past = state_attr('sensor.temptrend_24h', 'history') | default([current] * 24, true) %} - {{ (past + [current])[-24:] }} + {% set raw_val = state_attr(target, 'temperature') if target.startswith('weather.') else states(target) %} + {% set past = state_attr('sensor.temptrend_24h', 'history') %} + + {% if is_number(raw_val) %} + {% set current = raw_val | float | round(1) %} + {% else %} + {% set current = past[-1] if past is not none and past | length > 0 else 0 %} + {% endif %} + + {% if past is none or past | length == 0 %} + {{ [current] * 24 }} + {% else %} + {{ (past + [current])[-24:] }} + {% endif %} ```