Sub Pub loop... :<

Hello,

I am fairly new to Node-RED and have been stuck on this one issue going into week two here.. I have an ESP8266 controlling a relay and a touch switch that also controls the relay. Simple as this seems, when I toggle the power on from the UI or the switch I drop into a loop and I cannot figure out how to circumvent this..

My flow if this helps

 [{"id":"c4c9280f.8a10c8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"43882981.be16a8","type":"debug","z":"c4c9280f.8a10c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":360,"wires":[ ]},{"id":"b681cd55.407de","type":"mqtt out","z":"c4c9280f.8a10c8","name":"SUB Output - masterbed/light/state","topic":"masterbed/light/state","qos":"2","retain":"","broker":"9b92d4c7.9761f8","x":1040,"y":460,"wires":[]},{"id":"7a84ae6a.775c1","type":"ui_switch","z":"c4c9280f.8a10c8","name":"","label":"Light Switch","tooltip":"","group":"5772cf6f.359d1","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","topicType":"str","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","animate":true,"x":670,"y":460,"wires":[["43882981.be16a8","b681cd55.407de"]]},{"id":"912c69cc.6aa638","type":"mqtt in","z":"c4c9280f.8a10c8","name":"PUB Input - masterbed/light/state","topic":"masterbed/light/state","qos":"2","datatype":"auto","broker":"9b92d4c7.9761f8","x":310,"y":460,"wires":[["7a84ae6a.775c1"]]},{"id":"3f860de6.dd4152","type":"inject","z":"c4c9280f.8a10c8","name":"Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"masterbed/light/state","payload":"1","payloadType":"str","x":430,"y":640,"wires":[["7a84ae6a.775c1"]]},{"id":"924c12de.adee8","type":"inject","z":"c4c9280f.8a10c8","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"masterbed/light/state","payload":"0","payloadType":"str","x":430,"y":580,"wires":[["7a84ae6a.775c1"]]},{"id":"9b92d4c7.9761f8","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5772cf6f.359d1","type":"ui_group","name":"Bedroom Light","tab":"6e47d42d.482f1c","order":1,"disp":true,"width":"6","collapse":false},{"id":"6e47d42d.482f1c","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Welcome to the forum @ThisGuiii

In the switch clear the Message Pass Through checkbox, and set it Show State of Input.

I chose to put similar logic into the ESP32 I'm using instead of NR. If you want to go that route I'll share the code with you.

I have sunk so much time into this one snag, worn out three pages deep on google searches many times..
That did the trick! Thank you so much!

Hey LosinIt,

If you wouldn't mind, I'd like to see what code you have in production.

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