What's the best way to send an MQTT command to all subscribed topics?

I may be daydreaming here, but I'm wondering if there's a way to dynamically send a command RESTART 1 to either all topics, or all sub-topics within a topic.

background info: I have dozens of tasmota devices around my house from outlets to relays to switches to bulbs. some of the switches are dimmer switches which I'm running older tasmota firmware with custom scripting on to manage/control the touch slider and LED arrays. I'm not the original writer of these scripts and I can't get them to work on newer versions of tasmota, so I'm kind of hamstrung here. these devices occasionally "lock up" and stop responding to physical interaction or HK/HB/tasmota control so I have to either load their HTTP interface or send MQTT restart commands.

These devices are few on my network and I could easily write a flow to reboot the four of them every night, but I'd like to do a system wide reboot. Since I'm regularly adding devices and sometimes removing/renaming devices, a manually programmed or static list of devices isn't ideal.

I'm confident that a script on my MQTT server could manage this, but ssh'ing into my server to manage it and having no real visibility into it isn't ideal either. I could script the individual devices with their own restart logic, but there's a comparable level of blindness and a comparable lack of control there.

determined to complete this within nodered, I'm thinking my options are:

  1. discover a way to make it work with wildcards, for instance: "cmnd/lighting/*/RESTART 1" I can't get this to work, and I don't think it would reasonably allow me to exclude any devices. there aren't any devices I want to exclude, but I like to think about the future.
  2. (learn how to) Write a function to get all subscribed topics, parse them, and generate restart commands from said list. This feels the most robust and future proof of all options.

Thanks in advance for any insight/guidance here. I'm admittedly pretty amateur with both nodered and MQTT.

Interesting conundrum. :slight_smile:

As far as I know, you cannot send to a wildcard, only subscribe to one.

However, while Node-RED's mqtt-out node similarly can only send to 1 topic at a time, it does allow the topic to be set from a msg.

That means that "all" you need to do is capture the list of devices (more accurately the list of device topics for a reset). Once you have that in an array flow variable, you can use the split node to generate multiple messages from the array data and so send a series of messages containing the same payload to the multiple topics.


If all the device reset topics follow a set pattern, you can use a mini-flow to subscribe to the appropriate wild card topic and "slowly" gather all of the device topics into a flow variable as an array. So that adding new devices or changing their ids would update the list so that the output command would work with them automatically.

Thank you! You have confirmed my fears.

I'll go ahead and muddle through that setup with the help of my forums and googles... that is, unless, you have any suggestions/pointers for proceeding down that path?

Cheers

Tasmota devices have a "group topic".

eg

21:59:15.931 CMD: grouptopic
21:59:15.938 MQT: stat/gosund/2/RESULT = {"GroupTopic1":"tasmotas","GroupTopic2":"","GroupTopic3":"","GroupTopic4":""}

And if I send topic: cmd/tasmotas/status, payload: 1
I get a reply from 4 Tasmota devices, suggesting that at least some of my Tasmota devices have GroupTopic1 set by default.

There is also the concept of a DeviceGroup in Tasmota. Not sure what that does different from GroupTopic.

Either you’re a genius, I’m a dunce, or somewhere in between. I’m already using device groups, but I set them so long ago I’ve forgotten. I have some devices with one and a few with two, but group3 seems ideal.

Thank you