I’m using a template sensor (aussenthermometer_maximum) to save a state of another sensor (aussenthermometer_max_letzte_24_stunden) and enrich with an attribute with an attribute.
Source is a statistic sensor, which is calculation out of another sensor, which is sometime not available a startup of HA.
Then I thought to check against a number and use the old value if it is not a number. But as only trigger sensors restore their state during restart, I converted to trigger sensor as well. But still get the error on reboot:
ValueError: Sensor sensor.aussenthermometer_maximum has device class temperature, state class measurement unit °C and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: unknown (<class ‘str’>)
But I don’t understand why this is not working, as it should check if it is available and returns a number and only then take this into the sensor. Otherwise take the old state or the restored state before reboot.
- trigger:
- platform: state
entity_id: sensor.aussenthermometer_max_letzte_24_stunden
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
- sensor:
- name: Außenthermometer Maximum
unique_id: unique_id_template_sensor_aussenthermometer_maximum
state: >
{% if is_number(states('sensor.aussenthermometer_max_letzte_24_stunden')) %}
{{ states('sensor.aussenthermometer_max_letzte_24_stunden') }}
{% else %}
{{ states('sensor.aussenthermometer_maximum') }}
{% endif %}
icon: mdi:thermometer-plus
device_class: temperature
state_class: measurement
unit_of_measurement: "°C"
attributes:
zeit: >
{{ states('sensor.aussenthermometer_max_letzte_24_stunden_zeit') }}