Zigbee2MQTT - Sync Keypad and Alarm Control Panel States

I ended up using alarmo and then I made these automations to control the keypad.

I use two keypad so this can be done much simpler.

1 Like

Awesome!
Thanks for your help :slight_smile:

Have you figured it out? I am at the same spot right now. Everything works except the arm_night_zones.

if you are a moron like me scratching your head thinking you have it setup perfectly. please check for upper/lower case naming you have set!

my friendly name was set to keypad and in the blueprint i had zigbee2mqqt/Keypad

renamed zigbee friendly name to Keypad and suprise suprise it now works!

Can I ask how you got this to work? The keypad paired fine. It seems to communicate with the automation in that it triggers it, and it seems to get responses back. If I arm the alarm, the keypad gets the message and glows red. If I run the actions in the blueprint by hand, it arms or disarms the alarm (using alarmo). But the keypad will never arm or disarm the alarm. The trace always looks the same (Option 6 executed). It seems like it is very nearly working, but some detail is wrong. Any help appreciated.

UPDATE: OK, I figured out that I needed to add another 4-digit code to Alarmo for the keypad. I made it the same as the keypad code, so not sure if it because they are the same, or because it needed to be 4 digits, or because it just needed to be a new slot. But now it works. alarm_night_zones is not working, so might try the modifications of @Tykan to the blueprint.

Great work @AndrejDelany ! Thank you for sharing.

I tried @Tykan 's modification, but it lacked some of the features of the original, so I modded the original instead. All I did was add the night arming feature available on both Alarmo and the Xfinity XHK1-UE keypad. Using this blueprint, you could easily program this button on the keypad to do some other function on your alarm panel, like arm vacation. It is a trivial change to @AndrejDelany 's original blueprint, so I will just add it here.

blueprint:
  name: PIN-Keypads for Zigbee2MQTT including Xfinity XHK1-UE
  description: This Blueprint allows the synchronisation of an alarm control panel
    with a Zigbee2MQTT keypad. This means that the status of the alarm control panel
    is transmitted to the keypad and vice versa.
  domain: automation
  input:
    z2m_keypad_path:
      name: MQTT State Topic of your Zigbee2MQTT Keypad
      description: 'The State Topic is composed of your Zigbee2MQTT base_topic (see
        your Z2M Addon Configuration) and the Friendly Name of your keypad in Z2M.
        Example: zigbee2mqtt/Keypad'
    z2m_keypad_path_set:
      name: MQTT Set Topic of your Zigbee2MQTT Keypad
      description: 'This is the same as your State Topic, with the addition of /set.
        Example: zigbee2mqtt/Keypad/set'
    pin:
      name: Pincode
      description: 'The valid pin code to be accepted as correct by your alarm system.
        Example: 1234'
    control_panel:
      name: Control Panel
      description: 'An alarm control panel. Example: https://www.home-assistant.io/integrations/manual'
      default: []
      selector:
        entity:
          domain:
          - alarm_control_panel
          multiple: false
    action_arming:
      name: Action Arming
      description: An action to be performed when the alarm panel changes to the arming
        state.
      default: []
      selector:
        action: {}
    action_armed_home:
      name: Action Armed Home
      description: An action to be performed when the alarm panel changes to the armed
        home state.
      default: []
      selector:
        action: {}
    action_armed_night:
      name: Action Armed Night
      description: An action to be performed when the alarm panel changes to the armed
        away state.
      default: []
      selector:
        action: {}
    action_armed_away:
      name: Action Armed Away
      description: An action to be performed when the alarm panel changes to the armed
        away state.
      default: []
      selector:
        action: {}
    action_disarmed:
      name: Action Disarmed
      description: An action to be performed when the alarm panel changes to the disarmed
        state.
      default: []
      selector:
        action: {}
    action_pending:
      name: Action Pending
      description: An action to be performed when the alarm panel changes to the pending
        state.
      default: []
      selector:
        action: {}
    action_panic:
      name: Action Panic
      description: An action to be performed when the panic / SOS button of the keypad
        is pressed.
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/zigbee2mqtt-sync-keypad-and-with-alarm-control-panel-states/345311
variables:
  pin_var: !input pin
trigger:
- platform: state
  entity_id: !input control_panel
  to: arming
  id: panel_arming
- platform: state
  entity_id: !input control_panel
  to: armed_home
  id: panel_armed_home
- platform: state
  entity_id: !input control_panel
  to: armed_night
  id: panel_armed_night
- platform: state
  entity_id: !input control_panel
  to: disarmed
  id: panel_disarmed
- platform: state
  entity_id: !input control_panel
  to: armed_away
  id: panel_armed_away
- platform: state
  entity_id: !input control_panel
  to: pending
  id: panel_pending
- platform: mqtt
  topic: !input z2m_keypad_path
  id: keypad_mqtt
condition: []
action:
- choose:
  - conditions:
    - condition: trigger
      id: panel_arming
    sequence:
    - choose:
      - conditions:
        - condition: state
          entity_id: !input control_panel
          state: armed_home
          attribute: next_state
        sequence:
        - service: mqtt.publish
          data_template:
            topic: !input z2m_keypad_path_set
            payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_day_zones\"\n  }\n}"
      - conditions:
        - condition: state
          entity_id: !input control_panel
          state: armed_night
          attribute: next_state
        sequence:
        - service: mqtt.publish
          data_template:
            topic: !input z2m_keypad_path_set
            payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_night_zones\"\n  }\n}"
      - conditions:
        - condition: state
          entity_id: !input control_panel
          state: armed_away
          attribute: next_state
        sequence:
        - service: mqtt.publish
          data_template:
            topic: !input z2m_keypad_path_set
            payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"exit_delay\"\n  }\n}"
      default: []
    - choose:
      default: !input action_arming
  - conditions:
    - condition: trigger
      id: panel_armed_away
    sequence:
    - service: mqtt.publish
      data_template:
        topic: !input z2m_keypad_path_set
        payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_all_zones\"\n  }\n}"
    - choose:
      default: !input action_armed_away
  - conditions:
    - condition: trigger
      id: panel_disarmed
    sequence:
    - service: mqtt.publish
      data_template:
        topic: !input z2m_keypad_path_set
        payload: "{\n \"arm_mode\": \n  {\n    \"mode\": \"disarm\"\n  }\n}"
    - choose:
      default: !input action_disarmed
  - conditions:
    - condition: trigger
      id: panel_armed_home
    sequence:
    - service: mqtt.publish
      data_template:
        topic: !input z2m_keypad_path_set
        payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_day_zones\"\n  }\n}"
    - choose:
      default: !input action_armed_home
  - conditions:
    - condition: trigger
      id: panel_armed_night
    sequence:
    - service: mqtt.publish
      data_template:
        topic: !input z2m_keypad_path_set
        payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_night_zones\"\n  }\n}"
    - choose:
      default: !input action_armed_night
  - conditions:
    - condition: trigger
      id: panel_pending
    sequence:
    - choose:
      default: !input action_pending
  - conditions:
    - condition: trigger
      id: keypad_mqtt
    sequence:
    - choose:
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_transaction != null and
            trigger.payload_json.action_code == pin_var }}'
        sequence:
        - service: mqtt.publish
          data_template:
            topic: !input z2m_keypad_path_set
            payload: "{\n \"arm_mode\": \n  {\n    \"transaction\": \"{{ trigger.payload_json.action_transaction
              }}\",\n    \"mode\": \"{{ trigger.payload_json.action }}\"\n  }\n}"
    - choose:
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_code == pin_var and trigger.payload_json.action
            == "arm_all_zones" }}'
        sequence:
        - service: alarm_control_panel.alarm_arm_away
          target:
            entity_id: !input control_panel
          data:
            code: !input pin
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_code == pin_var and trigger.payload_json.action
            == "arm_night_zones" }}'
        sequence:
        - service: alarm_control_panel.alarm_arm_night
          target:
            entity_id: !input control_panel
          data:
            code: !input pin
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_code == pin_var and trigger.payload_json.action
            == "arm_day_zones" }}'
        sequence:
        - service: alarm_control_panel.alarm_arm_home
          target:
            entity_id: !input control_panel
          data:
            code: !input pin
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_code == pin_var and trigger.payload_json.action
            == "disarm" }}'
        sequence:
        - service: alarm_control_panel.alarm_disarm
          target:
            entity_id: !input control_panel
          data:
            code: !input pin
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action == "panic" }}'
        sequence:
        - choose:
          default: !input action_panic
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action_code != pin_var and trigger.payload_json.action_code
            | int(-1) != -1 }}'
        sequence:
        - service: mqtt.publish
          data_template:
            topic: !input z2m_keypad_path_set
            payload: "{\n \"arm_mode\": \n  {\n   \"transaction\": \"{{ trigger.payload_json.action_transaction
              }}\",\n   \"mode\": \"invalid_code\"\n  }\n}"
      - conditions:
        - condition: template
          value_template: '{{ trigger.payload_json.action == None }}'
        sequence:
        - choose:
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: armed_away
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_all_zones\"\n
                  \ }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: armed_home
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_day_zones\"\n
                  \ }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: armed_night
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_night_zones\"\n
                  \ }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: disarmed
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"disarm\"\n  }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: arming
            - condition: state
              entity_id: !input control_panel
              state: armed_home
              attribute: next_state
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_day_zones\"\n
                  \ }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: arming
            - condition: state
              entity_id: !input control_panel
              state: armed_night
              attribute: next_state
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_night_zones\"\n
                  \ }\n}"
          - conditions:
            - condition: state
              entity_id: !input control_panel
              state: arming
            - condition: state
              entity_id: !input control_panel
              state: armed_away
              attribute: next_state
            sequence:
            - service: mqtt.publish
              data_template:
                topic: !input z2m_keypad_path_set
                payload: "{\n \"arm_mode\": \n  {\n   \"mode\": \"arm_all_zones\"\n
                  \ }\n}"
      default: []
  default: []
mode: parallel
max: 10

1 Like

I’m having trouble importing this and keep getting

No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax
any suggestions?

I have tried editing it as an automation directly but struggling as my yaml skills are rather limited.

Did you check in the blueprints/automation/AndrejDelany folder to see if you have the yaml file there? You might need to restart HA.

Good luck.

1 Like

Wasn’t there so I created it and the blueprint is now available, haven’t got it working exactly as I wanted but at least I now have something to work with.

Many thanks for helping me out :+1:
.
And obviously many thanks to @AndrejDelany for the blueprint :+1:

Is there any way to extend this Blueprint to support additional usage of codes - i.e. 8888 = turn off the lights, 7777 = open my garage door

I love this idea! Will have a look into it, but don’t expect it to happen right now as I’m on vacation.

Thanks - Enjoy!

Hello,

unfortunately the import button seems to be broken.
I can’t import as the link doesn’t point to a valid YAML file.
My I kindly ask the author to fix this? Or provide a link to github or similar?

Thanks!

2 Likes

@semtex as the developer is sharing his code you can easily grab it and create your own thankfully. Just Create copy it in .yaml (whatever his name) and place it in /config/blueprint/automation . Then reload your yaml config in Development tools, it should appears in your Blueprints .
@AndrejDelany A big thanks, now I can enjoy my Frient Keypad, it works like a charm :+1:

1 Like

Actually, I don’t know why the automatic import is not working anymore. I someone has I hint why, I will fix it.

Seems like the Import Bluetooth link refers to this page rather than point to actual page where the blueprint resides at. For example, when I try to import this blueprint, on the HA diaglog, the Blueprint address shows up as:

https://community.home-assistant.io/t/zigbee2mqtt-sync-keypad-and-alarm-control-panel-states/345311

However, if I try to add another blueprint from here (for example, Pause Climate Entity…
Pause climate entity when window/ door open ), on the HA dialog the following address shows up:

   https://gist.github.com/raffy-ops/2bdf967036d8d274fb1f62572ed5e545

So if you fix the link to point to actual page/site where the blueprint is hosted, it should work.

1 Like

I have now figured out what the problem is. Home Assistant can apparently only import the yaml code from this forum if there is only one code element in the first post. I have now marked the example code for the alarm panel as a quote rather than code. Now it works.

Just checking if you are still considering adding this feature… Thanks

1 Like

Hi, yes the same, for countdown I use the siren instead

Your requested feature has now been added :slight_smile:
I always appreciate feedback after you have tested it.