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 %} ```