I think this should set a correct value, as soon as a valid value is delivered from sensor.weather_temperature. But sensor.weather_temperature_min is unknown… Is there another thing I’m missing?
I’ve been using a sensor like this for a while. I acknowledge that it seems overly complicated, but it works. I’ve tried a number of ways to simplify this, but every one of them breaks the sensor…
trigger:
- platform: time
at: "00:00"
id: reset
- platform: state
entity_id: sensor.weather_temperature
not_to:
- unknown
- unavailable
sensor:
- name: "Weather Temperature Min"
unique_id: weather_temperature_min
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer-chevron-down
state: |
{% set source = states('sensor.weather_temperature') | float(0) %}
{% if trigger.id == 'reset' %}
{{ source }}
{% else %}
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ [source, current] | min }}
{% endif %}
attributes:
datetime: |
{% set source = states('sensor.weather_temperature') | float(0) %}
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ now() if current < source else this.attributes.datetime | default(now(),1) }}
- name: "Weather Temperature Max"
unique_id: weather_temperature_max
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer-chevron-up
state: |
{% set source = states('sensor.weather_temperature') | float(0) %}
{% if trigger.id == 'reset' %}
{{ source }}
{% else %}
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ [source, current] | max }}
{% endif %}
attributes:
datetime: |
{% set source = states('sensor.weather_temperature') | float(0) %}
{% set current = (this.state or trigger.to_state.state) | float(source) %}
{{ now() if current > source else this.attributes.datetime | default(now(),1)}}