MQTT Triggered Automation

After reading the following: https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger, I have created the following 2 automations.

I can successfully trigger both automations via the HA GUI but I can’t seem to get the MQTT trigger to work.

My 2 automations:

  - alias: "mute while talking"
    trigger:
      platform: mqtt
      topic: hermes/dialogueManager/sessionStarted
      payload: '{ "siteId": "lounge" }'
    action:
      service: switch.turn_on
      entity_id: switch.soundbar_mute
  - alias: "finished talking"
    trigger:
      platform: mqtt
      topic: hermes/dialogueManager/sessionEnded
      payload: '{ "siteId": "lounge" }'
    action:
      service: switch.turn_off
      entity_id: switch.soundbar_mute

Am I missing something obvious?

Thanks

payload is watching for strings and your JSON payload may have a different string representation than expected.

You can subscribe to the topic and do the parsing in a condition:

- alias: "mute while talking"
  trigger:
    platform: mqtt
    topic: hermes/dialogueManager/sessionStarted
  condition:
    condition: template
    value_template: "{{ trigger.payload_json['siteId'] == 'lounge' }}"
  action:
    service: switch.turn_on
    entity_id: switch.soundbar_mute
1 Like

+1 with @m0wlheld

The HA extensions https://www.home-assistant.io/docs/configuration/templating/ provides useful info but it doesn’t explicitly detail how domains can be used such as trigger , entity , state and so on - in context sensitive blocks - when using template code in the various supporting yaml code blocks/structures. (as in the example above where trigger.payload is contextual where scoped to the trigger. For example, one can use entity.name in contexts where the template code is operating with an in-scope entity

1 Like