Device_class on template sensor

Hi friends!
I wanted to setup a battery level indicator on my HAS dashboard and followed the example here
https://www.home-assistant.io/cookbook/track_battery_level/

Whenever I add “device_class” as per my below example and the link above my config validation fails with a message that says

sensor.template:
- Invalid config for [sensor.template]: [device_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->battery_front_door_sensor->device_class. (See ?, line ?)

Here is my config
- platform: template
sensors:
battery_front_door_sensor:
friendly_name: Front Door Sensor Battery
unit_of_measurement: ‘%’
device_class: battery
value_template: >-
{%- if states.zwave.front_door_sensor.attributes.battery_level %}
{{ states.zwave.front_door_sensor.attributes.battery_level|round }}
{% else %}
{{ states.sensor.battery_front_door_sensor.state }}
{%- endif %}

When I comment out the device_class line everything works as expected.
Am I doing it wrong or are the docs outdated or did I find a bug?

Please format your code correctly using 3 `'s (upper left button on keyboard) or using the </> button in the editor.

anyways from the looks of it, device_class is not a valid option for template sensors, that can only be done in the customization. Remove that and you should be fine. If you want to add the device_class to the sensor, do it in the customization section.

Device class is only available for binary sensors, not regular sensors.

To specify an icon use

icon: mdi:battery

That feature was introduced in 0.69. Are you running an older version by chance?

What feature?

Who? The OP?

I’m assuming @NotoriousBDG meant using device_class with a template sensor. The docs now show it’s possible:

The addition of device_class for template sensors in Home Assistant 0.69.

@ettman8

Correct.

I noticed this after this post. That opens up some opportunities.

Yeah, it definitely makes battery monitoring simpler. If you have a lot of battery powered devices, Howto create battery alert without creating a template for every device - #204 by NotoriousBDG might be of interest to you.

There it is! I recon you are on the money