Hi all, I need some help understanding how to make an MQTT Automation trigger work.
I read the MQTT Automation trigger doc (link), and to my understanding, I am doing everything right.
I am trying to trigger an automation when an invalid code is an input in Alamo. Alarmo returns HA this information via MQTT:
Topic: alarm/event
Payload:
{
"event": "INVALID_CODE_PROVIDED"
}
I got this payload from listening to the topic in HA, so I am getting this information.
In my automation, I have the following trigger:
platform: mqtt
topic: alarmo/state
id: alarmo_state_invalid_code
payload: INVALID_CODE_PROVIDED
value_template: "{{ value_json.event }}"
From what I could get from the documentation using the value_template: "{{ value_json.event }}"
should extract the event key value from the JSON payload and compare it against the payload value INVALID_CODE_PROVIDED
. However, that is not happening.
Full automation for reference:
It is rather long as I am integrating Alarmo and a ZHA PIN PAD. All the other triggers are working fine:
alias: "Alarmo - ZHA Alarm Panel to MQTT "
description: ""
trigger:
- platform: event
event_type: zha_event
event_data:
device_ieee: xx:xx:xx:xx:xx:xx:xx:xx
args:
arm_mode_description: Disarm
id: disarm
- platform: event
event_type: zha_event
event_data:
device_ieee: xx:xx:xx:xx:xx:xx:xx:xx
args:
arm_mode_description: Arm_Day_Home_Only
id: arm_home
- platform: event
event_type: zha_event
event_data:
device_ieee: xx:xx:xx:xx:xx:xx:xx:xx
args:
arm_mode_description: Arm_All_Zones
id: arm_away
- platform: event
event_type: zha_event
event_data:
device_ieee: xx:xx:xx:xx:xx:xx:xx:xx
args:
arm_mode_description: Arm_Night_Sleep_Only
id: arm_night
- platform: mqtt
topic: alarmo/state
id: alarmo_state_disarmed
payload: disarmed
- platform: mqtt
topic: alarmo/state
id: alarmo_state_armed_home
payload: armed_home
- platform: mqtt
topic: alarmo/state
id: alarmo_state_armed_away
payload: armed_away
- platform: mqtt
topic: alarmo/state
id: alarmo_state_armed_night
payload: armed_night
- platform: mqtt
topic: alarmo/state
id: alarmo_state_armed_arming
payload: arming
- platform: mqtt
topic: alarmo/state
id: alarmo_state_invalid_code
payload: INVALID_CODE_PROVIDED
value_template: "{{ value_json.event }}"
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: disarm
sequence:
- service: mqtt.publish
data:
topic: alarmo/command
payload_template: >-
{ "command": "DISARM", "code": "{{ trigger.event.data.args.code
}}" }
- conditions:
- condition: trigger
id: arm_home
sequence:
- service: mqtt.publish
data:
topic: alarmo/command
payload_template: >-
{ "command": "ARM_HOME", "code": "{{
trigger.event.data.args.code }}" }
- conditions:
- condition: trigger
id: arm_away
sequence:
- service: mqtt.publish
data:
topic: alarmo/command
payload_template: >-
{ "command": "ARM_AWAY", "code": "{{
trigger.event.data.args.code }}" }
- conditions:
- condition: trigger
id: arm_night
sequence:
- service: mqtt.publish
data:
topic: alarmo/command
payload_template: >-
{ "command": "ARM_NIGHT", "code": "{{
trigger.event.data.args.code }}" }
default: []
- choose:
- conditions:
- condition: trigger
id: alarmo_state_disarmed
- condition: not
conditions:
- condition: device
device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: alarm_control_panel
entity_id: alarm_control_panel.front_door_alarm_pinpad_alarmcontrolpanel
type: is_disarmed
sequence:
- device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: alarm_control_panel
entity_id: alarm_control_panel.front_door_alarm_pinpad_alarmcontrolpanel
type: disarm
code: "00000"
- service: notify.notify
data:
message: clear_notification
data:
tag: alarmo
- service: notify.notify
data:
title: Alarmo
message: Home alarm Disarmed.
data:
tag: alarmo
- conditions:
- condition: trigger
id: alarmo_state_armed_home
sequence:
- device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: alarm_control_panel
entity_id: alarm_control_panel.front_door_alarm_pinpad_alarmcontrolpanel
type: arm_home
code: "00000"
- service: notify.notify
data:
message: clear_notification
data:
tag: alarmo
- service: notify.notify
data:
title: Alarmo
message: Home alarm Armed Home.
data:
tag: alarmo
- conditions:
- condition: trigger
id: alarmo_state_armed_away
sequence:
- device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: alarm_control_panel
entity_id: alarm_control_panel.front_door_alarm_pinpad_alarmcontrolpanel
type: arm_away
code: "00000"
- service: notify.notify
data:
message: clear_notification
data:
tag: alarmo
- service: notify.notify
data:
title: Alarmo
message: Home alarm Armed Away.
data:
tag: alarmo
- conditions:
- condition: trigger
id: alarmo_state_armed_night
sequence:
- device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
domain: alarm_control_panel
entity_id: alarm_control_panel.front_door_alarm_pinpad_alarmcontrolpanel
type: arm_night
code: "00000"
- service: notify.notify
data:
message: clear_notification
data:
tag: alarmo
- service: notify.notify
data:
title: Alarmo
message: Home alarm Armed Night.
data:
tag: alarmo
- conditions:
- condition: trigger
id: alarmo_state_armed_arming
sequence:
- service: notify.notify
data:
title: Alarmo
message: Home alarm is arming.
data:
tag: alarmo
- conditions:
- condition: trigger
id: alarmo_state_invalid_code
sequence:
- service: notify.notify
data:
title: Alarmo
message: An invalid code was used to arm or disarm the Home Alarm.
data:
tag: alarmo
default: []
mode: single
EDIT:
Solution Explanation: I was using the wrong MQTT topic. The error event is returned at alarmo/event
, not alarmo/status