Mqtt topic wildcard


I have an automation which works for a single switch (tasmota mini). However, I have more switches, each with a different topic, based on the sonoff mini serial number. I would like the automation to run if any of the tasmota switches sends the command matching the template.

Are there some wildcard characters or some other method I can add to the topic line in the trigger to make this work?

Current automation below:

- id: '1640192821228'
  alias: Turn off all lights
  description: ''
  - platform: mqtt
    topic: "stat/tasmota_EA268D/RESULT"
  - condition: template
    value_template: "{{ trigger.payload_json['Switch1']['Action'] == 'HOLD'}}"
  - service: light.turn_off
      entity_id: light.little_house_lights
  mode: single

Thanks for you help.

Yes. Refer to the Wildcard section here:

You’ll probably want to use the + wildcard.

    topic: "stat/+/RESULT"

However, if the second level within the topic can represent more devices than just the switches then the condition will need modification.

1 Like

Many thanks for the tip and the link. The explanation of how the MQTT wildcards work was exactly what I was looking for.

Tested and working.


1 Like

Is this still current? I’m trying to organise ESpresense devices:

  qos: 0
  retain: false
  topic: "espresense/rooms/+/exclude"
  payload: >-
    node:study node:lounge node:kitchen node:north_study
    node:pantry node:bedroom node:kids_bedroom node:bathroom

But I get the error : Wildcards cannot be used in topic names for dictionary value @ data[‘topic’]. Got None

AFAIK, it works for listening, not for publishing.