I have a template sensor for weight (that automatically distinguishes between two persons by approximate weight).
Problem is, the value just disappears (shows “Unknown”) after a period of time, and after HA restarts. It IS included in History and Logbook portions of congifuration.yaml, and it DOES show in History.
I want it to stay and show the last known value in a Lovelace badge.
This is the sensor:
- platform: template
sensors:
weight_name_jiri:
friendly_name: "Weight Jiri"
value_template: >-
{% set weight = states('sensor.ble_miscale_weight') | float %}
{% if 80 <= weight <= 100 %}
{{ states("sensor.ble_miscale_weight") }}
{% else %}
{{ states("sensor.weight_name_jiri") }}
{% endif %}
unit_of_measurement: 'kg'
icon_template: mdi:weight-kilogram