I’ve created a sensor in yaml using template integration, with a state_class and unit_of_measurement. However the data does not go into long-term-storage. Data from other sensors, like a Zigbee temperature sensor, do go into LTS, so I do not think it is a problem with the record/history integration itself.
What change do I need to make to have my sensor data go into LTS?
For some reason it seems you don’t have data from before that date, but it seems to be working correctly now. Maybe there was some config setup issue, or maybe you accidentally purged the records, I can’t say.
Lets just wait and see if it continues working going forward.
I believe 2025.3.1 required the value of unit_of_measurement to be valid for the chosen state_class. I don’t think x meets that requirement so the Template Sensor is excluded from long-term statistics.
Check Settings → Logs for any related error/warning messages. Also check Developer Tools → Statistics for any warnings about the Template Sensor.
Version 2025.3.2 removed that requirement and it now works like it did in the past. I suggest you upgrade then wait at least 2 days to see if the Template Sensor’s recorded history has increased beyond 10 days.
EDIT
I think I was wrong about all of that because I found the relevant PR and it applies to MQTT Sensor.
Nevertheless, check the places I mentioned for errors/warnings and consider upgrading to the latest patch release.