Templates for GPIO sensors

I am using GPIO 17 as input and inserted the text below in configuration.yaml.

binary_sensor:
  - platform: rpi_gpio
    ports:
      17: Alarm

  - platform: template
    sensors:
      AlarmOn:
        value_template: "{{ states.binary_sensor.Alarm.state == 'on' }}"

I am trying to create a sensor template (AlarmOn) to change the way output is displayed, but getting an invalid config error.

I am a bit new to templates, so probably I am doing a silly mistake.

Can someone help please?

See the first post in the linked thread below for how to post your config and maintain formatting. It helps when trying to provide assistance.

platform: template
sensors:
  Alarm Status:
    value_template: '{% if is_state("binary_sensor.alarm", "on") %}Alarm On{% else %}Alarm Off{% endif %}'

Thanks @silvrr. New to this. Post corrected.