Struggling with switch state feedback

Hi, I have a tasmota flashed switch that I have successfully connected to node-red via mqtt, and am able to turn switch off/on via node-red UI. Mosquitto and Node-red are both hosted on the same local pi. Node red version 1.0.5.

what doesn't work is providing status from the tasmota device back to node-red switch node if I manually turn it off or on. I actually didn't realize this until I found and connected BLYNK this week, so of course the switch doesn't provide feedback to Blynk either. However I am able to turn the switch off/on via Blynk in the shown flow.

in the attached flow, the switch node has indicator set to OUPUT, otherwise it doesn't seem to work. with it set to INPUT or passthrough the switch does not work. I initially had the blynk write event connected to input of the switch, but then the switch doesn't work. the blynk node 'update widget' is currently not connected as it prevents the blynk write from working.

at this point I am utterly confused. I stripped this back down to only the tasmota device with the node-red switch but still can't get the feedback to come back to reflect on the switch status. Tried PaulReed's older example and others that I found but still cannot get this to work. Where am I going wrong?

[{"id":"18e20935.de7437","type":"tab","label":"sonoff2 test","disabled":false,"info":""},{"id":"f012fd0d.28e95","type":"mqtt in","z":"18e20935.de7437","name":"sonoffswitch/cmnd/state","topic":"sonoffswitch/cmnd/state","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":330,"y":240,"wires":[["75078390.20798c","be7e343f.2fd478"]]},{"id":"9f8f4e11.698da","type":"mqtt in","z":"18e20935.de7437","name":"sonoffswitch/tele/STATE","topic":"sonoffswitch/tele/STATE","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":410,"y":140,"wires":[["75078390.20798c","6bea0b3d.04e724"]]},{"id":"3892cca9.c3cf54","type":"inject","z":"18e20935.de7437","name":"","topic":"sonoffswitch/cmnd/power","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":300,"wires":[["f827129b.83fb1"]]},{"id":"999b8169.44c62","type":"inject","z":"18e20935.de7437","name":"","topic":"sonoffswitch/cmnd/power","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":360,"wires":[["f827129b.83fb1","75078390.20798c"]]},{"id":"be7e343f.2fd478","type":"debug","z":"18e20935.de7437","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":810,"y":320,"wires":[]},{"id":"3cedc218.91ffde","type":"ui_switch","z":"18e20935.de7437","name":"Sonoff2","label":"Sonoff2test","tooltip":"","group":"c9cb9a99.fd7158","order":3,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"sonoffswitch/cmnd/power","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":640,"y":500,"wires":[["f827129b.83fb1","be7e343f.2fd478"]]},{"id":"f827129b.83fb1","type":"mqtt out","z":"18e20935.de7437","name":"sonoffswitch/cmnd/power","topic":"sonoffswitch/cmnd/power","qos":"2","retain":"true","broker":"e5102fc8.e43f8","x":830,"y":380,"wires":[]},{"id":"79fc7e37.9fc19","type":"change","z":"18e20935.de7437","name":"change 0 to off","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":520,"wires":[["f827129b.83fb1"]]},{"id":"21fa7d85.81e702","type":"change","z":"18e20935.de7437","name":"change 1 to on","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":440,"wires":[["be7e343f.2fd478","f827129b.83fb1"]]},{"id":"a317a1f6.8004f","type":"blynk-ws-in-write","z":"18e20935.de7437","name":"","pin":"21","pin_all":0,"client":"fcb61c07.82a5f","x":140,"y":460,"wires":[["21fa7d85.81e702","79fc7e37.9fc19"]]},{"id":"75078390.20798c","type":"change","z":"18e20935.de7437","name":"change on to 1","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":140,"wires":[[]]},{"id":"6bea0b3d.04e724","type":"change","z":"18e20935.de7437","name":"change off to 0","rules":[{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":240,"wires":[[]]},{"id":"b058d95d.ba6428","type":"blynk-ws-out-write","z":"18e20935.de7437","name":"update widget","pin":"21","pinmode":0,"client":"fcb61c07.82a5f","x":960,"y":200,"wires":[]},{"id":"e5102fc8.e43f8","type":"mqtt-broker","z":"","name":"localhost:1883","broker":"localhost:1883","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c9cb9a99.fd7158","type":"ui_group","z":"","name":"Lamp","tab":"bb3a78b2.a93268","order":1,"disp":true,"width":"6","collapse":false},{"id":"fcb61c07.82a5f","type":"blynk-ws-client","z":"","name":"Blynk cloud","path":"ws://blynk-cloud.com/websockets","key":"blah","dbg_all":true,"dbg_read":false,"dbg_write":false,"dbg_notify":false,"dbg_mail":false,"dbg_prop":false,"dbg_sync":false,"dbg_bridge":false,"dbg_low":false,"dbg_pins":"","multi_cmd":false,"proxy_type":"no","proxy_url":"","enabled":true},{"id":"bb3a78b2.a93268","type":"ui_tab","z":"","name":"Switches","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Played with some of the node settings this weekend but no luck. Also updated to nodered 1.0.6 since I saw that came out. any advice on where I should start?

Looking at the image of your flow you don't appear to have connected anything into the input of the switch. If you feed in payload values exactly equal to the On and Off payload values you have configured in the node then that will change the switch state. Make sure Pass Through is disabled or you will get a loop setup.
Test it by connecting inject nodes in the front first to make sure you are able to change the state by clicking the inject buttons.

1 Like

Thank you Colin. Your clarification of EXACT values got me looking down the right path. I had mistakenly thought that when using the change node and 'change' operation, if anything in the payload matched, it would replace the entire contents of the payload. Not the case of course. After going down that trail and solving it I finally got everything working. I doubt its the cleanest way but using any of the node red UI switch, Blynk app button or the physical sonoff/tasmota switch, it all works now including state syncing between all 3.

[{"id":"18e20935.de7437","type":"tab","label":"sonoff2 test","disabled":false,"info":""},{"id":"f012fd0d.28e95","type":"mqtt in","z":"18e20935.de7437","d":true,"name":"sonoffswitch/cmnd/state","topic":"sonoffswitch/cmnd/state","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":170,"y":100,"wires":[["be7e343f.2fd478"]]},{"id":"9f8f4e11.698da","type":"mqtt in","z":"18e20935.de7437","d":true,"name":"sonoffswitch/tele/STATE","topic":"sonoffswitch/tele/STATE","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":170,"y":40,"wires":[["be7e343f.2fd478"]]},{"id":"3892cca9.c3cf54","type":"inject","z":"18e20935.de7437","name":"","topic":"sonoffswitch/cmnd/power","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":320,"wires":[["3cedc218.91ffde","f827129b.83fb1"]]},{"id":"999b8169.44c62","type":"inject","z":"18e20935.de7437","name":"","topic":"sonoffswitch/cmnd/power","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":360,"wires":[["3cedc218.91ffde","f827129b.83fb1"]]},{"id":"be7e343f.2fd478","type":"debug","z":"18e20935.de7437","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":430,"y":240,"wires":[]},{"id":"3cedc218.91ffde","type":"ui_switch","z":"18e20935.de7437","name":"Sonoff2","label":"Sonoff2test","tooltip":"","group":"c9cb9a99.fd7158","order":3,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"sonoffswitch/cmnd/power","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":680,"y":300,"wires":[["f827129b.83fb1"]]},{"id":"f827129b.83fb1","type":"mqtt out","z":"18e20935.de7437","name":"sonoffswitch/cmnd/power","topic":"sonoffswitch/cmnd/power","qos":"2","retain":"true","broker":"e5102fc8.e43f8","x":930,"y":420,"wires":[]},{"id":"21fa7d85.81e702","type":"change","z":"18e20935.de7437","name":"change 1 to on","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"on","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":420,"wires":[["3cedc218.91ffde","f827129b.83fb1"]]},{"id":"a317a1f6.8004f","type":"blynk-ws-in-write","z":"18e20935.de7437","name":"Blynk sonoff button","pin":"21","pin_all":0,"client":"fcb61c07.82a5f","x":170,"y":420,"wires":[["21fa7d85.81e702"]]},{"id":"75078390.20798c","type":"change","z":"18e20935.de7437","name":"change on to 1","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":100,"wires":[["5b187dee.ffdf34"]]},{"id":"3c7be4d6.0ae8bc","type":"mqtt in","z":"18e20935.de7437","name":"sonoffswitch/stat/RESULT","topic":"sonoffswitch/stat/RESULT","qos":"2","datatype":"auto","broker":"e5102fc8.e43f8","x":170,"y":160,"wires":[["2bf1c90d.91a936","be7e343f.2fd478"]]},{"id":"2bf1c90d.91a936","type":"change","z":"18e20935.de7437","name":"pull out switch state","rules":[{"t":"change","p":"payload","pt":"msg","from":"{\"POWER\":\"OFF\"}","fromt":"str","to":"off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"{\"POWER\":\"ON\"}","fromt":"str","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":160,"wires":[["3cedc218.91ffde","75078390.20798c","3778093e.769cd6"]]},{"id":"3778093e.769cd6","type":"blynk-ws-out-set-property","z":"18e20935.de7437","name":"Blynk button color ON","pin":"21","pinmode":0,"prop":"onLabel","client":"fcb61c07.82a5f","x":920,"y":160,"wires":[]},{"id":"5b187dee.ffdf34","type":"blynk-ws-out-write","z":"18e20935.de7437","name":"Blync button on/off","pin":"21","pinmode":0,"client":"fcb61c07.82a5f","x":910,"y":100,"wires":[]},{"id":"e5102fc8.e43f8","type":"mqtt-broker","z":"","name":"localhost:1883","broker":"localhost:1883","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c9cb9a99.fd7158","type":"ui_group","z":"","name":"Lamp","tab":"bb3a78b2.a93268","order":1,"disp":true,"width":"6","collapse":false},{"id":"fcb61c07.82a5f","type":"blynk-ws-client","z":"","name":"Blynk cloud","path":"ws://blynk-cloud.com/websockets","key":"blah","dbg_all":true,"dbg_read":false,"dbg_write":false,"dbg_notify":false,"dbg_mail":false,"dbg_prop":false,"dbg_sync":false,"dbg_bridge":false,"dbg_low":false,"dbg_pins":"","multi_cmd":false,"proxy_type":"no","proxy_url":"","enabled":true},{"id":"bb3a78b2.a93268","type":"ui_tab","z":"","name":"Switches","icon":"dashboard","order":1,"disabled":false,"hidden":false}]