How to use switch node to publish an inject node to MQTT Broker

So, I am getting a temperature data from the MQTT broker and I want to publish a message which will overwrite a data that is on an OPC server, which looks like this;

"[{"id":"Visu+ UA Server.Visu+ SCADA.Tags.Start_Button","v":false}]"

When I use the inject node that is connected to the MQTT out node, it works and changes the data. But I only want it to work automatically when the other (temperature) data coming from the MQTT broker is less than "50". I used the switch node for this and I am able to get output when the comparison happens. My problem is, how do I use this "switch" node to inject a message into MQTT out node. I'm also copying the flow code here. Thanks in advance.

[{"id":"97527151.57977","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c8c0178d.388638","type":"mqtt in","z":"97527151.57977","name":"","topic":"iotgateway","qos":"1","datatype":"json","broker":"42bbbb0d.1b4ff4","nl":false,"rap":true,"rh":0,"x":460,"y":480,"wires":[["ca4e64d.53f1198"]]},{"id":"bcdd863a.a8cb18","type":"mqtt out","z":"97527151.57977","name":"","topic":"iotgateway/write","qos":"1","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"42bbbb0d.1b4ff4","x":940,"y":200,"wires":[]},{"id":"b7ac1935.42ee18","type":"inject","z":"97527151.57977","name":"Start_Value=False","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Message","payload":"[{\"id\":\"Visu+ UA  Server.Visu+ SCADA.Tags.Start_Button\",\"v\":false}]","payloadType":"str","x":490,"y":200,"wires":[["bcdd863a.a8cb18"]]},{"id":"ca4e64d.53f1198","type":"switch","z":"97527151.57977","name":"","property":"payload.values[0].v","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"str"},{"t":"gte","v":"50","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":480,"wires":[["d7bba128.d4f7a"],["7db978c6.f2df18"]]},{"id":"7db978c6.f2df18","type":"debug","z":"97527151.57977","name":">=50","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values[0].v","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":560,"wires":[]},{"id":"d7bba128.d4f7a","type":"debug","z":"97527151.57977","name":">50","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values[0].v","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":400,"wires":[]},{"id":"42bbbb0d.1b4ff4","type":"mqtt-broker","name":"","broker":"tcp://localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

If I understand you, you should add a change node on each side of the switch node to setup the msg and topic to be sent, then connect the output of the change nodes to the mqtt-out node.

I tried to do it like this but nothing's happening. I couldn't understand what you meant by adding a change node before the switch. What should it do before the switch?

[{"id":"97527151.57977","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c8c0178d.388638","type":"mqtt in","z":"97527151.57977","name":"","topic":"iotgateway","qos":"1","datatype":"json","broker":"42bbbb0d.1b4ff4","nl":false,"rap":true,"rh":0,"x":320,"y":280,"wires":[["ca4e64d.53f1198","6c5f1de5.8bec34","5e97d1a0.63993"]]},{"id":"bcdd863a.a8cb18","type":"mqtt out","z":"97527151.57977","name":"","topic":"iotgateway/write","qos":"1","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"42bbbb0d.1b4ff4","x":1100,"y":160,"wires":[]},{"id":"b7ac1935.42ee18","type":"inject","z":"97527151.57977","name":"Start_Value=False","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Message","payload":"[{\"id\":\"Visu+ UA  Server.Visu+ SCADA.Tags.Start_Button\",\"v\":false}]","payloadType":"json","x":490,"y":160,"wires":[["bcdd863a.a8cb18"]]},{"id":"ca4e64d.53f1198","type":"switch","z":"97527151.57977","name":"","property":"payload.values[0].v","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":280,"wires":[["87f6ca7a.00d4f8"]]},{"id":"87f6ca7a.00d4f8","type":"change","z":"97527151.57977","name":"","rules":[{"t":"set","p":"payload.values[0].v","pt":"msg","to":"[{\"id\":\"Visu+ UA  Server.Visu+ SCADA.Tags.Start_Button\",\"v\":false}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":280,"wires":[["bcdd863a.a8cb18"]]},{"id":"6c5f1de5.8bec34","type":"debug","z":"97527151.57977","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values[0].v","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":400,"wires":[]},{"id":"5e97d1a0.63993","type":"debug","z":"97527151.57977","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":480,"wires":[]},{"id":"42bbbb0d.1b4ff4","type":"mqtt-broker","name":"","broker":"tcp://localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Sorry,I meant after. I have a head cold and the neurons slow down going thru all the congestion.

This is what I mean.

[{"id":"97527151.57977","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"c8c0178d.388638","type":"mqtt in","z":"97527151.57977","name":"","topic":"iotgateway","qos":"1","datatype":"json","broker":"42bbbb0d.1b4ff4","x":460,"y":480,"wires":[["ca4e64d.53f1198"]]},{"id":"bcdd863a.a8cb18","type":"mqtt out","z":"97527151.57977","name":"","topic":"iotgateway/write","qos":"1","retain":"","broker":"42bbbb0d.1b4ff4","x":940,"y":200,"wires":[]},{"id":"b7ac1935.42ee18","type":"inject","z":"97527151.57977","name":"Start_Value=False","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Message","payload":"[{\"id\":\"Visu+ UA  Server.Visu+ SCADA.Tags.Start_Button\",\"v\":false}]","payloadType":"str","x":490,"y":200,"wires":[["bcdd863a.a8cb18"]]},{"id":"ca4e64d.53f1198","type":"switch","z":"97527151.57977","name":"","property":"payload.values[0].v","propertyType":"msg","rules":[{"t":"lt","v":"50","vt":"str"},{"t":"gte","v":"50","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":480,"wires":[["d7bba128.d4f7a","85b3c62.bcb5938"],["7db978c6.f2df18"]]},{"id":"7db978c6.f2df18","type":"debug","z":"97527151.57977","name":">=50","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values[0].v","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":560,"wires":[]},{"id":"d7bba128.d4f7a","type":"debug","z":"97527151.57977","name":">50","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values[0].v","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":480,"wires":[]},{"id":"85b3c62.bcb5938","type":"change","z":"97527151.57977","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"id\":\"Visu+ UA  Server.Visu+ SCADA.Tags.Start_Button\",\"v\":false}]","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":380,"wires":[["bcdd863a.a8cb18"]]},{"id":"42bbbb0d.1b4ff4","type":"mqtt-broker","name":"","broker":"tcp://localhost","port":"1883","clientid":"","usetls":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Oh it worked! Thank you very much :slight_smile: Hope you'll get better