So, I would like to get this battery level attribute information by creating template sensor as mentioned in this link (https://www.home-assistant.io/components/sensor.template/), then displays this battery level under HA using sensor card configuration.
Then I created my own configuration, as per below:
After created and restart HA, this sensor.door_sensor_battery_level entity id is not appeared under Developer > States > Current Entities in HA.
So, i can’t select sensor.door_sensor_battery_level to display it under HA homepage using sensor card configuration, whereby my purpose is just to display this battery level.
the entity_id is the id of the entity to track, NOT the name of the template sensor that you’re trying to create (this will be sensor.door_sensor_battery_level)
So you need this:
(device_class)(Optional)Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the unit_of_measurement .
Default value: None
As was already suggested, use device_class: battery
I am in the process of doing this, can you please confirm if the icon changes due to the battery % or do we need to show this a template for this? with an IF function.
The entity_id option was deprecated many versions ago. You can simply remove it. However, the resulting Template Sensor will not be compatible with the Energy integration.
Why? Because it lacks this: state_class: measurement
However, you cannot simply add that to the Template Sensor you posted because it uses the old-style method of configuring a Template Sensor (what is now known as the ‘legacy’ method). The ‘legacy’ style of Template Sensor doesn’t support the state_class option.
You have to define the Template Sensor using the new ‘modern’ format as shown in the documentation for the Template integration. It supports the state_class option.
There’s an example posted here with additional information: