Automation MQTT trigger not firing

I have an automation I want to trigger from a camera/motion_image topic. I can see in MQTT explorer the topic is being published to.

image

The topic is also used by an MQTT Camera entity and is working as expected there.
However my automation is never triggered (confirmed by trace) by this MQTT trigger. I have tried using a different topic (camera/motion) as a trigger and the automation runs correctly.
Is it possible the size of the payload (a ~600kb jpeg) is interfering with the trigger operation?

alias: Drive motion notification
description: ''
trigger:
  - platform: mqtt
    topic: camera/motion_image
    id: image
condition: []
action:
  - service: camera.snapshot
    data:
      filename: /extsd/ipwebcam/snapshot.jpg
    target:
      entity_id: camera.drive_motion_detection_image
  - device_id: ad91f0fdf7dae795ff215c2440663373
    domain: mobile_app
    type: notify
    message: |
      {{ trigger.id }}
    data: >
      {% set android_data = {"image": "%s"} |
      format("/media/camera/snapshot.jpg?authSig=REDACTED")
      %} {{ android_data }}
    title: Drive camera
mode: single

Hi!

I just happened to stumble on this exact issue yesterday. After quite a bit of digging around (gotta hate how the simplest things can take for ever with HA) I found out that the issue is that HA expects MQTT messages to have UTF-8 encoding. The trigger fails completely if you don’t set the encoding right which seems absolutely bonkers.

Anyways, you need to set the following in the MQTT trigger (yml-editor mode): encoding: ‘’

After adding that line the trigger works as expected. You can read more here: Automation Trigger - Home Assistant

1 Like

Amazing, that seems to have done the trick!