'check' incoming mqtt message for correct PIN then respond accordingly

I’ve got an MQTT keypad that I want to use with Home Assistant to disarm my house alarm.

Anyone know how I would check that the incoming MQTT contains the correct PIN? Is it just a case of setting up an MQTT sensor: and checking the state of the sensor in an automation? Or is there a better/more efficient way?

This is the page that has the bare bones of the logic.

Thank you

I’m also trying to SEND JSON to the keypad via MQTT

    - service: mqtt.publish
      data_template:
      topic: "zigbee2mqtt/alarmkeypad"
      payload: >-
        {
          "set_status": { "panelstatus":"arming_away", "secondsremain":0, "audiblenotif":0, "alarmstatus":0 } 
        }

but I’m getting this error

Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][3]['data_template']. Got None
extra keys not allowed @ data['action'][3]['payload']. Got None
extra keys not allowed @ data['action'][3]['topic']. Got None. (See /config/configuration.yaml, line 1373).

You could do that or omit the sensor and just use an MQTT Trigger in the automation.

For the service call, minimally, all lines after data_template should be indented by an additional two spaces.

If you are using a recent version of Home Assistant, the data_template option was deprecated in favor of simply using data (which can be used for options that do or do not have templates). However, the use of data_template will only cause a warning message and isn’t responsible for the error message.

1 Like

Thank you, for the benefit of anyone coming after me, I was able to parse the incoming MQTT message like this (took many tries to to get the syntax/quotation marks right)

  - alias: 'Keypad Disarm'
    trigger:
     - platform: mqtt
       topic: zigbee2mqtt/alarmkeypad
    condition:
      - condition: template
        value_template: '{{ trigger.payload_json.action_code == "9999" }}'              
      - condition: template
        value_template: '{{ trigger.payload_json.action == "disarm" }}'
    action:
    - service: persistent_notification.create
      data_template:
        message: "Disarm!"
        title: DISARM
1 Like