Alarm control panel template variable code

I’m using alarm control panel.
And I want to use a variable for disarming the panel.
Can some one help me with this?
I can’t get it running

text:
  -  platform: template
     id: alarmcodetext
     name: Touchpad code
     mode: password
     pattern: "[0-9]*"
     #min: 0
     #max: 4
     optimistic: True
  -  platform: template
     id: alarm_code
     name: Alarm code
     mode: password
     pattern: "[0-9]*"
     #min: 0
     #max: 4
     optimistic: True
     on_value:
      - lambda: |-
           id(code_string).publish_state(id(alarm_code).state.c_str());
  


alarm_control_panel:
  - platform: template
    name: Alarm Panel
    id: alarm_panel
    codes:
      - "1234"
      - "alarm_code"
#      - !secret alarm_code
      - lambda |-
            return id(code_string).state.c_str();
      - id(code_string).state.c_str()

What are you ultimately trying to achieve with this? It lools like your trying to create a way to assign code/s rarher than using codes that are saved in memory.

Hello,

I would like to make a stand alone alarm in Esphome, that is still working when my HA server is down.
I was thinking to make some variables that I can update by the webserver.
And then using this varaible for disarming the alarm panel.

I think thee "codes: " configuration requires fixed integers only and you cant or atleast not easily.

A workaround would be to create plenty of extra additional or single use codes and then add a template select entity. The options for the Select will be each of your extra codes.

Next, in your

on_state:
    then:
      - lambda: !lambda |-
          ESP_LOGD("TEST", "State change %s",

Your going to add a condition that checks for each/any of your extra codes. If a code has been selected(activated) then Unlock or whatever. Likewise if no codes are selected then the condition doesnt pass and the codes do nothing.

You could even add a text sensor to apply a name or memo for activating the code and also put it on a 12/24hr timer and have it automatically disable extra codes.

I do something similar with my Wiegand keypad.


text_sensor:
  - platform: template
    name: Last User
    id: last_user
    icon: mdi:clock-start  

sensor:

  - platform: template
    name: Keypad Code
    id: keyCode    
    on_value:
      - if:
          condition:
            - lambda: 'return id(keyCode).state == 1111;' 
          then:  
            - switch.toggle: OvrHead
            - text_sensor.template.publish:
                id: last_user
                state: "Justin's Code"          

      - if:
          condition:
            - lambda: 'return id(keyCode).state != 5553549;' 
            - lambda: 'return id(keyCode).state != 6422842;' 
            - lambda: 'return id(keyCode).state != 6722842;'
            - lambda: 'return id(keyCode).state != 6491970;'
            - lambda: 'return id(keyCode).state != 6753957;'
            - lambda: 'return id(keyCode).state != 1111;'
            - lambda: 'return id(keyCode).state != 1965;'
          then:
            - text_sensor.template.publish:
                id: last_user
                state: "Invalid User"