Sonoff wifi switch control with ESP Easy and Node Red

This is my example flow to control a Sonoff wireless switch using the ESP Easy firmware. It handles the button on the Sonoff in Node Red and also using the Big Timer component to turn it on at dusk and off at 11pm. I am using this to control Christmas lights automatically.

There is a video explaining the entire process including flashing the Sonoff with ESP Easy firmware: https://youtu.be/8CuD6YBdACs

[{"id":"b3fb06.96fcc4f8","type":"mqtt out","z":"359e8961.705a96","name":"","topic":"/Sonoff1/gpio/12","qos":"0","retain":"","broker":"cea5258a.b34038","x":901,"y":172,"wires":[]},{"id":"210cd794.79cf68","type":"ui_switch","z":"359e8961.705a96","name":"Relay","label":"Relay","group":"bf685d9c.f18b7","order":0,"width":0,"height":0,"passthru":true,"topic":"","style":"","onvalue":"1","onvalueType":"str","onicon":"","oncolor":"","offvalue":"0","offvalueType":"str","officon":"","offcolor":"","x":434,"y":248,"wires":[["2e8526f5.db708a"]]},{"id":"b08e5ac2.c0bd78","type":"mqtt in","z":"359e8961.705a96","name":"","topic":"/Sonoff1/#","qos":"0","broker":"cea5258a.b34038","x":101,"y":451,"wires":[["7da23d8f.02f104"]]},{"id":"7da23d8f.02f104","type":"debug","z":"359e8961.705a96","name":"","active":false,"console":"false","complete":"false","x":395,"y":451,"wires":[]},{"id":"ff9e779b.7b7398","type":"mqtt in","z":"359e8961.705a96","name":"","topic":"/Sonoff1/Button/Switch","qos":"0","broker":"cea5258a.b34038","x":147,"y":42,"wires":[["ae8f3998.807478"]]},{"id":"ae8f3998.807478","type":"switch","z":"359e8961.705a96","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","outputs":1,"x":368,"y":43,"wires":[["87a58deb.05412"]]},{"id":"2e8526f5.db708a","type":"function","z":"359e8961.705a96","name":"Store current value","func":"global.set(\"Sonoff1\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":638,"y":248,"wires":[["b3fb06.96fcc4f8"]]},{"id":"87a58deb.05412","type":"function","z":"359e8961.705a96","name":"Flip state","func":"if (global.get(\"Sonoff1\")===\"1\") {\n    msg.payload=\"0\";\n} else {\n    msg.payload=\"1\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":333,"y":115,"wires":[["210cd794.79cf68"]]},{"id":"56d97b75.5a15f4","type":"bigtimer","z":"359e8961.705a96","outtopic":"/home/test","outpayload1":"","outpayload2":"","name":"Big Timer","lat":"47.44021","lon":"19.02919","starttime":"5001","endtime":"1380","startoff":"0","endoff":"0","offs":"0","outtext1":"1","outtext2":"0","timeout":"480","sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":"0","month1":"0","day2":"0","month2":"0","day3":"0","month3":"0","day4":"0","month4":"0","day5":"0","month5":"0","d1":"0","w1":"0","d2":"0","w2":"0","d3":"0","w3":"0","d4":"0","w4":"0","d5":"0","w5":"0","suspend":false,"random":false,"repeat":false,"atstart":false,"x":129,"y":301.5,"wires":[[],["210cd794.79cf68"],[]]},{"id":"2ace973f.15a3f8","type":"inject","z":"359e8961.705a96","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"x":121,"y":165,"wires":[["210cd794.79cf68"]]},{"id":"164c243f.4e40cc","type":"inject","z":"359e8961.705a96","name":"","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"x":120,"y":205,"wires":[["210cd794.79cf68"]]},{"id":"cea5258a.b34038","type":"mqtt-broker","z":"","broker":"192.168.1.80","port":"1883","clientid":"node-red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"bf685d9c.f18b7","type":"ui_group","z":"","name":"Sonoff","tab":"156af96f.f8fd27","order":7,"disp":true,"width":"6"},{"id":"156af96f.f8fd27","type":"ui_tab","z":"","name":"Home","icon":"home","order":"1"}]

Flow Info

Created 8 years ago
Updated 6 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x2)
  • inject (x2)
  • mqtt in (x2)
  • mqtt out (x1)
  • mqtt-broker (x1)
  • switch (x1)
Other
  • bigtimer (x1)
  • ui_group (x1)
  • ui_switch (x1)
  • ui_tab (x1)

Tags

  • sonoff
  • esp
  • easy
  • esp8266
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option