Hi,
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: ''
trigger:
- platform: mqtt
topic: "stat/tasmota_EA268D/RESULT"
condition:
- condition: template
value_template: "{{ trigger.payload_json['Switch1']['Action'] == 'HOLD'}}"
action:
- service: light.turn_off
target:
entity_id: light.little_house_lights
mode: single
Thanks for you help.
123
(Taras)
February 6, 2022, 1:58pm
2
Yes. Refer to the Wildcard section here:
Learn about MQTT Topics, naming conventions, MQTT $SYS topics, MQTT Prefix, MQTT Topic Wildcards, and more in this MQTT Essentials article.
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.
Thanks
1 Like
MickW69
(Michael)
March 13, 2023, 1:59am
4
Is this still current? I’m trying to organise ESpresense devices:
data:
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
francisp
(Francis)
March 13, 2023, 5:11am
5
AFAIK, it works for listening, not for publishing.