Battery sensor or Zwave Door

I setup an automation to read the battery level of my door lock but I’m getting errors in the log about it.
17-03-22 10:08:39 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Front Door Battery, the state is unknown. 17-03-22 10:08:40 WARNING (MainThread) [homeassistant.helpers.condition] Value cannot be processed as a number:

Here is my code. Does anyone see where I went wrong? Its reading back a value of 90% all the time.

  - platform: template
    sensors:
      batt_frontdoor:
        friendly_name: 'Front Door Battery'
        value_template: '{{ states.sensor.kwikset_touchpad_electronic_deadbolt_alarm_level_8_1.attributes.battery_level }}'
        unit_of_measurement: '%'

Hi,

You may need | int or | float at the end…
{{ states.sensor.kwikset_touchpad_electronic_deadbolt_alarm_level_8_1.attributes.battery_level | float}}

You need .state at the end after battery_level

I removed the sensor as a template and just used the battery_level sensor in my configuration and all is good now. Not sure why tho. thanks

Note that standalone sensor for battery level will go away in 0.41/0.42

If that’s the case I suggest you just add .state and keep the template sensor @Dayve67 all you need to add is .state the rest looks good.

Ok. if i add .state to the end I now get this

17-03-22 14:38:01 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Front Door Battery, the state is unknown.

  - platform: template
    sensors:
      batt_frontdoor:
        friendly_name: 'Front Door Battery'
        value_template: '{{ states.sensor.kwikset_touchpad_electronic_deadbolt_battery_level_8_0.attributes.battery_level.state }}'
        unit_of_measurement: '%'

Oh, oops sorry I misled you… I didn’t realize you were looking at an attribute. The way you had it should work…

You should put that template line in the template editor in the dashboard and see if it works correctly.

Thats ok.
Im new to this. So how do I put it into the template editor?

If you have home assistant running, under the developer tools one of the buttons will link to template editor. (down at the bottom of the sidebar on left hand side)

Just paste in your
{{ states.sensor.kwikset_touchpad_electronic_deadbolt_alarm_level_8_1.attributes.battery_level }}
into the text box to see if it renders correctly, you should see the battery level in the output on the right side

Ah got it. If I take out the .state it shows the value.

Seems to be working but still shows up a warning in the log. Hmmm

Why? I just converted to use it - seems handy

Zwave node is getting its own entity with many attributes, including battery level.
For automation and alerts it is enough.
A separate sensor is just for visuals - this can be still done with a template sensor.