Wifi controlled switching - hacking a Sonoff device

Тәжірибелік нұсқаулар және стиль

An embarrassingly long time ago, Another Maker sent me a Sonoff Basic WIFI controlled switching module.
Today I'm finally getting around to using (and modifying) it to hopefully make my life a bit more convenient.
Here are a couple of the resources I made use of along the way:
electrosome.com/led-control-e...
www.tspi.at/2019/03/15/sonoff...
And here's the hacky code that I ended up bodging together to make this thing work:
pileofstuff.ca/r/ybd6r
Thanks to Another Maker for sending me the Sonoff to play with: / anothermaker
-----
My tip jar: / pileofstuff
If you are OK with me getting a commission on your e-bay purchases, feel free to use my affiliate link: ebay.to/33IF7PA
Some other links to products on e-bay may also be affiliate links
lbry.tv/@pileofstuff
odysee.com/@pileofstuff
-----
This isn't the only way to do it.
It's probably not the best way to do it.
But it's how I do it.

Пікірлер: 69

  • @MrBobWareham
    @MrBobWareham6 ай бұрын

    Well done for spending all that time and going down the rabbit hole only to find it goes a lot deeper than you expected.

  • @SimpleElectronics
    @SimpleElectronics3 жыл бұрын

    Holy crap! This is what I need in my life! This is an awesome project and I can see it being expanded to so many things!

  • @DrexProjects

    @DrexProjects

    3 жыл бұрын

    I think I have 8 of them running lights, fans and water taps for gardening. Regular plants... Not Weed.

  • @Flying-Toast
    @Flying-Toast8 ай бұрын

    This is awesome, I just used two of these in my latest video! Thanks for the tutorial :)

  • @777Thibs
    @777Thibs3 жыл бұрын

    Neat lighting on your Ender 3. I did similar, instead running a strip inside the bottom-facing v slot of the top rail. I also placed a short strip directly onto the hotend cover to illuminate under there. I still haven't gotten around setting up Octoprint, but I have all the parts to get it working.

  • @vegaswayne247
    @vegaswayne2473 жыл бұрын

    You have a Sonoff Basic R2, which is why GPIO 14 was not found. The older ones don't have the large black wires for the mains current. The GPIO 2 pin with cause a boot failure if it is held low when the unit is powered on. I've done several with the external switch connected to the RX pin (GPIO3). Programming was easy using Hpme Assistant and ESPHome. Using GPIO3 (RX) will let you use a toggle switch, for example, a standard light switch. You just have to flash it before soldering on the switch wires. The program can be updated over-the-air so the serial connections won't be necessary after flashing.

  • @EsotericArctos
    @EsotericArctos3 жыл бұрын

    Itead also have a Zigbee version of this. Most of the Itead WiFi stuff is highly hackable as they are based around the ESP8285 chip, which is pretty well an ESP8266 with 1mb RAM onboard. They are a really great devices. Very popular with "Makers." The SonOff Mini is also great if you have less space. You can modify the SonOff Basic t0 be a dry contact relay as well. I use one with Tasmota as a "smart" thermostat.

  • @martink9785
    @martink97853 жыл бұрын

    Great project 👍

  • @PaulOvery001
    @PaulOvery0013 жыл бұрын

    Well done

  • @deankq4adj125
    @deankq4adj1253 жыл бұрын

    Great project, and for those naysayers saying that version of pi doesn't work, I guess you proved them wrong. Great setup and idea.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I still would recommend that people use the supported hardware, but in my case I use the most basic feature s so I don't overload the poor little guy.

  • @PIXscotland
    @PIXscotland3 жыл бұрын

    I would have just gone Tasmota on that. It comes with a UI for the web, can be direct driven by URL Post commands. The default button is an on/off by default as well. The external switch is a useful addition for your use case though.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I looked into tasmota a bit, but they focus so much on the MQTT / home assistant stuff that I never found that info. After several people mentioned that there actually is a web interface I finally found it buried deep in the project's web pages. Oh well, this was a fun challenge. And I learned some stuff.

  • @EsotericArctos

    @EsotericArctos

    3 жыл бұрын

    @@pileofstuff MQTT is a great way to communicate with these. Tasmota does have a lot of Home Assistant fans, so it is easy to get lost in the documentation. Home Assistant seems to be popular :)

  • @AnotherMaker

    @AnotherMaker

    3 жыл бұрын

    @@pileofstuff One day I will get you on Node-red and MQTT. I think you'll genuinely love it...but this was a good project in its own right and I learned some stuff along the way.

  • @MrGmanGB
    @MrGmanGB3 жыл бұрын

    Hi - You should flash these Basic units using Tasmotizer. The R2 also has a switch built in. I also run Octoprint with the tasmota plugin which allows you to switch everything off from the octoprint webpage. I have all of this setup on my printer for the last few years and works perfectly.

  • @TheEmbeddedHobbyist
    @TheEmbeddedHobbyist3 жыл бұрын

    I have about 6 running tasmota connected in the power cord, the lights don't have an earth so wiring is easy. I've also go two in 6gang extension leads. I just cut the outer cover of the cord away, cut the L and N then run the earth over the top of the pcb. This way you don't need a connector on the earth to find room for in the box. Nice beer.

  • @GadgetReboot
    @GadgetReboot3 жыл бұрын

    This might be useful for me as a basement workshop hazardous (mainly thermal) kill switch and double checker, like if I was using hot air or a hot plate, I want to keep certain appliances like that on a dedicated power bar I can switch off upstairs if I forget and maybe have it semi-automated where I know I only need the stuff for a few hours so I set a 6 hour power strip shut down timer and have it protect me from myself

  • @PablumMcDump
    @PablumMcDump3 жыл бұрын

    The Sonoff S31 has regular AC receptacles, and does Kill-a-watt-like power monitoring, which I've seen used for interesting things like detecting when the washer's done by the drop in power draw. An interesting member of the Sonoff family (I'm using with Tasmota and Home Assistant).

  • @grimninja2004

    @grimninja2004

    3 жыл бұрын

    btw, the s31 is not supported by the sonoffs web interface still , cant even be turned on or off . the camera cant trigger a scene like they say it can. and ittt support is usless unless you want to pay for iftt and the advancded sonoff subscribion

  • @AJB2K3
    @AJB2K33 жыл бұрын

    Those Back box's don't exist in the UK which is a shame as they look so useful!

  • @JWH3
    @JWH33 жыл бұрын

    I'm doing something very similar to this only in hacking a smart bulb for fun. I picked a difficult one on accident because it's RGB seems to be set via a serial protocol. But I have control over the white right now. I want to write it myself in Arduino for learning and just need to tap it's direct programming lines as it's esp8255 based (esp8266 with less flash) but otherwise I should be good to go.

  • @AnotherMaker
    @AnotherMaker3 жыл бұрын

    Fantastic work. It really never crossed my mind to try to program that thing directly. I've flashed tasmota on them and that's pretty cool, but I could really see some benefit to running fully custom code. I need to make some ESP8266s that are directly powered by AC and this may be the way to go. Thank you.

  • @grimninja2004

    @grimninja2004

    3 жыл бұрын

    probably 100% uslsess, but i wonder if the espixel firmware or similar could run on these. it has 1 pin of io and thats all you need to drive ws2211........ it may even be able to power small strips

  • @AnotherMaker

    @AnotherMaker

    3 жыл бұрын

    @@grimninja2004 I may have to check that out!

  • @anthonycalia1317
    @anthonycalia13173 жыл бұрын

    Flash it with Tasmota and you get everything you want and lots more

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    That is an option. I feel that I learned more doing it this way, though.

  • @DrexProjects
    @DrexProjects3 жыл бұрын

    I used the dual switch plastic boxs for my SonOffs. Left plenty of room for reset and pushbuttons.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I looked for those, but as I said, plastic electrical boxes are not very common here.

  • @DrexProjects

    @DrexProjects

    3 жыл бұрын

    @@pileofstuff Got mine at Home Hardware.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    @@DrexProjects Didn't try there - the closest one is quite a distance away.

  • @DrexProjects

    @DrexProjects

    3 жыл бұрын

    @@pileofstuff Oh ya st. b is miles from nowhere.

  • @wallacebrown3151
    @wallacebrown31513 жыл бұрын

    The button on the sonoff originally is programmed to manually turn the unit on/off. Cool that you were able to add a second switch and enclose it in an electrical box and I don't blame you for not wanting to use the factory software. Security concerns aside, seems a little strange to send the commands all the way to China and back if you don't need to access over the internet

  • @elvinhaak

    @elvinhaak

    3 жыл бұрын

    Yep. But it can be handy to have some internet-accessible server if you want to control it from your mobile phone, for example when that is not on your wifi but using 4G for its connection. Also when at your own home. I really like this idea though and simply use the webbrowser while on local site!

  • @DrGreenGiant
    @DrGreenGiant3 жыл бұрын

    Point to note. You had some issues after programming with it doing funny things. You still had the UART dongle connected. There's a very good chance that dongle won't be providing enough power to run the wi-fi. I've had this issue before at least. After connecting the mains is worked fine

  • @edwardfletcher7790
    @edwardfletcher77903 жыл бұрын

    The Tasmota FW is one of the best options for these units.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I mostly did this for the challenge and the learning.

  • @edwardfletcher7790

    @edwardfletcher7790

    3 жыл бұрын

    @@pileofstuff I figured as much, just wanted to give you something to add easy functionality if you decide to extend your Home Assist. network...

  • @HazeAnderson
    @HazeAnderson3 жыл бұрын

    If you clean up too much you find yourself changing channel name to neaterpilesofstuff 😏

  • @Chrisamic
    @Chrisamic3 жыл бұрын

    14:20 "Hey, it's uploading". I actually got a laugh out of this. Nothing ever works for me first time even if I do follow the instructions (or think I have). It always seems to take some phutzing around and alignment of the planets before I work out what the secret sauce is.

  • @edgarcastiel321

    @edgarcastiel321

    3 жыл бұрын

    i realize I'm kinda randomly asking but does anybody know a good website to watch newly released tv shows online ?

  • @brentleyzayden7428

    @brentleyzayden7428

    3 жыл бұрын

    @Edgar Castiel I watch on FlixZone. You can find it on google =)

  • @tengelgeer
    @tengelgeer3 жыл бұрын

    Note: If you select the D1 Mini as a board you can just use Dx directly in code like "byte relayPin = D5" So no need to add that conversion in the comments. And you can just use the button on the Basic to do the toggle. That's what the stock firmware does as well. And an ESP does come with internal pull up's on most of it's pins just like a basic Arduino ;) Also, Tasmota i still VERY usable without Home Assistant. I would certainly check it out because you could have done all this with Tasmota as well without a line of code ;)

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I though about using the built-in button, but I didn't feel like messing with extending it outside the case. Some days I have an odd mix of laziness and doing pointlessly hard things...

  • @camolas71
    @camolas713 жыл бұрын

    Hi, a relay connected to pi gpio can do the same. There are a script to do it on octopy

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    It can turn everything off, but it can't turn the Pi itself on remotely.

  • @markfergerson2145
    @markfergerson21453 жыл бұрын

    I kinda followed along but my OCD got hung up on that 12V relay. Where do its coil contacts go on the board? Are you just supposed to kludge 12V in from the outside world?

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    No idea. I'll have to dig deeper when i have time. I suspect those relays are simply the wrong ones.

  • @elvinhaak

    @elvinhaak

    3 жыл бұрын

    @@pileofstuff Were they ment to be switching something on 12 V like in a car? Easy to hook up 12 Volt from that for the relais and have the other end of the coil be switched by fet or transistor or even optocoupler but a bit hash to directly link to a GPIO-output

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    @@elvinhaak The problem, as I see it, is there is no way to get 12 volts onto the board.

  • @matambale
    @matambale3 жыл бұрын

    Did you just say "Snot-soldered" @17:42? Every time I tack-solder something, henceforth it shall be called "snot-soldered".

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    Maybe...

  • @fredflintstone1
    @fredflintstone13 жыл бұрын

    A nice video and fun to watch tell the truth did teenager help a tad with the code:-)

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    It was the other teenager.

  • @jw200
    @jw2009 ай бұрын

    I dont see point in these things. I thought sonoff can be controlled thru any internet. My home is in city A and i want to control my light from city B. It means I cant do that? It only works in local server. That sucks

  • @ste76539
    @ste765393 жыл бұрын

    All very good, but you do know you could have done the same thing with just one of those relays and one GPIO pin on your Raspberry Pi? There's an Octoprint plugin that adds a power button on the Octoprint web server, took me about ten minutes to set everything up and cost virtually nothing to implement. K.I.S.S.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I thought about that, but i couldnt figure out how to use the Pi's GPIO to remotely turn the PI on.

  • @ste76539

    @ste76539

    3 жыл бұрын

    You leave it on. Just log into Octoprint, upload a file, pre-heat and print, when it's done, you just turn off the printer again (there's probably a plugin that will do this automagically by now, but I prefer to do it manually), job done. Mine's been on non stop for nearly two years without any issues. Costs virtually nothing to run.

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    @@ste76539 That's an option, but where mine is it gets unplugged by other people sometimes, so I prefer to shut it down properly when I'm not using it.

  • @frankowalker4662
    @frankowalker46623 жыл бұрын

    Nice. But I prefer a switch I can just turn on and off without relying on a computer or WIFI conection..

  • @pileofstuff

    @pileofstuff

    3 жыл бұрын

    I'm trying to reduce the number of times I have to run up and down the stairs. My knees arent getting any younger...

  • @johncoops6897

    @johncoops6897

    3 жыл бұрын

    @@pileofstuff - Well, most people just switch things on when they go upstairs, and switch them off before they come down!

Келесі