Posted on 163 Comments

#21: Six Sonoff Secrets

Customise your Sonoff home automation controllers with a memory upgrade, weatherproof housing, control switches, sensors, and custom firmware.

ITEAD keep releasing new Sonoff models so this isn’t a complete list, but some of the models mentioned in the video include:

Storage

winbond-25q32fvThe flash memory chip in Sonoffs is 8Mbit, which is only 1MByte. Then if you want to do OTA (Over The Air) updates you need to limit your program size to less than half the available memory so that a new program can be uploaded alongside the old one. And if you use a SPIFFS (SPI Flash File System) to store non-volatile data outside your program, you lose even more memory.

You can replace the flash memory chip with a Winbond 25Q32FV in SOP-8 package, which is a 32Mbit (4MByte) chip. You can buy them on eBay for about US$3 for a pack of 10.

The original flash memory on the Sonoff is a Winbond 25Q08FV, which is the 8MBit (1MByte) version of the same chip.

Thanks to Pete Scargill for this idea! You can see more on his original blog post: “32Mb ESP01 and Sonoff

Safety

Sure, you can just cut a power lead and screw it into a Sonoff, but it’s probably a bad idea. You need to consider how your Sonoff will be used, including physical protection (stop little fingers reaching the terminals!) and liquid protection from spills. You also need to make sure there is strain relief on the cables to prevent them being pulled out, and possibly exposing live mains connections. You can do it cheaply using a plastic project box, and with some cable ties around the cables just inside the box so they can’t be pulled out. The result can be a very neat setup that won’t look like a dodgy DIY cable, and should be safe for general use.

sonoff-powerboard

You can go even further and use an IP-rated (Ingress Protection) case and cable glands, to make your Sonoff waterproof and physically very strong.

sonoff-ip56-case

In this video I gave a very simple explanation of the two-digit IP codes. There are also extensions to the code for other attributes. You can find more information and tables showing the specific meaning of the numbers at en.wikipedia.org/wiki/IP_Code.

Switches

Internet control is fun, but usually you also want some way to manually turn the output on or off without using your phone. You can modify a Sonoff to connect an external button across the pins of the built-in button, allowing you to toggle the output by pressing the button manually. The built-in button is connected to GPIO0, so when the button is pressed it pulls GPIO0 to GND. This is used during power-up to put the Sonoff into bootloader mode, and can also be used to toggle the output or do other actions.

sonoff-gpio0-terminals

Alternatively, you can connect an external button between GND and GPIO14 so that your software running on the Sonoff can detect when it has been pressed. Some firmware, including Theo Arends’s TASMOTA, supports this out of the box.

GPIO14 is exposed on the internal header used to upgrade the software on a standard Sonoff. There is already a pull-up resistor on GPIO14, so you don’t need any other parts. Just connect a button across the GPIO14 and GND pins, and you’re done!

sonoff-header

Even better, TASMOTA has an option to support an external switch instead of an external button. The difference is that with a button, you want the output to change state each time you press and release the button. This means the firmware needs to treat both the button press and release (cycling from HIGH to LOW to HIGH) as a single event. But a switch just changes state (goes from HIGH to LOW, or goes from LOW to HIGH) and stays there because it latches in place. So your software needs to treat each level change as a separate event, and toggle the output. Once again, TASMOTA supports this out of the box.

Sensors

As explained in the section about switches, the regular Sonoff exposes GPIO14 on the internal header that is used for flashing new firmware. The same header also provides GND and 3.3V connections, and the GPIO14 pin is provided with a pull-up resistor. This makes it super easy to connect anything that needs a single digital pin, such as an external switch / button or a one-wire sensor.

sonoff-th-sensor-pinoutTo make it even easier, the Sonoff TH10A and TH16A both feature a 2.5mm 4-way (TRRS) socket that is intended for connecting external sensors. The socket provides 3.3V, GND, and GPIO14: the same I/O pin exposed on the internal header of a normal Sonoff. That means you don’t even need to modify the board, you can simply plug in your sensor or switch externally.

sonoff-th-with-cable-800

The 2.5mm socket also has a 4th connection, but there are parts missing inside the Sonoff so it’s left unused. You can fix this easily by putting a solder blob across two pads on the Sonoff PCB, and optionally installing a pull-up resistor.

In the video I said that there is a 10k pull-up from GPIO14 to 3.3V. However, I didn’t notice that there are actually 2 pull-ups in parallel, so the effective pull-up on GPIO14 is 5k! You can still use a 10k pull-up on GPIO4 if you like, or you can use a 4.7k resistor if you want them to be about the same. 4.7k is common for I2C, but 10k is generally fine too.

sonoff-th-bottom-breakouts

Software

There are many alternative firmware projects for the Sonoff. Personally I love Theo Arends’s firmware, but there are many others that may suit you better.

To learn about how to install new firmware, see SuperHouseTV Episode #17: Home automation control with Sonoff, Arduino, MQTT, and OpenHAB.

If you have any other suggestions please let me know in the comments below, and I’ll update this list.

Sites

Because the Sonoff uses an ESP8266 microcontroller, there are a huge number of sites with information that’s relevant to the Sonoff. These include:

163 thoughts on “#21: Six Sonoff Secrets

  1. Woah! I extremely like your post!
    All the information’s and ideas that was missing from somewhere else!
    Continue your great work!

    And I’m exited to work on ways to embed toggle switch in firmware with states. You have an starting exemple?

  2. Great video! Very instructive and your enthusiasm is infectious.
    Question though, re: housing in IP rated boxes (nice explanation btw).

    How much of a negative effect does that housing have on WiFi range of the ESP8266?

    nb Using Chrome 55. no input boxes appear for this form.

    1. Thanks Paul 🙂

      That’s a really interesting question about the box reducing WiFi range. My initial reaction was “no, of course not, plastic doesn’t absorb WiFi signals” but then I stopped to think about it a bit more and realised that it *may* have some effect. Industrial cases like the one I used are usually very thick and heavy, much thicker than the plastic on a simple consumer product, and depending on the specific plastic it may contain material that attenuates a 2.4GHz signal. Not likely, but possible. One interesting idea I’ve heard is that if you want check if a specific material will attenuate a WiFi signal, try putting it in a microwave oven for a few seconds and see if it gets hot. If it does, it contains material that absorbs the same frequencies as 802.11b/g etc use. If it doesn’t get hot, the radiation is passing straight through unimpeded. I’ve never tried that myself but I’m tempted to put a box in the microwave just to see what happens. IMPORTANT: make sure there are no captive nuts or other metal parts in the box before you microwave it!

  3. Have you taken a look at “Homie” ?

    Homie is a lightweight MQTT convention for the IoT.

    https://github.com/marvinroger/homie

    This is a cool framework. there is also a OTA managment server for it at : https://github.com/jpmens/homie-ota/

    1. Yes, I’ve looked at Homie in the past, and I quite like it. I think it’s important to have some sort of structure to MQTT topics, otherwise things get out of control very quickly. When I started using MQTT about 5 years ago I did the usual thing of using random topics out of convenience. It’s easy to do that, but before long you won’t remember what is being published where. I keep a spreadsheet of topics but even that can end up out of sync with reality. Since I’ve been using Theo Arends’s firmware on Sonoffs I’ve been inclined to use his topic structure, just because it’s how the firmware works and it’s easier than maintaining a forked version of his code. His structure is different to Homie: personally I think the Homie structure is better than Theo’s structure because it slices the topics in a different way, with everything oriented around devices rather than message types, but that’s totally a personal opinion. Both ways are “right” if they make sense, and Theo’s structure makes enough sense to me that I’m very happy to use it.

  4. Can you kindly post details of the waterproof box you used?

    1. I got that box a while ago from a certain company that I won’t link to anymore. However, it’s similar to this one that has slightly different dimensions: http://www.altronics.com.au/p/h0301-ritec-105lx75wx40hmm-ip65-sealed-abs-enclosure/

      I’ll update the page with links to some products 🙂

  5. Great video, Jonathan. Please keep them coming.

    I found these Windbond chips on ebay but the lower most number listed on the chip does not match your image. Will this matter?

    Here is the link: http://www.ebay.com/itm/10Pcs-WINBOND-W25Q32FVSSIG-W25Q32FVSIG-25Q32FVSIG-SOP-8-IC-Chips-FLASH-BS1-/262478524681?hash=item3d1cf07109:g:LmMAAOSw9eVXWwLa

    Thanks,

    C

    1. Yes, those are fine. The part number is correct: the bottom number is usually a batch code or date code in year-week format, so that’s 2016 week 8.

      1. great thanks, Jonathan.

  6. Just wanted to say thanks for a quality post. You are so right, safety is forgotten all to often. Thanks for demonstrating how safety is part of quality.

  7. I am confused by two topics in this episode, first you suggest and demonstrate replacing the flash chip to allow OTA. Later, you cover TASMOTA which incorporates OTA using the existing Sonoff memory. Did i miss something along the way? Is the existing memory sufficient for TASMOTA version of OTA or does it require a replacement chip?

    1. TASMOTA fits in the factory-supplied flash memory, so there’s no need to upgrade if you use it. However, many other people have run out of space on the Sonoff when writing their own firmware. If you use TASMOTA, you don’t have to bother with the memory upgrade 🙂

  8. Great video as ever Jonathan 🙂

    I was running a Domoticz setup before I found out about the Sonoff (via you)

    The ESP Easy firmware works really well with the Sonoff and Domoticz has a built in MQTT broker.

    http://www.letscontrolit.com/wiki/index.php/ESPEasy

    1. I too have had great success with ESPEasy, more so than with Tasmota.

  9. Love your videos Jon!
    Do you know if these devices are approved for install into homes in Australia ? I have a couple Belkin products but they are quite expensive. Getting the sparky to put some of these in would be a lot cheaper and very customisable.

    Cheers mate,
    Mick.

    1. Thanks Mick!

      iTead say they have now received CE certification on some Sonoff models. It’s a bit hard to find, but they have this on their site: https://www.itead.cc/wiki/images/f/f7/CE_Certificate_for_Sonoff_Series.pdf

      1. and this certificate is real?

        1. Now that I’ve visited the Sonoff factory personally, I’m pretty confident that they’re doing everything right: https://www.superhouse.tv/27-visit-to-the-sonoff-factory/

  10. Thank you! Really nice video
    Will really like to see your opinion on the Sonoff Touch too

  11. Hi Jon,

    Always look forward to your vids, especially the MQTT/ESP related ones. I had bought a Sonoff a while ago to tinker with but haven’t really done much with it. I got quite excited when I saw the touch on this video and nearly bought it. I say nearly because when read the blurb i noticed a neutral wire is required and unfortunately, as with most standard wired light switches, there are no neutral feeds anywhere near any of my switches.

    Thanks again for all your content!

    Cheers
    Jon

  12. Help needed:

    I’ve setup a homekit fan accessory using a raspberry pi, HAP-NodeJS, MQTT and a sonoff.

    It works fine but the one problem i’ve got with it is the status on the home app not showing correctly. When I turn the fan accessory ON the status in the home app my iOS device is correct and shows it’s ON.

    BUT if I leave it on for a while then go back into the home app is shows it’s OFF even though the accessory is still ON???

    I switch it ON then OFF again and it turns OFF.

    I used this code here for the .js file.

    https://github.com/jat80/ESP8266/blob/master/Home%20Automation/Part%208/relayLight_accessory.js

    But modified a few lines to make it look like a fan accessory.
    I don’t really have any experience with javascript (or coding in general for that matter) so don’t know if there is something else in the code that could be the problem with the status not showing correctly.

    Any help would be appreciated.

    Thanks!

  13. Hello Jonathan,

    Thanks for made me do sleepless nights :/ your posts and videos are very interesting and helpfull.
    I’m trying to connect sonoff rf (with temperature sensor and a button) to openhab with tasmota firmware and I almost succeeded thanks to your tips.
    Your knowledge sharing is very appreciated.
    keep it up…

  14. Hi,
    Inspired by your video, I loaded TASMOTA 3.9.11 firmware to Sonoff WiFi and Sonoff RF. Everything works great except for the control GPIO14 (both Sonoff)
    Shorting GPIO14 to the GND – no effect. I do this with supply from USB -> RS 3.3V (without connecting to 230V).
    Where to find the problem?
    Thank you!

    1. I’ve got exactly the same problem. Got simplest Sonoff with stock firmware and this trick doesn’t work for me either

      1. I don’t think the stock firmware (the one supplied by Itead that works with eWeLink) supports the GPIO14 switch trick. It uses GPIO14 for connecting to sensors. To do that trick you’ll need to use firmware that supports it (such as TASMOTA) or write your own.

    2. It sounds like other features are working properly (such as pressing the built-in button to toggle the relay) and it’s just the GPIO14 feature that isn’t working. Is that correct?

      Check in user_config.h around line 111, which should set the SWITCH_MODE value. For a rocker switch (latching) it should be set to TOGGLE. Also, check that you don’t have any I2C features or sensors enabled because that also tries to use GPIO14.

  15. Hi
    This is perfect! The modules look perfect for running light switches, retaining local control and being able to update OpenHAB with state changes. The only wrinkle is that, like most UK homes, I have no neutral at my light switches. Given the module itself runs on 3.3v, do you think there’s any chance of running it from batteries? I guess it’s unlikely to last very long on a pair of AAs.

    1. It wouldn’t run for long. That’s a frustrating situation, and I want to do a video about it soon. The very brief summary is that you can locate the Sonoff in the ceiling where the active loops down to the switch, and where neutral should also be available. Then you can use the active loop to drag a control wire pair that links a wall switch to the Sonoff. There are some things to be careful of (such as don’t re-use the existing active loop) which I’ll cover in the video.

      1. Ah I see, that should work for the upstairs lights as I should be able to access the wiring from the loft. Not sure about the downstairs lights as I have huge sheets of chipboard which I’d have to cut holes in for access. Might be doable though. Would PoE be a viable alternative? I suppose if I’m going to run cable, I could just run an extra live/neutral in, although not sure of the legalities of doing so. I really appreciate the efforts you put into this site and the videos! Great inspiration!

        1. I meant to say “huge sheets of chipboard as the floors upstairs which I’d have to cut holes in for access”

      2. Did you ever get a chance to do this video. I would like to use these to control my lighting as we don’t have a neutral in the UK i thought maybe putting these in the ceiling next to the lights.

        1. Not yet, but it’s still on my list. Unfortunately my list is way bigger than the time I have available! The next 4 videos are already underway, and the next Sonoff video will have to be after those 🙁

      3. This solution would also be perfect for me. I could place the Sonoff in the ceiling and make a closed control wire loop to control the Sonoff over GPIO14. But wouldn’t the distance of the closed control wire loop to control the Sonoff be too long to cover a low voltage current? I am no electrician so I might be completley mistaken, but let’s say I have to cover 2/3 meters from the ceiling to the wall switch, would that work?

  16. Would you be comfortable running these in the wall cavity behind a switch? Will they overheat?

    Great write up, I’ve got 6x in use at home now with openhab2. Just started on tinkermans Sonoff SC + neopixel ring. Might be a good one to cover next?

    1. Personally I’d be comfortable putting them in a wall cavity. They don’t seem to run hot so I don’t think there’s any particular fire danger. I used to have an EtherTen powered by PoE inside the wall behind every light switch, and they run quite warm. I think Sonoffs run cooler than EtherTens.

    2. One problem is if you happen to change your Wi-Fi router. You have have to get access to the switch on Sonoff in order to change the SSID/Wi-Fi configuration.

  17. Jonathan:
    I flashed a https://www.itead.cc/wiki/Sonoff_4CH with https://github.com/arendst/Sonoff-Tasmota I have been trying to make it work with Home Assistant without success. If you could help with the setup of both the Sonoff firmware and Home Assistant I would appreciate it immensely!! I have not seen information in your You Tubes about Home Assistant so I hope this is not asking to much!! Thanks for the help in advance!!

    1. I haven’t used Home Assistant, sorry. It’s on my list of things to investigate, but right now I can’t be any help with it 🙁

    2. I know that DrZzs has been working with Tasmota and Home Assistant. I don’t know anything about either of them, but I hope to be learning soon. Maybe this will help you.
      https://youtu.be/-OGptklNI1E

  18. I’ve flashed the sonoff basic with Tasmota and it works great with OpenHAB.
    But if I connect a short wire (about 20 cm) to the GPIO14 and grnd pin, the switch starts to flip so now and then.
    Might the pull-up be inadequate? Or should I add a filter?
    Any suggestions?

    1. Did you find a solution for this issue?

    2. You have to use a low pass filter.

  19. Unless the Sonoff (or other gadget) will be outdoors or otherwise exposed to the elements or flooding, a weatherproof box is overkill from both the functional and cost perspectives. Similarly, if the Sonoff is indoors and away from kids, animals and friction/vibration, a regular project box can also be overkill.

    Plus, I have a problem with plastic project boxes. They cracked when I drilled holes in them, or they broke while being mounted, or they snapped when the lid was over-tightened. I’m just too cruel to plastic project boxes.

    Metal boxes work fine, but are often too expensive for the task at hand, EXCEPT when the electronics inside generates significant heat, in which case metal boxes are the only way to get the heat out.

    I believe nice boxes are needed only when the device will be exposed for all the world to see. To me, project boxes are more about appearance than anything else.

    My needs for a sheltered electronics enclosure involve guarding against three things:
    1. Insects entering and frying themselves.
    2. Moisture due to accidental spills/spray, or condensation due to normal day/night temperature cycling when humidity is high.
    3. Incidental contact (not forceful) with the surroundings.

    My solution? A heavy-duty/freezer 1 gallon Ziploc ™ bag, some hot-snot, and some tie-wraps. Total cost is under 25 cents. Wish I could attach a photo, but words will have to do:

    Start with the wire cut (Sonoff unmounted), with lots of slack (1-2 ft).

    Cut slots on each side of the bag about 2″ above the bottom, big enough to admit the wire.

    Feed the wire ends in each side and tie a square knot between the two ends, leaving enough spare wire at each end to attach the Sonoff. Secure the knot with a tie-wrap. This provides strain relief.

    Note: The knot is optional, especially for solid wire or Romex: Just overlap the wires and use 4-5 tie-wraps next to each other to prevent slippage.

    Attach the Sonoff, then put everything into the bag.

    Pull the wires tight, place the strain relief so it is in the middle of the bag, right at the bottom. Mark the cable where it exits each side of the bag.

    Put some hot-snot 1″ inside one of the marks, pucker the bag over it, and cinch it with a tie wrap. Repeat for the other wire. Ensure the bag is under no strain when the two ends of the wire outside the bag are pulled apart.

    Next, close the bag most of the way, suck out the remaining air, then close it completely. This ensures the bag won’t inflate due to temperature or atmospheric pressure changes.

    This makes a functional DIY insect-proof and water-resistant enclosure. It is also trivially easy to open and close – no tools required.

    Of course, this solution looks terrible, so it should be hidden, which again helps ensure it is kept well away from hazards.

    And unlike some higher-end weatherproof electronics enclosures (e.g. Pelican), there is no need to include desiccant or do nitrogen purging to control internal moisture, since the step of removing most of the air also removes nearly all of the condensible moisture.

    This enclosure method is fairly durable when protected from the elements and mechanical abuse. I have freezer bag enclosures that are still pliable after being in my garage rafters for over 5 years, and under my bathroom sink for even longer.

    This is not a rugged solution! If more mechanical protection is needed a $2 “old work” plastic double junction box (“J-box”, with cover) can be used, with the freezer bag used inside if moisture protection is needed. The total cost is still far cheaper than a project box, and still ugly enough to be kept hidden.

    1. I am late in joining the party. I use a 6 inch piece of an old bicycle tube to cover the sonoff switch and run a 6 inch piece of rope and then small clamps to the ends including the rope . The rope limits the stretch, so no strain on the wire and connections. It is stretch proff, water tight and has no impact on the wifi signal

  20. Hi! I’ve been using sonoff with Tasmota firmware and it is pretty stable so far. The only issue is the random on and off state changes, when a phisical switch is connected as explained in the video (between GPIO14 and GND). This issue doesnt happend when connecting a push button and changing SwitchMode to 3 (pushbutton).
    Is there any way to prevent the switch to randomly trigger? May be a capacitor or a pullup resistor?

    1. Edit: issue also happens with both switch and push button (Switch modes 0 and 3 respectively). I tried with a phone line wire (shielded and grounded to the metal frame of the lamp where the sonoff module in installed), same results.
      I’m wondering if anyone has experienced this issues and solved it, it is extremely annoying to the point I had to leave out the physical switch until I find the proper way (if there is any) to install it.

    2. That’s interesting. I haven’t seen that problem, but there are probably some things that can help fix it. Firstly, you could add a stronger pull-up. I’d start by putting 10k between the input and 3.3V. This will effectively be in parallel to the existing pull-up on the board.

      Do you know if this happens only when the mechanical switch is open, or closed, or both? Also, how long is the cable to the switch, and does it run directly alongside mains wiring? Try to take data connections across mains cables at right angles, if possible.

      1. Hi Jonathan, thanks for the answer. The issue happens both in close and open states of the switch.
        Here you have some pictures of the actual work: https://goo.gl/Miyvm5
        For data, I used 15cm of telephone cable (https://goo.gl/q5Mk8E). That was after considering some the discussion taking place here: https://goo.gl/GlQ94k, specifically regarding the use of shielded cables to avoid interferences.
        For the pictures you can tell I tried to place the data cable from pinout header in a 90d angle wrt mains, but also you can check all cables (main input, output and data) come across a single hole in the lamp and that might not be the best idea. Again, as I am using a shielded cable for data, grounded to the metal frame of the lamp, I thought that would be enough, but may be not at all.

        1. Oh, I see, so the cable isn’t even very long! When I first read your comment I assumed that you meant 15 meters, not 15 centimeters, then I saw the photo and realised that the Sonoff is mounted right behind the lamp fitting. That’s such a short piece of cable that I don’t see how it could be a big problem like this. Also, if it happens in both the open and closed states of the switch, I think there’s some other problem happening here. If the switch is closed, the digital input will be pulled to GND really hard through a direct short circuit, so the Sonoff absolutely should not see it change state.

          I’m puzzled about this. Can you see the Sonoff reporting a state change? For example, if it’s publishing its state changes to an MQTT broker, can you watch that topic and see it send a bunch of on / off messages?

          I’d really like to know what’s going on here.

          1. Hi Jonathan, I decided to re-solder the header pins and replace the external switch, but keeping the shielded wire grounded to the lamp metal frame. It’s been two hours and there are no records of state changes in the logs so I think it was definitely a combination of bad components and amateur mistake.
            Thanks a lot for your kind assistance

          2. Hi Jonathan, I have to say my previous attempts worked like a charm for 12 hours or so, but today the module triggered itself again, two events in a row. You can see the logs here: http://pastebin.com/JT2PXnBL
            And here is a sample log showing the proper triggers made from Home Assistant (intentional, not self triggered): http://pastebin.com/NRY6qW6j

    3. I had this same issue on 2 out of 7 sonoffs I have. Putting a 10k pull up resistor in fixed the issue for me.

      1. Mike, were you using a switch or a push button?

        1. Yes, with a 10k resistor it remains working without an issue (for 24hs now). Seems to be a stable patch

  21. Hi Jonathan,
    Thank you for your great video tutorials! About the rocker switch you used in this episode… is it a regular AC main switch? Or a DC switch? If DC, can you suggest one? Preferably, I’m looking for an inexpensive one that might fit into an AC-sized wall plate. Like this:
    http://www.homedepot.com/p/Hampton-Bay-Devon-1-Toggle-Wall-Plate-White-935TWHB/204803145.
    What do you think?
    Cheers!

    1. Thanks Bennett! I just used a regular AC mains switch in the demo, which is massive overkill for this purpose. For mechanical switches there isn’t really any such thing as an “AC switch” or a “DC switch”, it’s just that they are rated for different purposes because of the way AC vs DC behaves when the connection is made or broken between the metal contacts. You’ll commonly see that a switch may be rated for (say) “250V 10A AC, 120V 1A DC”. That means it’s rated to carry a higher voltage and current on AC than on DC. There are multiple reasons for this, but the biggest issue is the way arcing happens. With AC, the arc will self-extinguish 50 or 60 times per second (depending on the mains frequency in your country) but with DC it will sustain the arc for as long as the contacts are near each other. So a high DC current is more likely to weld the contacts closed than a high AC current. Also, the mechanical structure of a switch can be designed in multiple ways, so that either the contacts close and separate slowly / progressively (imagine a typical “slide” switch) or rapidly, snapping open and closed with a spring. Contacts that “snap” open and closed quickly will experience less arcing, so they can handle higher voltages / currents.

      Short answer: any switch at all will be just fine for handling the 3.3V at about 0.002A that the Sonoff needs for a logic input.

      1. Brilliant! Thank you for the response! I learn a lot from you everyday! I soldered headers onto my first Sonoff last night and tried to flash it using the ‘Blink’ example code, but the feedback from the upload was that it appeared to be out of memory (I forget the exact text). I must’ve done something wrong so I will try again this evening. Happy St. Patty’s!

      2. Hi Jonathan, one other question. I’m having difficulty connecting to the Sonoff to flash it using a D1 Mini. Is that even possible? Do I need to load software onto the D1 first? Thank you again. Best, Bennett

  22. Hey guys,
    I wonder if someone can help. I have the Sonoff basic with Tasmota firmware v 4.0.6 installed. I have configured PowerOnState=1, BlinkCount:0, “PowerRetain”:”ON”, etc.

    My problem is that whilst the relay will come on after start, it will never stay on pass 30s and switches off. It does the same if POWER/LIGHT switched on manually. I think I have checked all possible settings, retained flag, etc but can’t fathom it.

    Any help here?

    1. Darn PulseLight…. Got it sorted now.

  23. Hi, thanks for the excellent work, I’m thinking how to do multiple firing with a sonoff pcb, I know that if I change the firmware I can do it as you have explained joining GPIO 14 with ground, but I want to find out some. Method to do it with the original firmware, I discovered that joining the two pins that are seen in the image of the Link, relay switches once but I can not get it to switch again (except I press the button) I think it’s because To be a model without RF components is missing, it would be so nice to verify in your SONOFF RF if you can do the complete cycle of the relay by joining more pins (somehow you have to send the commands off and on the RF module).

    http://s2.subirimagenes.com/otros/previo/thump_9710713img0025.jpg

  24. this helped me alot thank you 🙂

  25. Thanks for the video! It was great!
    Any way to cause a sonoff to switch between voltages rather than switching just between on and off? I have a heating system that will change its function when receiving 220 volts and when receiving 130 volts. I would like to use a sonoff (or any other way) to schedule the control of this.

    Thanks!!

  26. Thank you for the episode – you successfully shamed me into getting around to taking care of the deathtrap Sonoff attached to my lamp! Yes, I knew it was a danger, no I hadn’t got around to fixing it because, well, it worked.

    It is now safe and sound (and earthed!) in it’s grey project box!!

  27. Hey Jonathan,

    Quick question that I am having trouble getting an answer on. With the *stock* firmware, does the pairing button toggle power output?

    Thank you, your info has been great as I am getting up to speed with the Sonoff products.

  28. Hey Jonathan,

    great video :).

    I am having a problem you might be able to help with.

    One of Sonoff basic failed flashing and now whenever i try to connect to pc via usb serial for flashing the chip on uart heats up. Any ideas?

  29. Sonoff-MQTT-OTA-Arduino – End of Life

    This software is End of Life. New features will be introduced in Sonoff-Tasmota available on https://github.com/arendst/Sonoff-Tasmota

  30. Hi Jonathon,

    Have you had any luck with using Sonoff devices in a multi-way switched light setup? Most of the lights in my house are multi switched (2 or 3 switches) which makes using wifi relay’s a bit tricky. I have connected all of my single circuits using the Sonoff TH devices (Tasmota) without issue, but the multi-way switching has me bamboozled.

    Keen to understand if you have tacked this one.

    Cheers,
    Ian

    1. Hey, i’m also very interested, but I thing i now the answer.

      Look at this website!
      http://xbmcnut.blogspot.nl/2017/07/syncing-two-sonoffs-for-2-way-light.html

    2. RE: multi-way switched fixture – vote me in on needing a solution/recommendation to this one!

      I think it’s simpler for my case to bring source power to the ceiling fixture directly and always have a Sonoff there to perform the mains switching via MQTT. This is conceptually similar to Jonathan’s architecture except that the power distribution and relay is not in a central panel.

      The question I have is whether I can use the existing switch wiring in the walls to control just one “switch” Sonoff? This way, when any switch is toggled, that will change the GPIO14 input state on the single Sonoff and it then sends the request to the automation hub to toggle the power to the load. Any fallacies with using existing home cabling for the DC wiring between the wall switches? If not, then this is a case for needing an electrician to install DC wiring (e.g., Ethernet CAT5) and then install the Sonoff in a central location where I can easily provide it with power. I wouldn’t need power at the wall because I’d use the old-fashioned, non-lit, light switch (i.e., not LED lit pushbuttons). Not ideal in that it’s not 100% DIY.

      The real sticking point for me is when the original wiring brings source power to the fixture rather than any one of the switches. In this situation I don’t have power in the wall anywhere for the “switch” Sonoff. I can’t use the original wiring to bring power down from the ceiling AND also have wiring available for the DC “stuff”. In this case, I’ll have to have an electrician bring power to one of the switches… so, again, not 100% DIY solution. If this is the case, I might as well go w/ the CAT5 solution outline above and begin to mimic a central control panel.

      Cheers!

      Mike

  31. Thanks for the video.
    Re GPIO pushbuttons:
    Am I right in thinking I can use both GPIO0 and GPIO14 as contacts for pushbuttons? Is there a third GPIO that’s free for use? It looks like GPIO4 is free.
    That way I could use one Sonoff Basic to receive data from 3 hardware buttons for device control (optionally linking one to the connected relay)
    Is that achievable?
    Thanks

  32. Hello,

    Thanks for the great post, i really love it!.
    I do have a question. You say to buy Winbond 25Q32FV in SOP-8 package from iBay.
    But i would like to buy from alixpress, but cant find the exect type you have in the post.
    So my question is: wil this chip work for the modification ?
    100 stks W25X40CLSNIG W25X40CL SPI FALSH SOP8 4 Mbit Winbond W25X40 W25X40BVSNIG

    https://nl.aliexpress.com/item/10pcs-lot-Free-shipping-W25X40BVSNIG-W25X40BVNIG-4Mbit-flash/32692899720.html?spm=a2g0z.search0104.8.65.5b83e883c7CtXF&priceBeautifyAB=3

    Greet Davo

  33. Another firmware to consider (if you’ve replaced the flash chip) is Mongoose OS: https://mongoose-os.com/ – it’s hard to describe properly but is like a very compact operating system with a development environment split between the microcontroller and your desktop computer. Development is in C or JS, it has a file system and you can call into the APIs from webpages that your ESP8266 is hosting.

  34. Thanks for this, I really like the GPIO14 trick – makes the sonoff very useful for a garage door controller & monitor.

    Another option for custom firmware (it’s mine):
    https://sites.google.com/site/mppsuite/esp2866
    with variations: https://sites.google.com/site/mppsuite/esp2866/mpp8266download

    It’s for those who would prefer to use an android device as the hub/server/automation engine vs a pi or arduino.

  35. Very informative video.
    Thank you for that.

    Although there is some crazy things being done out there, I feel for my basic needs I can probably use the factory firmware. Just solderbuttonsso that I can toggle on off from wall switch and connect the lights
    I’m guessing that will serve the purpose of controlling manual via push button switch and Alexa when needed.

  36. Hi. I found this device is support 10A input/output. How to use for 20A appliances such like 3.5hp air conditioner?

    1. You can use the output to switch a high-power external relay.

  37. Hello Jonathan,
    First of all I love this video!
    I tried the solution with the TH-10 and conventional switch as you instructed in the video. Unfortunately I could not get the conventional switch to toggle the light on or off. I’m pretty sure I soldered GND and GPIO14 to the TRRS 2.5mm jack correctly. Do I need to change the firmware of the TH-10 for it to work? I’m using the ewelink app with other Itead device so would prefer if possible to keep the stock firmware.

    Your assistance is very much appreciated

    Thanks Again!

    Re,
    John

  38. Hi! I was wondering what switch mode to use with a physical toggle switch?

  39. Hey
    I wonder if someone can help. I have the Sonoff basic with Tasmota firmware v 5.11.1 installed. I have configured PowerOnState=1, BlinkCount:10, “PowerRetain”:”ON” or “OFF”, PulseTime =0,etc.

    My problem is that wish the relay will stay ON after POWER ON,but it will off pass about 10s after POWER ON. I think I have checked all possible settings, retained flag, etc but can’t fathom it.

    Any help here?

    1. i think i read some were that for some reason its reverse on the sonoff ie hi is low and low is high but there is code that reverses this lots on google

  40. Im wondering if there is a way to make gpio14 do dimming ie to make if the button gpio1 is pressed on to sonnof once it dimms 10% and so on up to 100% then when at 100% if pressed goes back to 0% and if you hold the button down it starts to dim 1-100%
    obviously gpio14 would be used to connect to a esp 32 or similar with pwm or a pwm board or if not pwm a board that varies voltage from 0-10v as most dimming leeds have this
    or you could poss use a 3v – 10 v amplifier using mosfets and resisters . (can gpio14 be used to vary the voltage between its 3v max and 0v (0-3v) the applifier would amplify the values appropriately to achieve the desired 0-10v value so getting the dimming needed)

  41. Thanks for the post!
    I am looking for some of this firmwares, or maybe I’ll try to do my own code using the Arduino IDE.
    What I need is:

    1. to get the less latency to switch the relay as fast as possible.
    2. I need to be able to network like 20 independent Sonoffs connected to one central ap router.

    I used to work with OSC under NodeMcu and worked fine; I am not sure that I need this firmwares because I’ll not use all this domotic features…
    I am looking on the ESPurna & Tasmota, and maybe I should use Websockets. That’s the faster way about latency?

    Based on this 2 requirements, what of this firmwares / environments do you think I can check?

  42. Hi Jonathan,
    Can you please share the name of the mobile app that you are using to connect and control the Sonoff after TASMOTA firmware update, since you cannot use the eWeLink app any longer as you already mentioned…
    Thanks!

    1. Hi Samuel,

      I use OpenHAB running an a Raspberry Pi as my main home automation controller. My phone has the OpenHAB app installed, which communicates with the controller. The controller in turn uses MQTT to send commands to the Sonoff. There’s more detail about the architecture in this episode: https://www.superhouse.tv/24-home-automation-system-architecture/

  43. Jon

    Love your posts there are great and informative.
    Is there a way to access the GPIO4 and GPIO 14 pins on the Sonoff Dual V2.

    Is the only way a direct solder on the ESP itself?

  44. I had a rather bad experience with one of the single Sonoff devices. I left one hooked up to a heater and it melted the input terminals although it was only drawing about 8 amps. Trusting those solder joints for big loads is probably not ideal.
    I ran some #14 copper along the traces to see if it could handle a bigger load and that seems to help.

  45. I couldn’t find the chip listed in the YouTube notes or hear you say it, but I did find “Winbond 25Q32FV in SOP-8 package, which is a 32Mbit (4MByte) chip” listed here on your website. However I could not find a listing on Ebay, Amazon, or Aliexpress. I’m guessing maybe SOP-8 is the size, of course 32Mbit (4MByte) is the size. I’m hoping “Winbond 25Q32FV” is background info. and not needed to buy the chip. I found this listing will it work. I looked through all of the other people’s post and see I’m not alone. The one post that did link to Ebay is no longer available, nor do need 100 of them from aliexpress.

    MX25L3205 MX25L3205DM2I-12G 32mbit 4MSPI FLASH SOP-8 5pcs/Free postage
    http://s.aliexpress.com/zeqayMVj?fromSns

    1. Yes, I agree. I can’t find the exact item specified. When I searched for

      Winbond W25Q32FV

      Ebay returned a lot other similar names, but I have not experience to know which are OK and which will be a waste of money. Lots of similar names, like W25Q64FWSIG, W25Q128FVSG, W25Q32BVSIG.

      Would any number after Q be OK, i.e. W25Q*FV? I’m assuming FW,BV won’t be useful.

      Are the trailing characters (SIG, SG), anything to be concerned about?

      And of course, there look to be much large chips available, so just for availabilities sake, should I go with the 128?

      ——-
      And thanks for the great series of videos! Your long form and patient explanation is so much better than many of the youTubes I look at!

      1. I looked up the part number spec for that chip, and the trailing info doesn’t make sense to me. According to the datasheet, if it has “I” after the final number it means industrial temperature range, and if there’s a “G” it means “green” package (ROHS compliant) but just about everything is anyway these days.

        In case it helps, the part number coding is defined on page 58 of the datasheet: https://www.elinux.org/images/f/f5/Winbond-w25q32.pdf

        With the smaller capacity parts becoming harder to get, it should be fine to use a larger capacity part. I haven’t tried that though so I can’t guarantee it.

        1. Thanks very much for the very helpful reply.

          I’ll go with the smallest chip that I can still find and let you know what happens.

          (May be a while, as I have a home project I’m committed to ;- ) )

  46. Hi.

    Great Post.
    Wanted to check if it was possible to do the switching mechanism on the standard stock firmware?

  47. Hi Johnathan! Absolutely love your videos mate and you got me ordering a few sonoff’s for my garage, front gate, and a couple of light switches at home.
    I’d love to know if you’ve had any experience wiring this momentary switch to a sonoff? https://www.ebay.com.au/itm/LED-12mm-illuminated-Metal-Momentary-Push-Button-Switch-Boat-Car-3A-220V-DC/382230897511?hash=item58febca367:m:m7Kav8mZnHD0e0NXorO8Lmg

    I think this is the best option to use because it has an LED indicator, so if the light is on outside, I don’t have to manually look outside to see if it’s on (if I had turned it on indefinitely). Instead the led indicator on the switch will be on. Problem is, these onboard LED lights are rated @3V, 5V or 12V depending on which units you choose.
    Can I plug them instead of the sonoff existing LED or would you have a better idea? It might be helpful to check this thread with a similar problem https://github.com/arendst/Sonoff-Tasmota/issues/716

    Thank you very much in advanced!

    1. Those buttons should work nicely. The ads for illuminated buttons often give you options for 3V, 12V, etc, but that’s deceiving. The buttons themselves are almost always set up for 3V drive of the LEDs, and if you select a different voltage (like 12V) when you place the order they just throw some resistors in the package and expect you to wire it in series with the LED. The buttons themselves are exactly the same, no matter what voltage you order!

  48. Hi Jon, your very informative , i just have a simpke question about the sonoff rf, i dont always want to use the mobile to turn things on and off, but I would like a remote to control the sonoff, I know you can get these 4 button learning remotes, but I would like a 8 or 12 button one to operate several of them, is there anything out there that can do this.
    I’ve seen this one on eBay but have no idea it would work
    http://www.ebay.co.uk/itm/Blue-433MHz-16CH-16-Buttons-Remote-Control-Transmitter-Electric-Window/
    Anyway great if you can help, keep up the good work

  49. Hello, I hope you can help me.
    I would like to use sonoff attached to a remote controlled car. For that I need sonoff to work with 12DCV.
    There is anyway of doing it with “sonoff basic 120V” or I really need to buy other type off sonoff ?
    Thanks.

    1. Could be 5 or 9V too.

    2. There is a model called “Sonoff SV”, where “SV” means Safe Voltage. It’s designed to be powered from a low-voltage source so that you can use it in projects that don’t use mains power.

      However, for a remote controlled car it’s probably bigger and heavier than you want. The major benefit of a Sonoff is that it’s set up for mains power, but electrically it’s very simple. You can achieve the same end result with something like a Wemos D1 Mini, which has the advantage of a USB connection so it’s very easy to reprogram.

  50. G’day Jonathan, thanks very much for ths, & in advance for all the other wonderful it leaves me expecting to find here. It’s also really beaut to find something like this in a voice like my own, Australian.

    I’m experienced in programming, but not in electronics, & found this while doing some “how to” searches alongside seting up an order of goodies with which to begin my own journey into home automation. I’m aiming to do as much as possible, preferably all, in low voltage, for two reasons. The first is that it’s legal, & safer, for someone not qualified to work with mains voltage. The other is that I’m a regular festival volunteer & one “home” that I want to automate is my festival camp. Seeing this video prompted me to add a 3 pack of Sonoff SV modules (https://www.banggood.com/3Pcs-SONOFF-DC-5V-24V-DIY-WIFI-Wireless-Switch-Socket-SV-Module-APP-Remote-Control-For-Smart-Home-p-1152507.html) to my order.

    So a couple of questions…
    Do you have anything that covers home automation with low voltage gear more directly? (I expect to be trawling your site enough that I might find it anyway)
    And, seeing that you’re an Apple guy, do you have anything about working with HomeKit? (& I notice this post pre-dates Apple’s announcement of opening HomeKit up to hobbyists)

    Thanks again, & I’m looking forward to the lessons I’ll find here.

    1. PS… seeing you “SuperHouse or SuperHuman?” video has inspired me to see what I can do to make life easier for my elderly mother.

    2. Hi Pedro! Thanks for your support 🙂

      Much of my current home automation system is based on 12V (or lower) control, with the mains voltage parts limited to the final devices that switch loads. I’ve done that for the same reasons as you: my electrician can take care of wiring up the loads back to the switchboard, and I can do the control side in relative safety.

      Many of my videos show low voltage parts of the system so I don’t really know what to recommend, but perhaps the overall architecture episode will give a good idea of how I’ve separated out the mains portions:

      https://www.superhouse.tv/24-home-automation-system-architecture/

      1. Thanks again 🙂 … now to watch that episode.

Leave a Reply to Simon Pavert Cancel reply

Your email address will not be published. Required fields are marked *