New to MQTT... couple Qs

Hi all,

I am a total noob with Node-Red and am struggling to connect Tasmota plus an ESP-Easy and getting them all to pub & sub.

I am trying to implement the following:
1x ESP32 with a toggle switch. (controller)
3x Sonoff 1ch flashed with Tasmota. (receivers)
1x Raspberry Pi 3B with Pi OS and the latest install of node-red.

What I want to do is publish the ESP32 switch toggle state change, subscribe to that state change on the 3x Tasmotas and toggle the relays .

I hope that makes sense, and is this possible? Any guidance for this application would be greatly appreciated.

Thanks
Andy

Well, yes, it is possible. However, it seems you are missing a quite important part of the MQTT setup, the broker.
Have you installed something like that? Typically mosquitto on your rpi would be the obvious choice.
GV

Hi, yes I have installed Aedes broker.

Andy

So, the idea is to use the "mqtt in" in node red to listen to the "pub" made by the controller and when the message is received to publish "mqtt out" what the sonoff will need to turn on.
Your flows in NodeRed will kind of translating what the ESP32 will publish into something the Sonoff can understand.
You need to know what message the ESP32 will publish and the message the Sonoff are subscribed to, in order to receive the order.

1 Like

How far have you got? Are you able to subscribe to the state on the Tasmota devices? That should be the easiest part.

Personally I recommend Mosquitto as the broker unless you have a reason to go with another. I have no experience with Aedes but provided it works then whichever you use it should not matter.

1 Like

I've looked at Aedes in the past and decided that it is only worth using if you need its integration features such as MongoDB and REDIS integration. Otherwise Mosquitto is reliable, small and fast. But I doubt this is the issue here anyway as you say.


I would start by setting up the controller and a simple NR flow to dump the controllers changes to debug. That should indeed be the easy bit.

Then I would connect the Sonoff's to the broker and make sure that manual button presses are resulting in expected output at the broker.

Finally, I would create my flow to connect the 2.

3 Likes

If you are not already familiar with the concepts of MQTT then I recommend this set of tutorials. Work through those and you will know pretty much everything you need to know about MQTT. https://www.hivemq.com/mqtt-essentials/

3 Likes

Hi, what is this as I am just getting started?

In that case I suggest watching the node-red essentials videos (linked from the docs I think). They will give you a good start in node-red.

Ok, RTFM, understood :slight_smile:

I didn't mean it quite like that :slight_smile:
You will save a lot of time in the long run by watching them I think. https://www.youtube.com/watch?v=ksGeUD26Mw0

1 Like
mqtt-in -->-- debug node

Where the MQTT-in node is configured to connect to your broker and listen for the topic that the controller outputs.

1 Like

Ok, got that part working ok, as follows in debug:

9/3/2020, 11:36:40 PMnode: bce7452a.dae148
control/switch : msg.payload : string[61]
"{"idx":1,"RSSI":10,"command":"switchlight","switchcmd":"Off"}"
9/3/2020, 11:36:42 PMnode: bce7452a.dae148
control/switch : msg.payload : string[60]
"{"idx":1,"RSSI":10,"command":"switchlight","switchcmd":"On"}"

Great. Now do the same for one of your SONOFF devices.

1 Like

MQTT-out?

No, start by listening for data from Tasmota.

1 Like

Ok, listening seems to be working ok on debug:

9/3/2020, 11:59:06 PMnode: d78e0865.698078
fan1/relay/RESULT : msg.payload : string[14]
"{"POWER":"ON"}"
9/3/2020, 11:59:06 PMnode: d78e0865.698078
fan1/relay/POWER : msg.payload : string[2]
"ON"
9/3/2020, 11:59:13 PMnode: d78e0865.698078
fan1/relay/RESULT : msg.payload : string[15]
"{"POWER":"OFF"}"

Ok, and I have added an MQTT-out node, configured it to pub to fan1/relay/POWER and connected "on" and "off" inject nodes, and it seems to be working ok (relay clicking and tasmota console updating).

9/4/2020, 12:34:30 AMnode: d78e0865.698078
fan1/relay/cmnd/POWER : msg.payload : string[2]
"ON"
9/4/2020, 12:34:30 AMnode: d78e0865.698078
fan1/relay/RESULT : msg.payload : string[14]
"{"POWER":"ON"}"
9/4/2020, 12:34:30 AMnode: d78e0865.698078
fan1/relay/POWER : msg.payload : string[2]
"ON"
9/4/2020, 12:34:33 AMnode: d78e0865.698078
fan1/relay/cmnd/POWER : msg.payload : string[3]
"OFF"
9/4/2020, 12:34:33 AMnode: d78e0865.698078
fan1/relay/RESULT : msg.payload : string[15]
"{"POWER":"OFF"}"
9/4/2020, 12:34:33 AMnode: d78e0865.698078
fan1/relay/POWER : msg.payload : string[3]
"OFF"
00:26:44 MQT: fan1/relay/RESULT = {"POWER":"OFF"}
00:26:44 MQT: fan1/relay/POWER = OFF
00:26:47 MQT: fan1/relay/RESULT = {"POWER":"ON"}
00:26:47 MQT: fan1/relay/POWER = ON
1 Like

I now need a little guidance connecting the "in" to the "out" if you will :slight_smile:

Have you watched the videos?