Cant figure out why template sensor not working

So this used to work on my old setup. Just redid everything and the template sensor shows up in states, but the actually state is blank.

my sensor.yaml:

- platform: template
  sensors:
    test_battery:
        value_template: '{{ states.zwave.assa_abloy_yale_key_free_touchscreen_deadbolt_yrd446_2.battery_level }}'
        friendly_name: 'test'
        unit_of_measurement: "%"

The current batterty level that shows in states is 98%.

Any ideas?

try adding an “entity_id:” entry to the sensor config.

It won’t update if it can’t figure out what entity to update on.

https://www.home-assistant.io/components/template/#entity-ids

- platform: template
  sensors:
    test_battery:
        entity_id: zwave.assa_abloy_yale_key_free_touchscreen_deadbolt_yrd446_2
        value_template: '{{ states.zwave.assa_abloy_yale_key_free_touchscreen_deadbolt_yrd446_2.battery_level }}'
        friendly_name: 'test'
        unit_of_measurement: "%"

I use this for my sensors:

  - platform: template
    sensors:
      aqara_battery_temp_kitchen:
        friendly_name: "Battery level"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('sensor.temperature_158d0003591323', 'battery_level') }}"

Oh, and looking again I see that your template is wrong.

this:

should be:

value_template: '{{ states.zwave.assa_abloy_yale_key_free_touchscreen_deadbolt_yrd446_2.attributes.battery_level }}'

Ive never needed entity id for that, but regardless I tried yours and its still blank.

Ah, thanks! That did it

I’m not sure how old your “old setup” was but the requirement for the entity_id was added a few releases back.

It’s not always necessary tho (see the link I posted). If the system can determine an entity_id to use to update then everything is fine. If it can’t it will (should…?) put an error in the log and the sensor won’t update. You then need to manually provide it with an entity_id to update on.

Either way, I’m glad I could help.