Can't get battery device class to work

Hi,

I’m struggling to get a sensor to be recognised as the battery device class.

It’s an http post sensor coming from Tasker on an android phone with the battery life. The data is coming through okay it just won’t seem to register as a battery class.

I have it set up as:

homeassistant:
  customize:
    sensor.android_battery:
      device_class: "battery" (have also tried without quotes)

But it just comes through into my frontend as a normal sensor as if the code above isn’t there at all…

Running 0.69.0 on RPi3 Hassio, any help much appreciated!

Thanks :slight_smile:

I have used the door device_class in my customize.yaml. It looks like this:

  binary_sensor.back_door_sensor:
   device_class: door
   friendly_name: "Back Door"

It worked without any issues and took effect once I did a “Reload Core” and changed the state of the door.

I also used the battery device class, but I implemented it in my configuration.yaml where the sensor was defined. Like this:

  - platform: template
    sensors:
      master_bathroom_door_battery:
        entity_id: zwave.master_bathroom_door_sensor
        value_template: "{{ states.zwave.master_bathroom_door_sensor.attributes.battery_level }}"
        friendly_name: 'Master Bathroom Door Battery'
        device_class: battery

It took effect after restarting home assistant. The icon changed to a battery, but the level does NOT have a unit of % (no unit at all). I had to do this to get the units to be %:

  - platform: template
    sensors:
      master_bathroom_door_battery:
        entity_id: zwave.master_bathroom_door_sensor
        value_template: "{{ states.zwave.master_bathroom_door_sensor.attributes.battery_level }}"
        friendly_name: 'Master Bathroom Door Battery'
        device_class: battery
        unit_of_measurement: "%"