How to use the mqtt payload in action?

Hi

I’m currently trying since two hours how to get the value from the payload:

This what I have

Zigbee2MQTT:info  2021-01-17 23:11:20: MQTT publish: topic 'zigbee2mqtt/centralite', payload '{"action":"disarm","action_code":"1234","action_transaction":36,"action_zone":0,"battery":42,"linkquality":150,"temperature":21.8,"voltage":2900}'
Zigbee2MQTT:info  2021-01-17 23:11:20: MQTT publish: topic 'zigbee2mqtt/centralite', payload '{"action":"","battery":42,"linkquality":150,"temperature":21.8,"voltage":2900}'
Zigbee2MQTT:info  2021-01-17 23:11:20: MQTT publish: topic 'zigbee2mqtt/centralite/action', payload 'disarm'

And This is what I have as automation:

  trigger:
    - platform: mqtt
      topic: zigbee2mqtt/centralite
  condition:
    - condition: template
      value_template: "{{ 'disarm' in trigger.payload }}"
    - condition: or
      conditions:
       - condition: state
         entity_id: alarm_control_panel.alarm
         state: armed_home
       - condition: state
         entity_id: alarm_control_panel.alarm
         state: armed_away
  action:
    service: alarm_control_panel.alarm_disarm
    data_template:
      entity_id: alarm_control_panel.alarm
      code: '{{trigger.payload.action_code}}'

The automation is triggered so trigger + conditions seems OK. But the code is wrong because my alarm is still ‘armed’

What I can miss ? :frowning:

Thank you

try

value_template: '{{ "disarm" == trigger.payload_json.action }}'

and

code: '{{ trigger.payload_json.action_code }}'

nice thank you, in 2 minutes you find the solution !

However, how can I know it was the good syntax ? I tried 15 different threads and I never see payload_json :frowning:

I think some docs are missing on this part. About MQTT for trigger, action, condition ect it’s so difficult to find something and up to date ! :slight_smile:

1 Like