I know it was cited as an example, but it seems to me that that software running on the Arduino board is deficient if it only tries the DHCP server once and doesn’t keep doing it until it gets a response. A nitpick, I know, but the hairy-eared programmer in me was twitching. 🙂
I was also wondering, given you are running most of those board via power over ethernet, is it possible to software control that to trigger a reset instead. Then your watchdogs could just listen to the MQTT and cycle the POE on the corresponding port (as well as report the issue). Just another (probably more complicated) way to attack the problem.
I’ve had a couple of people say that DHCP requests should be attempted indefinitely so the watchdog isn’t needed, which is correct in general. I should have used a better example. It’s fairly easy to put a check in the main loop so that each time around it checks if it has an IP address, checks how long it was since it was last requested, and tries again if the counter has exceeded a retry time.
However, that means putting a few extra lines of code in the loop, and allocating another couple of bytes to storing a timestamp. When you’re working in a processor with 2.5k of RAM and 16k of flash, sometimes you need every byte you can get just to buffer part of a packet. Every potential error such as a failed DHCP request can be coded around with checks and safeguards and timestamps, but every one of those extra checks grows the code by another few bytes. At some point you can’t just keep adding tests to recover gracefully from every possible failure.
Yes, centralised power management would be one way to move the watchdog away from the device and put it in a central location. That would work for some devices, but not for some that are remote. I have some devices running on solar, and I’ve had devices physically located 1000km away that I had no physical access to or control over once they shipped to another site, but I needed to make absolutely sure would attempt to recover themselves if something went wrong. I should probably have used something like that as an example.
One very interesting idea that came up in the YouTube comments was having some code running somewhere that would watch activity on MQTT, and if it failed to see any particular device for a period of time it would log a failure and send an alert. Not quite going as far as actually power cycling the remote device, but very handy to be notified if something is out of the ordinary. I don’t know of anything like that but I’m going to investigate it, and write something if necessary.
Yes, there are probably many situations where those hardware watchdogs are the correct solution in the never ending list of trade-offs. Sorry if I was sounding negative, didn’t mean to be. They are the hardware equivalent of an exception being thrown all the way to the main-entry function restarting the program, I would say. Certainly done that before.
P.S. How old is your dog? Our Lab is nine and age is just starting to catch up with him (arthritis). Even still, he would never sit still that long if I needed him to.
Don’t worry about it, you’re not the only person to tell me that it shouldn’t fail hard for something dumb like a lack of DHCP response!
We think Bonnie is about 5 (maybe going on 6) but we don’t know for sure. We got her from Animal Aid so we only have a best guess of her age at the time she was found. She LOVES attention, so it’s not hard to get her to sit still: all it takes is a pat or a foot against her and she’ll just lie there. Just like a WDT she’ll instantly jump up if you stop paying her attention though, so she was the perfect prop for this video 🙂
Amazing. I can remember getting very excited reading the review in BYTE about a new “affordable” UNIX workstation back in about 1983 that only cost about as much as my parents house!
[…] you have been reading our blog over the last few months you have probably read about the awesome Arduino homebrew controller or the Arduino cocktail maker. After writing about these projects we thought that it was only fair […]
The mode button can also be used as an input, if you want to control it directly from the Sonoff. It’s connected to GPIO0, so if you hold it down during startup it goes into a mode waiting for a new program. But you can also check the button position in your sketch, and use it to toggle the output on or off each time it’s pressed.
Received on basic sonoff and testing it with is own cloud eWeLink… really cool! But still want to control it with my openhab and MQTT Protocol (“homie” is a wonderfully well made arduino helper for that…).
And now I think I’ll be the first to “wire” extend the mechanical button through an “surfacetouch” switch on the wall… I’ll need alot of a research…
Of course I can just make my own esp8266 wall switch but It will depends on my wifi… again… but now I think of it… independent wifiWallSwitch will be awesome for modifyable Scene!
Hi it would be beneficial to add a fuse somehow, It worries me shoving things in walls etc. you could use temp. sensor but no point knowing its overheating if your away on holidays.
daniel
What would be the best way to add a fuse, if the power supply overheats or faults for some reason having devices like this could be a fire disaster. you could monitor is temperature but if your away that’s not going to be much help.
I think I sent this twice sorry.
kind regards Daniel
Yes, good point, safety is very important for any mains-voltage project. Here in Australia all power circuits are required to have a circuit breaker, which is pretty much a universal rule anywhere around the world. So there should already be some level of protection. You could also add a fuse in line with the Sonoff yourself if you wanted to, probably at a lower rating than the fuse on the whole circuit since the circuit provides power to many devices in your house. Please get advice from a local electrician first before you do anything like this, because regulations are different for each country and I want to make sure you do it safely!
Brilliant project. You mentioned that the pairing button could be used as another input, to act like a manual on/off switch? I am a bit weak on the coding side so could suggest how I could update the project files to reflect this?
And how you are planning to Pat the Dog’ with this one?
Yes, the pairing button could be used as a manual on/off switch by changing the code to detect when it’s pressed. I’m working on a follow-up video with more advanced Sonoff tricks, such as replacing the flash memory chip and using more advanced firmware. I’ll also cover how to use the built-in button, and how to connect an external button so you can control the Sonoff manually from a wall plate.
I just got a cheap NVR that I can connect to my DVRs over the lan – were about $35 or so from aliexpress and no HDD needed to just view cameras. I have some cheapo wireless mice on them for when I need to fiddle with them.
It looks like the UI is the same as the generic “h264” brand one I got that is well known for being a sieve for security, so dont go portfowarding it from the internet either.
Thanks for all your work and willingness to share your experience with the community. I have 10 of these devices that I’m messing around with using arendst’s code. I am very interested in your last post regarding connecting an external switch. I’m also working on connecting a momentary switch with the led backlight to the board. I don’t think that it is the same one that you used for your light switches, but it is very similar.
Nice tutorial, thanks for that!
Did you make progress on connecting the external switch? I’m thinking about this as well.
I’m mainly interested in if the low voltage from the Sonoff would be enough for the common wall switches (as they would normally not switch these low currents) and, off course, safety.
Yes, I have all the parts now to film another Sonoff episode talking about using external switches and other variations to the basic setup. I’m finishing an episode about electric window mechanisms right now, which is nearly done.
That is great news. I was going to share how I got mine working with arendst’s sketch and an LED momentary switch, but it would be better illustrated in one of your videos.
I removed the LED on the sonoff and soldered the wires for the external LED to the board. I also cut the long post for the reset switch so that I could run the 4 conductor wire out of the sonoff housing using the hole where the post was accessed.
Let me know if you have any issues accessing the drawing.
Hi Jon,
Great video.
I’ve been playing about with the ESP-01 for some time now and have built my own version of what the Sonoff module does.
The Sonoff beats mine hands-down as it’s much more compact and totally self-contained (and cheaper than the cost of all of my individual components). I’ve just taken delivery of 2 Sonoff units and have set to and installed the Arduino IDE version of the O/S.
I just have one question regarding which pin of the Sonoff/ESP8266 controls the relay. On my ESP-01 I manipulate the GPIO2 to switch my relay on and off.
I’ve had a look at your sketch ‘BasicOTARelay’ and it would appear to be Pin 12 that activates the relay on the Sonoff board. Is that correct?
I loaded my own sketch onto the Sonoff and all looks good. I can talk to it via a web browser and the serial output reports correctly. I can’t test it fully until I apply mains voltage but just need to be sure about pin12 first.
Thanks once again for such a great article.
Take a look at Blue Iris. Much better option than any DVR I have come across. Easy to integrate into web apps etc as well to become part of the general home automation ecosystem.
Have you tried this on the Sonoff Dual? It’s a little different on the inside. I’ve also seen some traffic that is saying that the Dual has two processors???
I’ve just received a Dual so I’ll have a look inside. From what I’ve read, the Dual has a different pin connected to the button so you need to use a jumper wire across specific parts of the PCB to put it into bootloader mode. I haven’t tried that myself yet though.
[…] They come with their own software on them which is cloud based but you can upload Sketches via the Ardino software just like you would with an Arduino. So I have a sketch written by Jonathan Oxer who runs the Youtube Channel SuperHouse and also Director at Freetronics. http://www.superhouse.tv/17-home-automation-control-with-sonoff-arduino-openhab-and-mqtt/ […]
I enjoyed your You Tube video on Sonoff switches. I too have been playing with this model and a new model issued by Sonoff that is packaged with a male plug on the back and female socket on the front. I have reprogrammed them with aRest ported to arduino by Marco Schwartz. They now host a web page on my home network and do not talk to any cloud servers.
Great to find this project! I had been trying to build MQTT units for power switching out of ESP12s so having a cheap starting point that is CE certified was a great start.
I’m trying to avoid bricking the Sonoff Dual that i’ve started with, and have got as far as setting up the Arduino IDE with ESP8266 libraries, but don’t seem to be able to find advised board choice/Arduino IDE settings for this.
Have set this up and it is working really well.
Where I am a little stuck in OTA updating from a different network segment. My WiFi and Wired networks run on different subnets, so in order to update I need to put my PC on the Wireless subnet for it to come up in the Network Ports list.
Is there a way you are aware of I can scan the Wireless subnet from the Wired subnet?
No amount of googling has pointed me anywhere near the right direction.
The Duals has 12 jumper pins instead of 5. wich one do we need to upload the sketch?
On the above forum there is a example with mqtt. its not directly talking to the gpio pins. but for me that is ok. I will use them as replacement for my KaKu switches.
Yes, the client needs to supply a client ID to the MQTT broker. That’s how the broker can tell different clients apart, and know which clients have received which messages. It probably depends on the broker, but I’ve found that with Mosquitto it doesn’t like having multiple clients with the same ID. It does wierd things like only send messages to one of the clients, and the other client never sees it. The good thing is that there’s nothing magic about the client ID: it can be anything, it just has to be unique. So you can use the end of the MAC address of the node to generate the client ID automatically, for example. That way your sketch can be the same in each node, and they all end up with unique IDs.
Thanks for the reply Jon. I used your sketch to flash the sonoff then created a homekit accessory.js file to control it (via HAP-NodeJS on my pi3) but for the life of me couldn’t get it to work.
I could control it via manual commands in mosquitto but the commands via the home app/siri wouldn’t turn it on. I then looked at the topic via mosquitto_sub -v -t ‘#’ and the “1” and “0” commands were both coming up when doing via home app and mosquitto but only mosquitto was actually turning it on. I was stumped.
I initially thought the client id in the sketch needed to be the same as the client id in the accessory.js file. But decided to change it in the accessory.js to something different and hey presto, it worked!
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!
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.
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.
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?
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 🙂
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.
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???
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.
I’ve managed to fix the Slampher sonoff problem with the info on Peter Scargill’s website. Had to switch a zero ohm resistor over so you can put it into programming mode. After that I flashed it the same way as the sonoff.
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.
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???
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.
i’m trying to hack the Slampher sonoff. I’ve already done the regular sonoff, and tried the same method with the Slampher but getting these errors:
Global variables use 33,408 bytes (40%) of dynamic memory, leaving 48,512 bytes for local variables. Maximum is 81,920 bytes.
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
Got the same error about espcomm
This mean the device isn’t in programming mode.
press and hold the button before connecting power. after this hold it for a few seconds. now try again.
After this when using the serial monitor don’t forget to set it to 115200 baud
I have tried in multiple different ways but cannot get the OTARelay.ino file to compile. When trying it in Linux I get the following error.
/home/charles/Downloads/BasicOTARelay-master/BasicOTARelay/BasicOTARelay.ino:14:26: fatal error: PubSubClient.h: No such file or directory
#include
^
compilation terminated.
Using library ESP8266WiFi at version 1.0 in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi
Using library ESP8266mDNS in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266mDNS (legacy)
Using library ArduinoOTA at version 1.0 in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ArduinoOTA
exit status 1
Error compiling for board Generic ESP8266 Module.
I also tried it in Windows but got similar errors complaining about missing directories or files. I was able to successfully upload the blink ino.
In the Arduino IDE, go to:
Sketch > Include Library > Manage Libraries
in the “Filter your search” field, type ‘pub’.
You will see the “PubSubClient” by Nick O’Leary. Simply highlight it and click install.
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…
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!
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.
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.
[…] It is a Tweet or Post by Jon Oxer from Superhouse.tv (an awesome Home Automation and Electronics Youtube Channel based in Australia). And the Title of the Post is “SuperHouse Vlog #50: The future of SuperHouse“. […]
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.
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.
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!
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.
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!!
Thanks for the great tutorial!
I am just getting started in this and am a total beginner.
Just installed MQTT and Openhab2 on a rapberry pi 3 and will flash my sonoff switches and try to connect them to openhab2.
Are there any good step by step guides on how to link the sonoff to openhab and setup a UI in the phone?
The learning curve on Openhab seems quite steep =/
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?
I also don’t like to leave remote internet access to chance. Best to get your own SSL certificate and DNS entry. StartSSL and DuckDNS are great for hobbyists.
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.
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?
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.
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.
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.
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?
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
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
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!
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.
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!
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
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.
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).
Hi I have all of my lights and sockets connected back to two metal cabinets containing 20AMP SSR relays mounted on din rails. I’ve also got some 12V din rail transformers to switch the relays. Can the VIN on the relay breakout boards take 12V to switch the relays (I think the relays can take between 3 and 33 volts to switch and probably sink around 30ma. I was hoping to have maybe one or two arduinos per cabinet, with one containing about 34 relays and the other 20 relays. How many of these boards could be powered in this way from one arduino? Also is there any way to manage state change if the arduino restarts. I.e. not turn everything on or off at start up?
[…] to use that one board for building different switch configurations. You can find the video here http://www.superhouse.tv/arduino-light-switches/ . His other videos on home automation are well worth watching. The keypads can be made with or […]
Moving On, how to set up a sellable smart home. With so many cloud based units how can a house be sold as smar t when all the tech is really personal and if AI then becomes unlearnt when chnging owners. From hostnames not ip address, to planning a move plent of scope to advise and plan
Hi, firstly I have to say awesome stuff…
I have been working on my own home automation project on and off for the past 2 years or so using capacitive touch switches php mysql python modbus etc, and well lets just say its a bit messy and prone to connection issues. Seeing your switches and breakout boards has left me in awe and i have found the breakout boards on freetronics but i cant find the switches and breakout boards for the switch end of the setup. Would much appreciate a link to them if you have one. Also would love to see how you setup node-red, openhub, and mosquito, seems much easier than writing all my own code php python scripts to polll th earduino modbus and dump into mysql database then use php to display information and give me control over everything remotely.
I haven’t listed the button PCBs, because I made the ones shown in the video several years ago and I can’t easily source those buttons anymore. I’ve just redesigned the PCBs to use a different button that’s easy to find, and I have some of the buttons on order. I’m going to do a whole episode about the light switches themselves, and show how to do different styles. When I have the new boards done I’ll put them up on the site as well.
Hi Jonathan, I subscribe to a number of home automation channels, butI must commend you, I learn most from your channel. Every video has taught me a bunch of new stuff. Great work.
Question I have is do you ever publish your sketches or code? I’m not a programmer but is very keen on setting up lights like you explained with the 8266 and the light switch toggle on a GPIO. I can do the first part, the GPIO part has me panicking.
Great journey you have taken us on! Thanks
Thanks Willie! I’ve just received updated PCBs for my light switches, so over the next couple of days I’ll be recording an episode about how they work. As part of that I’ll touch on the software side again, including how to use toggle switches and regular light switches in place of momentary buttons. Each of my projects has source code published on GitHub where relevant, and linked from the episode page.
[…] Power Shield […]
URL to the power regulator?
I used this one, which is a switchmode module: http://tron.cc/pr28v
[…] Read more and get the source code here […]
[…] Read more and get the source code here […]
Hi Jon,
I know it was cited as an example, but it seems to me that that software running on the Arduino board is deficient if it only tries the DHCP server once and doesn’t keep doing it until it gets a response. A nitpick, I know, but the hairy-eared programmer in me was twitching. 🙂
I was also wondering, given you are running most of those board via power over ethernet, is it possible to software control that to trigger a reset instead. Then your watchdogs could just listen to the MQTT and cycle the POE on the corresponding port (as well as report the issue). Just another (probably more complicated) way to attack the problem.
Great videos.
E.
Hi Evan 🙂
I’ve had a couple of people say that DHCP requests should be attempted indefinitely so the watchdog isn’t needed, which is correct in general. I should have used a better example. It’s fairly easy to put a check in the main loop so that each time around it checks if it has an IP address, checks how long it was since it was last requested, and tries again if the counter has exceeded a retry time.
However, that means putting a few extra lines of code in the loop, and allocating another couple of bytes to storing a timestamp. When you’re working in a processor with 2.5k of RAM and 16k of flash, sometimes you need every byte you can get just to buffer part of a packet. Every potential error such as a failed DHCP request can be coded around with checks and safeguards and timestamps, but every one of those extra checks grows the code by another few bytes. At some point you can’t just keep adding tests to recover gracefully from every possible failure.
Yes, centralised power management would be one way to move the watchdog away from the device and put it in a central location. That would work for some devices, but not for some that are remote. I have some devices running on solar, and I’ve had devices physically located 1000km away that I had no physical access to or control over once they shipped to another site, but I needed to make absolutely sure would attempt to recover themselves if something went wrong. I should probably have used something like that as an example.
One very interesting idea that came up in the YouTube comments was having some code running somewhere that would watch activity on MQTT, and if it failed to see any particular device for a period of time it would log a failure and send an alert. Not quite going as far as actually power cycling the remote device, but very handy to be notified if something is out of the ordinary. I don’t know of anything like that but I’m going to investigate it, and write something if necessary.
Yes, there are probably many situations where those hardware watchdogs are the correct solution in the never ending list of trade-offs. Sorry if I was sounding negative, didn’t mean to be. They are the hardware equivalent of an exception being thrown all the way to the main-entry function restarting the program, I would say. Certainly done that before.
P.S. How old is your dog? Our Lab is nine and age is just starting to catch up with him (arthritis). Even still, he would never sit still that long if I needed him to.
Don’t worry about it, you’re not the only person to tell me that it shouldn’t fail hard for something dumb like a lack of DHCP response!
We think Bonnie is about 5 (maybe going on 6) but we don’t know for sure. We got her from Animal Aid so we only have a best guess of her age at the time she was found. She LOVES attention, so it’s not hard to get her to sit still: all it takes is a pat or a foot against her and she’ll just lie there. Just like a WDT she’ll instantly jump up if you stop paying her attention though, so she was the perfect prop for this video 🙂
Do you have the complete source code with the libraries as i cannot seem to fins all the correct ones to compile it?
Amazing. I can remember getting very excited reading the review in BYTE about a new “affordable” UNIX workstation back in about 1983 that only cost about as much as my parents house!
And it would have been less powerful….
What motion sensor are you using in this video? Orion?
In later blog, you mentioned a different motion sensor that had a wider “view” of the area that you were monitoring.
I’m really inspired by what you are doing with your house.
I’m running OpenHAB with ESP8266’s, but want to use the motion sensors to automate the lights and fans in the house.
Thanks!
Rob
[…] you have been reading our blog over the last few months you have probably read about the awesome Arduino homebrew controller or the Arduino cocktail maker. After writing about these projects we thought that it was only fair […]
Well now the problem is how to hook an human/physical switch for sending command to that sonoff or directly… more in/output available inside?
I’ll definitively buy some but I’ll need a wall “esp” switch too!
Tank you! This one help me ALOT in my reverse ingineering!
Love your research.
The mode button can also be used as an input, if you want to control it directly from the Sonoff. It’s connected to GPIO0, so if you hold it down during startup it goes into a mode waiting for a new program. But you can also check the button position in your sketch, and use it to toggle the output on or off each time it’s pressed.
Received on basic sonoff and testing it with is own cloud eWeLink… really cool! But still want to control it with my openhab and MQTT Protocol (“homie” is a wonderfully well made arduino helper for that…).
And now I think I’ll be the first to “wire” extend the mechanical button through an “surfacetouch” switch on the wall… I’ll need alot of a research…
Of course I can just make my own esp8266 wall switch but It will depends on my wifi… again… but now I think of it… independent wifiWallSwitch will be awesome for modifyable Scene!
Whoa whole lotta questions here!
Hi,
The github links don’t seam to work, i found the correct ones seam to be :
https://github.com/SuperHouse/BasicOTABlink
and
https://github.com/SuperHouse/BasicOTARelay
(without tv in the end)
Oops, sorry! You’re right. I’ll fix the links in the post now.
Hi it would be beneficial to add a fuse somehow, It worries me shoving things in walls etc. you could use temp. sensor but no point knowing its overheating if your away on holidays.
daniel
Hi,
What would be the best way to add a fuse, if the power supply overheats or faults for some reason having devices like this could be a fire disaster. you could monitor is temperature but if your away that’s not going to be much help.
I think I sent this twice sorry.
kind regards Daniel
Yes, good point, safety is very important for any mains-voltage project. Here in Australia all power circuits are required to have a circuit breaker, which is pretty much a universal rule anywhere around the world. So there should already be some level of protection. You could also add a fuse in line with the Sonoff yourself if you wanted to, probably at a lower rating than the fuse on the whole circuit since the circuit provides power to many devices in your house. Please get advice from a local electrician first before you do anything like this, because regulations are different for each country and I want to make sure you do it safely!
Brilliant project. You mentioned that the pairing button could be used as another input, to act like a manual on/off switch? I am a bit weak on the coding side so could suggest how I could update the project files to reflect this?
And how you are planning to Pat the Dog’ with this one?
Again awesome project….
Thanks Wayne 🙂
Yes, the pairing button could be used as a manual on/off switch by changing the code to detect when it’s pressed. I’m working on a follow-up video with more advanced Sonoff tricks, such as replacing the flash memory chip and using more advanced firmware. I’ll also cover how to use the built-in button, and how to connect an external button so you can control the Sonoff manually from a wall plate.
I just got a cheap NVR that I can connect to my DVRs over the lan – were about $35 or so from aliexpress and no HDD needed to just view cameras. I have some cheapo wireless mice on them for when I need to fiddle with them.
It looks like the UI is the same as the generic “h264” brand one I got that is well known for being a sieve for security, so dont go portfowarding it from the internet either.
Thanks for the information Jon, I’m a long time follower of all you projects 🙂
I had just made an ESP based relay but wasn’t too keen on connecting it to the mains!
This looks like the perfect piece of kit.
Thanks once again and keep up the good work!
Ed
Thanks for all your work and willingness to share your experience with the community. I have 10 of these devices that I’m messing around with using arendst’s code. I am very interested in your last post regarding connecting an external switch. I’m also working on connecting a momentary switch with the led backlight to the board. I don’t think that it is the same one that you used for your light switches, but it is very similar.
I look forward to your next video.
James
I’ve got problem with my sonoff. When i pair it with my phone, it says ” device belongs to other user”.
Does anyone knows what’s the problem ?
Nice tutorial, thanks for that!
Did you make progress on connecting the external switch? I’m thinking about this as well.
I’m mainly interested in if the low voltage from the Sonoff would be enough for the common wall switches (as they would normally not switch these low currents) and, off course, safety.
[…] SuperHouseTV #14: Ambient tile using Arduino, ESP8266, and NeoPixel compatible LEDs […]
You talked about modifying the code so that the button could be used as an on/off script.
Were you still going to do this?
I’m also waiting for this tutorial. I think its cool to have it as a working toggle switch.
Yes, I have all the parts now to film another Sonoff episode talking about using external switches and other variations to the basic setup. I’m finishing an episode about electric window mechanisms right now, which is nearly done.
That is great news. I was going to share how I got mine working with arendst’s sketch and an LED momentary switch, but it would be better illustrated in one of your videos.
It’s always good to see how different people approach the same problem, so don’t be shy about sharing your project! I’d love to see it
Here is the links for my project.
Switch – https://www.amazon.com/gp/product/B01C7CQHLO/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1
Arendst’s Code – https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki
Drawing – https://mail.mcmurphys.net:8443/home/james@mcmurphys.net/Briefcase/external_switch.pdf
I removed the LED on the sonoff and soldered the wires for the external LED to the board. I also cut the long post for the reset switch so that I could run the 4 conductor wire out of the sonoff housing using the hole where the post was accessed.
Let me know if you have any issues accessing the drawing.
Hi, what an awesome find! Thanks for sharing! Your videos have always inspired!
Hi Jon,
Great video.
I’ve been playing about with the ESP-01 for some time now and have built my own version of what the Sonoff module does.
The Sonoff beats mine hands-down as it’s much more compact and totally self-contained (and cheaper than the cost of all of my individual components). I’ve just taken delivery of 2 Sonoff units and have set to and installed the Arduino IDE version of the O/S.
I just have one question regarding which pin of the Sonoff/ESP8266 controls the relay. On my ESP-01 I manipulate the GPIO2 to switch my relay on and off.
I’ve had a look at your sketch ‘BasicOTARelay’ and it would appear to be Pin 12 that activates the relay on the Sonoff board. Is that correct?
I loaded my own sketch onto the Sonoff and all looks good. I can talk to it via a web browser and the serial output reports correctly. I can’t test it fully until I apply mains voltage but just need to be sure about pin12 first.
Thanks once again for such a great article.
[…] http://www.superhouse.tv/12-building-an-arduino-home-automation-controller/ […]
Take a look at Blue Iris. Much better option than any DVR I have come across. Easy to integrate into web apps etc as well to become part of the general home automation ecosystem.
@Jon
Have you tried this on the Sonoff Dual? It’s a little different on the inside. I’ve also seen some traffic that is saying that the Dual has two processors???
I’ve just received a Dual so I’ll have a look inside. From what I’ve read, the Dual has a different pin connected to the button so you need to use a jumper wire across specific parts of the PCB to put it into bootloader mode. I haven’t tried that myself yet though.
[…] They come with their own software on them which is cloud based but you can upload Sketches via the Ardino software just like you would with an Arduino. So I have a sketch written by Jonathan Oxer who runs the Youtube Channel SuperHouse and also Director at Freetronics. http://www.superhouse.tv/17-home-automation-control-with-sonoff-arduino-openhab-and-mqtt/ […]
@Jon
So, the itead forum has had some discussion about the Dual… http://support.iteadstudio.com/support/discussions/topics/11000006870/page/1?url_locale=
At this point the only thing that I have been able to do is upload to the device. Jumping Pin 15 to ground indeed puts the ESP into program mode.
Where I am confused is how they are actually talking to the Silicon Labs F330. The relays appear to be controlled by this secondary MCU.
Looking forward to hearing what you decide to do with this device.
treborjm87
I enjoyed your You Tube video on Sonoff switches. I too have been playing with this model and a new model issued by Sonoff that is packaged with a male plug on the back and female socket on the front. I have reprogrammed them with aRest ported to arduino by Marco Schwartz. They now host a web page on my home network and do not talk to any cloud servers.
Great to find this project! I had been trying to build MQTT units for power switching out of ESP12s so having a cheap starting point that is CE certified was a great start.
I’m trying to avoid bricking the Sonoff Dual that i’ve started with, and have got as far as setting up the Arduino IDE with ESP8266 libraries, but don’t seem to be able to find advised board choice/Arduino IDE settings for this.
To complicate things I’m wanting to add OTA support. There’s some useful stuff in http://support.iteadstudio.com/support/discussions/topics/11000006870/page/1 where there’s an image of the point to attach the jumper that’s grounded to get the Dual into programming mode.
So guess what I’m asking is, has anyone been reprogramming the Dual, and if so could they share their Arduino IDE board settings?
You inspired me to buy a couple of these things. I took your sketch and added a couple features that I like. Hope others will too 😉
https://github.com/PepijnVisser/Sonoff/blob/master/Sonoff_1_0_2.ino
Have set this up and it is working really well.
Where I am a little stuck in OTA updating from a different network segment. My WiFi and Wired networks run on different subnets, so in order to update I need to put my PC on the Wireless subnet for it to come up in the Network Ports list.
Is there a way you are aware of I can scan the Wireless subnet from the Wired subnet?
No amount of googling has pointed me anywhere near the right direction.
The Duals has 12 jumper pins instead of 5. wich one do we need to upload the sketch?
On the above forum there is a example with mqtt. its not directly talking to the gpio pins. but for me that is ok. I will use them as replacement for my KaKu switches.
The single port is working fine. is there nobody using the dual ones?
didn’t had much trouble finding the example code. but can’t upload it.
Sorry if this is a stupid question but i’m really new to arduino. In regards to the relay code, both the payloads are 0. Should the first one be a 1?
oh, should I change 49 to 1 and 48 to 0?
of forget my last comments got it to work fine. that’s if my comments ever come out of moderation…….
Just out of interest, do you have to define the clientid in the sketch? Can I remove this? If so what lines in total do I need to remove?
Yes, the client needs to supply a client ID to the MQTT broker. That’s how the broker can tell different clients apart, and know which clients have received which messages. It probably depends on the broker, but I’ve found that with Mosquitto it doesn’t like having multiple clients with the same ID. It does wierd things like only send messages to one of the clients, and the other client never sees it. The good thing is that there’s nothing magic about the client ID: it can be anything, it just has to be unique. So you can use the end of the MAC address of the node to generate the client ID automatically, for example. That way your sketch can be the same in each node, and they all end up with unique IDs.
Thanks for the reply Jon. I used your sketch to flash the sonoff then created a homekit accessory.js file to control it (via HAP-NodeJS on my pi3) but for the life of me couldn’t get it to work.
I could control it via manual commands in mosquitto but the commands via the home app/siri wouldn’t turn it on. I then looked at the topic via mosquitto_sub -v -t ‘#’ and the “1” and “0” commands were both coming up when doing via home app and mosquitto but only mosquitto was actually turning it on. I was stumped.
I initially thought the client id in the sketch needed to be the same as the client id in the accessory.js file. But decided to change it in the accessory.js to something different and hey presto, it worked!
[…] To learn about how to install new firmware, see SuperHouseTV Episode #17: Home automation control with Sonoff, Arduino, MQTT, and OpenHAB. […]
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?
So I got my PocketCHIP. Didn’t like the lack of security so I’ve created a setup script that also installs the packages above.
https://gist.github.com/alecthegeek/434325b6ea261ba84499f4966795073e
However people should copy and modify it to suite. I wrote to reflect my own needs
Nice work, Alec! Thanks for posting this. I’ll update the page to add a link to it, so people who don’t read the comments will see it.
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.
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!
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/
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.
Can you kindly post details of the waterproof box you used?
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 🙂
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
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.
great thanks, Jonathan.
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.
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?
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 🙂
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
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.
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
Thank you! Really nice video
Will really like to see your opinion on the Sonoff Touch too
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!
Sorry, I haven’t used Homekit so I don’t think I can help with that. Perhaps someone else has some insight?
No problem. Thanks anyway.
I’ve managed to fix the Slampher sonoff problem with the info on Peter Scargill’s website. Had to switch a zero ohm resistor over so you can put it into programming mode. After that I flashed it the same way as the sonoff.
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
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!
i’m trying to hack the Slampher sonoff. I’ve already done the regular sonoff, and tried the same method with the Slampher but getting these errors:
Global variables use 33,408 bytes (40%) of dynamic memory, leaving 48,512 bytes for local variables. Maximum is 81,920 bytes.
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
Any idea what is wrong?
JT,
Got the same error about espcomm
This mean the device isn’t in programming mode.
press and hold the button before connecting power. after this hold it for a few seconds. now try again.
After this when using the serial monitor don’t forget to set it to 115200 baud
also any help on my previous post would be awesome as well. Thanks.
Is it possible to read state of switch?
Nice videos on Youtube. Could you please leave links to the items you use for the things you build.
The linked items above fail.
Thanks
Dave
I have tried in multiple different ways but cannot get the OTARelay.ino file to compile. When trying it in Linux I get the following error.
/home/charles/Downloads/BasicOTARelay-master/BasicOTARelay/BasicOTARelay.ino:14:26: fatal error: PubSubClient.h: No such file or directory
#include
^
compilation terminated.
Using library ESP8266WiFi at version 1.0 in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi
Using library ESP8266mDNS in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266mDNS (legacy)
Using library ArduinoOTA at version 1.0 in folder: /root/.arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ArduinoOTA
exit status 1
Error compiling for board Generic ESP8266 Module.
I also tried it in Windows but got similar errors complaining about missing directories or files. I was able to successfully upload the blink ino.
Thanks
You need to make sure you have installed the pubsubclient library in your applicable Arduino Library folder first. Download it from github.
https://github.com/knolleary/pubsubclient
In the Arduino IDE, go to:
Sketch > Include Library > Manage Libraries
in the “Filter your search” field, type ‘pub’.
You will see the “PubSubClient” by Nick O’Leary. Simply highlight it and click install.
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…
[…] Food. Art. Recycle Bin. SuperHouse Automation. […]
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!
I’ve got exactly the same problem. Got simplest Sonoff with stock firmware and this trick doesn’t work for me either
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.
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.
[…] It is a Tweet or Post by Jon Oxer from Superhouse.tv (an awesome Home Automation and Electronics Youtube Channel based in Australia). And the Title of the Post is “SuperHouse Vlog #50: The future of SuperHouse“. […]
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.
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.
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!
I meant to say “huge sheets of chipboard as the floors upstairs which I’d have to cut holes in for access”
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?
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.
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!!
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 🙁
Thanks for the great tutorial!
I am just getting started in this and am a total beginner.
Just installed MQTT and Openhab2 on a rapberry pi 3 and will flash my sonoff switches and try to connect them to openhab2.
Are there any good step by step guides on how to link the sonoff to openhab and setup a UI in the phone?
The learning curve on Openhab seems quite steep =/
Have you used Broadlink?
Can you review and use with sonoff?
I’ve ordered one, but it hasn’t arrived yet.
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?
Did you find a solution for this issue?
Hi I have refashed using BasicOTARelay from superhouse
question is I need to reflash again how do you do that please
nigel
sorry i have sorted it my wiring was loose
I also don’t like to leave remote internet access to chance. Best to get your own SSL certificate and DNS entry. StartSSL and DuckDNS are great for hobbyists.
And also be sure to have a tight firewall, forwarding only specific protocols on specific ports from specific machines.
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.
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?
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.
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.
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.
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.
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
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
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.
Mike, were you using a switch or a push button?
Yes, with a 10k resistor it remains working without an issue (for 24hs now). Seems to be a stable patch
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!
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.
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!
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
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?
Darn PulseLight…. Got it sorted now.
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
[…] For a template of the document that I show in the video, see the episode page at http://www.superhouse.tv/23-preparing-your-home-automation-system-for-death […]
Link to related blog post is ftps instead of https which is a bit strange.
That was my typo! Fixed now, thanks 🙂
Thanks for fix and keep up the good work!
Hi I have all of my lights and sockets connected back to two metal cabinets containing 20AMP SSR relays mounted on din rails. I’ve also got some 12V din rail transformers to switch the relays. Can the VIN on the relay breakout boards take 12V to switch the relays (I think the relays can take between 3 and 33 volts to switch and probably sink around 30ma. I was hoping to have maybe one or two arduinos per cabinet, with one containing about 34 relays and the other 20 relays. How many of these boards could be powered in this way from one arduino? Also is there any way to manage state change if the arduino restarts. I.e. not turn everything on or off at start up?
Many thanks
Andy
Are you aware of this repository?
https://github.com/UnifiedEngineering/T-962-improvements
Custom firmware for the t-926 that addresses a lot of the problems with it.
[…] to use that one board for building different switch configurations. You can find the video here http://www.superhouse.tv/arduino-light-switches/ . His other videos on home automation are well worth watching. The keypads can be made with or […]
Moving On, how to set up a sellable smart home. With so many cloud based units how can a house be sold as smar t when all the tech is really personal and if AI then becomes unlearnt when chnging owners. From hostnames not ip address, to planning a move plent of scope to advise and plan
Hi,
I like your boards, it’s a great idea!
Do you have distributor(s) in Europe for the I/O Breakout Shield? (I didn’t find it on Roboshop).
Hi, firstly I have to say awesome stuff…
I have been working on my own home automation project on and off for the past 2 years or so using capacitive touch switches php mysql python modbus etc, and well lets just say its a bit messy and prone to connection issues. Seeing your switches and breakout boards has left me in awe and i have found the breakout boards on freetronics but i cant find the switches and breakout boards for the switch end of the setup. Would much appreciate a link to them if you have one. Also would love to see how you setup node-red, openhub, and mosquito, seems much easier than writing all my own code php python scripts to polll th earduino modbus and dump into mysql database then use php to display information and give me control over everything remotely.
Thanks John!
I haven’t listed the button PCBs, because I made the ones shown in the video several years ago and I can’t easily source those buttons anymore. I’ve just redesigned the PCBs to use a different button that’s easy to find, and I have some of the buttons on order. I’m going to do a whole episode about the light switches themselves, and show how to do different styles. When I have the new boards done I’ll put them up on the site as well.
Yhea!!! I’ll be the first buyer!
Hi Jonathan, I subscribe to a number of home automation channels, butI must commend you, I learn most from your channel. Every video has taught me a bunch of new stuff. Great work.
Question I have is do you ever publish your sketches or code? I’m not a programmer but is very keen on setting up lights like you explained with the 8266 and the light switch toggle on a GPIO. I can do the first part, the GPIO part has me panicking.
Great journey you have taken us on! Thanks
Thanks Willie! I’ve just received updated PCBs for my light switches, so over the next couple of days I’ll be recording an episode about how they work. As part of that I’ll touch on the software side again, including how to use toggle switches and regular light switches in place of momentary buttons. Each of my projects has source code published on GitHub where relevant, and linked from the episode page.
Totally agree with your arguments. I wouldn’t say better.
I came from the broadcast industry and I have no doubt that reliability in all environments are granted only by wire connections.
Wifi might be easy and cheaper but I only consider them if I don’t have way/space to run the ethernet cable inside the wall.
I’d love to hear your thoughts are options for controlling lights with hard wired connections beyond rewiring everything back to the breaker box.