Manual alarm panel using code_template

Does anyone have a working example of the manual alarm panel setup using the “code_template” feature to support different codes for different states? In all my attempts, the numeric keypad fails to show in the UI and it is impossible to make any state change.

3 Likes

What you describe seems to be a bug in the Lovelace card of the Alarm Panel. See topic 3. below for details.
Here is a working code to demonstrate the use of code_template:

# configuration.yaml
alarm_control_panel:
  - platform: manual
    name: TV-Zugang
    code_template: >-
      {% if is_state('alarm_control_panel.tv_zugang', 'armed_home') %}
        111
      {% else %}
        222
      {% endif %}

Beware of the following pitfalls:

  1. Use >- to start the multiline template. A simple > will keep the line feeds in the result and will ruin your PIN codes.
  2. Do NOT put any quotes around the PIN codes. Those quotes would not be interpreted as string delimiters but would become part of the string itself and you would have to enter your PIN codes including quotes.
  3. There seems to be a long lasting bug in the Lovelace Alarm Control Panel card: In all my tests the numeric key pad vanished as soon as I used code_template instead of code. You can still use the card without the keypad but you have to enter the code through the normal keyboard instead of the on-screen keypad.
    I have just filed an issue for that problem.