New to MQTT... couple Qs

Once you have watched the videos then you need to formulate the problem in a way that you can solve it with node-red. So you might, for example, have a set of requirements like: When I receive a message from the MQTT In node with this content then I want to send a message to the MQTT Out node with some other content. To implement this you might need a Switch node (not the dashboard ui-switch node) to route messages from mqtt down particular paths, then possibly Change nodes to set message content to the required values.
When you get to that stage it is probably also worth reading the docs page Working with Messages.
When using a node make sure you look carefully at the help text for the node which will (believe it or not) often have useful information.

1 Like

Agree with Colin that the rest is so much the core Node-RED functionality it would be good to get an overview of what is possible and what are the common ways of solving issues.

However if you're like me and learn best by fast progress, I would believe a single change node after the switch input would do to change all 3 relays at once. It would need to:

  • move msg.switchcmd to msg.payload
  • change msg.payload from On to ON
  • change msg.payload from Off to OFF

I've not used Tasmota myself so I'm not sure if sending a payload of ON to fan1/relay/POWER is the right topic/payload combination but maybe you'll get the idea.

1 Like

Thanks a lot, that got me heading in the right direction, although I thing my solution may not be ideal.

Solved a problem and got this welder able to control extraction fans remotely, which is a real bonus.

Thanks to all.

2 Likes

If you want someone to look at the flow and suggest imporovements then export it and paste it here and I expect someone will that a look. Select the relevant nodes and then Ctrl+E and Copy to Clipboard. Then here use the </> button and paste it in.

I can do that... this is my change node... basically reducing the string to just on & off.

[{"id":"eb96c7bb.6b9818","type":"change","z":"ac5c3d8c.1c7c4","name":"Output","rules":[{"t":"change","p":"payload","pt":"msg","from":"On","fromt":"str","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"Off","fromt":"str","to":"OFF","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"switchcmd","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"switchlight","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"command","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"RSSI","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"idx","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":":","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\"","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"{","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"}","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":",","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"3","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"4","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"5","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"6","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"7","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"8","fromt":"num","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"9","fromt":"num","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":340,"wires":[["543922a7.a9fd6c","945f5fed.7fc","4782895a.5d7b38","aa151564.7c8f88"]]}]

Aargh no, that isn't the way to do it. Add a debug node showing us what you are getting from the MQTT In node and tell us what you want to convert that to.

In node red if it is difficult or messy that very often means you are not doing it the best way.

Edit. Also try setting the Output mode in the MQTT In node to Parsed Json and show us what it gives in a debug node.

hi Colin, Hit my 5-post limit earlier... see post#12 for input, and below for MQTT-out node.

[{"id":"945f5fed.7fc","type":"mqtt out","z":"ac5c3d8c.1c7c4","name":"fan1","topic":"fan1/relay/cmnd/POWER","qos":"2","retain":"","broker":"217c6d87.d2cc82","x":530,"y":280,"wires":[]},{"id":"217c6d87.d2cc82","type":"mqtt-broker","z":"","name":"PI_MQTT","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Did you see the edit I made to my post, suggesting changing the output to parsed JSON?

Just saw the edit...

9/5/2020, 12:21:21 AMnode: 543922a7.a9fd6c
control/switch : msg.payload : Object
object
idx: 1
RSSI: 7
command: "switchlight"
switchcmd: "On"

Excellent, now you have a JavaScript object rather than a string. Have you read the docs page working with messages?

Hold on though, shouldn't your input be the state of something rather than a command, or have I lost track of exactly what you are trying to do?

Here's the log output from the ESP32

3031779: SW  : GPIO=18 State=1 Output value=1
3032003: WD   : Uptime 51 ConnectFailures 0 FreeMem 207512 WiFiStatus 3
3035379: SW  : GPIO=18 State=0 Output value=0
3037579: SW  : GPIO=18 State=1 Output value=1
3040478: SW  : GPIO=18 State=0 Output value=0
3041978: SW  : GPIO=18 State=1 Output value=1
3044478: SW  : GPIO=18 State=0 Output value=0

and the configuration setup for the GPIO.

Ok, I see what you are doing.
So with the the js object you posted and the working with messages page you should be able to make some progress.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.