Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'payload_json'

Hi, and thank you in advance for your support!

I’m trying to implement the following Frigate Automation, re Home Assistant notifications | Frigate
and I receive the following error when I run/test the automation.
Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘payload_json’
Could you please help troubleshoot the automation?

the automation:

id: '1667754760785'
alias: Front Door Snapshot Fired
description: ''
trigger:
  - platform: mqtt
    topic: frigate/events
    payload: switch.frontdoor_snapshots
condition: []
action:
  - service: notify.mobile_app_be2015
    data:
      title: Someone is at the front door!
      message: Dingdong, who is at the front door?
    data_template:
      message: A {{trigger.payload_json["after"]["label"]}} was detected.
      data:
        image: >-
          https://externalURL/api/frigate/notifications/{{trigger.payload_json["after"]["id"]}}/snapshot.jpg?format=android
        tag: '{{trigger.payload_json["after"]["id"]}}'
        when: '{{trigger.payload_json["after"]["start_time"]|int}}'
mode: single

You created an MQTT Trigger that triggers exclusively when the received payload contains the string “switch.frontdoor_snapshots”.

By using this:

trigger.payload_json["after"]["label"]

you expect the received payload will be in JSON format and contain “after” and “label” keys.

Why do you expect the payload to contain something different from what you specifically asked for in the MQTT Trigger (switch.frontdoor_snapshots)?

Is it possible that you want the MQTT Trigger to trigger for any received payload? In that case, simply remove payload: switch.frontdoor_snapshots.

1 Like

@123 Taras, thank you for pointing that out. I need to pay better attention to the code!