How do I increase history retention for custom sensors?

I am using the sensor below from MQTT data. It does not seem to save history beyond 10 days. I understand there is 10d short-term history and a less granular long-term history. My other devices (temperature sensor, air quality sensor, etc) seem to have the long-term history without additional configuration. Can you explain to me if custom sensors like what I have set up do not automatically have long-term history, and how I can configure it so it keeps the long-term history? Thank you!

mqtt:
  sensor:
    - name: "tesla battery level"
      state_topic: "teslamate/cars/1/usable_battery_level"
      device_class: battery
      unit_of_measurement: "%"
    - name: "tesla state"
      state_topic: "teslamate/cars/1/state"
    - name: "tesla power"
      state_topic: "teslamate/cars/1/power"

Try adding state_class: measurement. You can also check if this is there in Developer Tools, States.

2 Likes

Ellcon is correct, adding a valid state_class will cause LTS to be generated. This will be kept forever. You can only add it for the numeric type sensors.

mqtt:
  sensor:
    - name: "tesla battery level"
      state_topic: "teslamate/cars/1/usable_battery_level"
      device_class: battery
      state_class: measurement
      unit_of_measurement: "%"
    - name: "tesla state"
      state_topic: "teslamate/cars/1/state"
    - name: "tesla power"
      state_topic: "teslamate/cars/1/power"
1 Like

Thanks @Ellcon and @tom_l for your solution. So it sounds like if I wanted to log non-numeric sensors/data, then I would have to log it into an external database?