Sensor template value not saved into recorder if it doesn't change?

Interesting thing happened to me overnight…
I have Xiaomi thermo/hygro sensor, connected via new BT proxy. This part works fine. Since temp value is sent with two decimals i created template sensor with only one decimal:

- platform: template
  sensors:
    stopnice_temperatura_bthome:
      friendly_name: Stopnice temperatura
      unique_id: stopnice_temperatura_bthome
      value_template: "{{states('sensor.stopnice_7d43_temperature')| round(1)}}"
      unit_of_measurement: "°C"
      device_class: temperature

I also have SQL for MIN and MAX temp today:

SELECT ROUND(MIN(CAST(state as FLOAT)),1) as state FROM states WHERE entity_id = 'sensor.stopnice_temperatura_bthome' AND last_updated > CURRENT_DATE AND state not like 'unavailable' AND state not like 'unknown';

But, today in the morning when i woke up both SQL sensors was “unknown”, while current temp. was alive and 23.4 degrees.

After digging i found out that temperature from xiaomi didn’t change from yesterday - well, it changed, but within second decimal, so template sensor remained at 23.4 degrees.
It seems that template sensor doesn’t get recorded if remains unchanged. I proved that with this procedure:

  • went to developer tools
  • selected sensor “sensor.veranda_0b24_temperature”
  • changed it manually to 23.1
  • that moment both SQL’s show up and after above sensor “corrected” itself (received value 23.4 from xiaomi again) SQL’s now show MIN=23.1, MAX=23.4

Is this normal? I wouldn’ tbe too surprised, since efforts are being made to keep recorder size to a minimum…
If so, how can i “make” recorder to record value at least once a day?
Ok, one solution is to extract SQL from original value, not from template sensor… but still, it’s an interesting finding…

Yes this is normal. Only state changes and events are stored.

How about a triggered template sensor?

Trigger on change of the source sensor and a time trigger.

1 Like

Thank you for confirmation! Another new thing i learned… it’s interesting that this is the first time it happened to me that any temperature actually stayed exactly the same (up to a decimals!) for several hours…

Now i figured it out that i can actually use my original sensor from xiaomi for SQL, not my template sensor, since i have round to 1 set in my SQL, too. And original sensor won’t stay on same value so long, since xiaomi publishes two digits resolution temperature.

Thanks for pointing out trigger template sensor - i’ll look at it, since it can come usefull in the future.