Using alarm_control_panel.code in an automation

I have a rs485 connected keypad that I want to use for arming and disarming my alarm. I want to use the same “alarm_control_panel.code” to trigger an “action:”. I cannot seem to make it work.

My focus is on the action: → to: clause.
Thanks
Ed

The following snip-it from my automations.yaml executes the intended action if I enter “1234” on my keypad.

- id: '1727041912854'
  alias: Trigger Alarm 2a
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.rs485_pin
    to: "1234"
  action:
  - type: turn_on
    device_id: fdf2f95d6479f1505e0cb8cf0d5322ff
    entity_id: 3b9689c79345158c7e5f2032cf40d307
    domain: switch
  mode: single

If I change the to: clause to compare to the code setting in my alarm_control_panel does not execute the intended action.

 -id: '1727041912854'
  alias: Trigger Alarm 2a
  description: ''
  trigger:
  - platform: state
    entity_id:
    - sensor.rs485_pin
   to: alarm_control_panel.home_alarm_1700.code
  action:
  - type: turn_on
    device_id: fdf2f95d6479f1505e0cb8cf0d5322ff
    entity_id: 3b9689c79345158c7e5f2032cf40d307
    domain: switch
  mode: single

From my configuration.yaml my alarm_control_panel is as follows.

### Alarm Control Panel ####
alarm_control_panel:
  - platform: manual
    name: Home Alarm 1700 
    code: '1234'
    code_arm_required: true
    arming_time: 5 # The delay before arming.
    delay_time: 3 # The pending state before alarm is triggered.
    trigger_time: 120 # The time the alarm stays active.
    disarm_after_trigger: false # Action after 120 seconds.
    disarmed:
      trigger_time: 0
    armed_home:
      arming_time: 0
      delay_time: 0