Changing 'template entity' state based on 'entity value + attribute'

*** apologies, code copied instead of picture ***

Question on changing the value (state) of an entity for friendly readout in lovelace card.

I have a nuki lock that reports the battery status as an attribute of the entity lock.frontdoor as either battery_critical: false or true (see below picture):
image
image

Now I would like it to show up on my lovelace card as status being either ‘Good’ or ‘Charge!’, therefore I created this template sensor but I do not seem to be able to get the script right, I can only grab the value from the entity but not from the battery_critical attribute of the entity.

configuration.yaml :

sensor:
  - platform: template
    sensors:
      lock_frontdoor_battery_level:
        value_template: '{% if is_state("sensor.nuki_frontdoor_battery_level", "battery_critical", "false") %}Good{% else %}Charge{% endif %}'
        friendly_name: 'Frontdoor Battery Level' 

Is there anyone that can help me write the correct script? I think the syntax in row 55 is incorrect… when I take out the attribute it works and takes the status of the lock.frontdoor entity, but when I try to add the attribute to grab the state from, it fails.

A bit more info, I also have a separate template.yaml with the following code, not sure if the template from the configuration.yaml should have the above template sensor or should I keep it in the template.yaml file?

template.yaml :

#Adding Nuki Lock Battery Status Entities
  - sensor:
      - name: "Nuki Frontdoor Battery Level"
        device_class: battery
        state: "{{ state_attr('lock.frontdoor', 'battery_critical') }}"

Thanks!

Hello and welcome to the forum.

Can you please post the correctly formatted configuration text instead of a picture of the text?

That makes it a lot easier for us to help you.