That's a good question and there is a trick to it if certain things are done.
So, as I read it:
You send two messages. One to turn it on and the other to turn it off.
There is a quirk with MQTT
and sending messages.
All messages become a string.
So really you can't send true
and false
, because when they are received the become "true"
and "false"
.
It is a subtle difference, but enough to trip a new person.
There is also a trick with the switch
node.
You have to set it so the node indicates the input and to untick the "if message is received, send it to output."
Here is a very basic flow which does what I think you want to do.
What you have to understand is it is not using true
and false
to signal.
[{"id":"19c72ec5.517ec1","type":"debug","z":"b9924a74.4d98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":747,"y":3999,"wires":[]},{"id":"37622de9.6886b2","type":"mqtt in","z":"b9924a74.4d98f8","name":"","topic":"test","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":587,"y":3999,"wires":[["19c72ec5.517ec1"]]},{"id":"6cedf4eb.ad6e94","type":"ui_switch","z":"b9924a74.4d98f8","name":"","label":"switch","tooltip":"","group":"53792891.774238","order":12,"width":"3","height":"1","passthru":false,"decouple":"true","topic":"","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":270,"y":4000,"wires":[["dd8652.089a79b","19075bb6.a11ea4"]]},{"id":"dd8652.089a79b","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"test","qos":"","retain":"","broker":"378c0403.8cda04","x":440,"y":4000,"wires":[]},{"id":"4c072efb.0d50f","type":"mqtt in","z":"b9924a74.4d98f8","name":"","topic":"test","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":130,"y":4000,"wires":[["6cedf4eb.ad6e94","3be4856c.34e62a"]]},{"id":"3be4856c.34e62a","type":"debug","z":"b9924a74.4d98f8","name":"Receive","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":280,"y":3960,"wires":[]},{"id":"19075bb6.a11ea4","type":"debug","z":"b9924a74.4d98f8","name":"Send","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":440,"y":3960,"wires":[]},{"id":"79fce463.fe6a24","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":4130,"wires":[["13abeb5b.ca4aed"]]},{"id":"40f8573a.2fee88","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":4170,"wires":[["13abeb5b.ca4aed"]]},{"id":"13abeb5b.ca4aed","type":"mqtt out","z":"b9924a74.4d98f8","name":"","topic":"test","qos":"","retain":"","broker":"378c0403.8cda04","x":280,"y":4150,"wires":[]},{"id":"edf5d0c5.0c1d18","type":"comment","z":"b9924a74.4d98f8","name":"ESP device","info":"","x":680,"y":3960,"wires":[]},{"id":"a2520722.8a9978","type":"comment","z":"b9924a74.4d98f8","name":"Other device sending on/off signals.","info":"","x":220,"y":4090,"wires":[]},{"id":"378c0403.8cda04","type":"mqtt-broker","z":"","name":"MQTT HOST","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"53792891.774238","type":"ui_group","name":"Group 7","tab":"de5134a7.f0a0d","order":4,"disp":true,"width":6},{"id":"de5134a7.f0a0d","type":"ui_tab","name":"Tab 6","icon":"dashboard","order":5}]
After you have seen it working, change the inject
nodes and the switch
to using/sending true
and false
, and activate the two debug
nodes: Send
and Receive
and see the difference.
You will have to edit the MQTT
nodes to use your server.
And maybe edit where the switch
is. But that is more dressing than important.