No State History Found for Template Sensor

I made some template sensors based on entity attributes. On the graph in Lovelace it shows “No State History Found” but if I click on the graph I do see the history bar. This is only for the templated sensors, other sensors graph fine. Is there some additional configuration step I am missing?

- platform: template
  sensors:
    living_room_blinds_1_battery:
      value_template: "{{ state_attr('light.living_room_blinds_1_dim','battery_level')}}"
      friendly_name: "Living Room Blinds 1 Battery"
entity: sensor.living_room_blinds_1_battery
graph: line
icon: 'hass:blinds'
name: Living Room 1
type: sensor

image
image

Add the following to your sensor: device_class: battery

This will add a unit of measurement, allowing you to graph the value. It will also add a battery icon that changes state depending on the battery level.

If you want to keep the icon you have now add unit_of_measurement: '%' instead of the device class.

Thanks but neither of these steps seemed to make a difference. Setting device_class: battery did change the icon to a battery with a question mark. But that was the only difference. I gave it a couple of days but no graph with that or setting uom to %.

Look in the developer tools states menu. Does the state contain the unit (%)?

If so, try this template that removes the unit (%) from the state and assigns the battery device class:

- platform: template
  sensors:
    living_room_blinds_1_battery:
      value_template: "{{ state_attr('light.living_room_blinds_1_dim','battery_level')|replace('%', '') }}"
      friendly_name: "Living Room Blinds 1 Battery"
      device_class: battery
1 Like

That did the trick, thanks for the help.