Hacker News new | past | comments | ask | show | jobs | submit login
Reprogramming a $13 consumer wifi-enabled outlet (rluckom.github.io)
165 points by zipfle on Nov 25, 2017 | hide | past | favorite | 42 comments



This looks quite similar to the Sonoff S20. [1] Although they opted for the ESP module instead of designing a custom PCB around the ESP8266 chip as Sonoff does.

According to the S20 schematic, uart is routed to a header, so it should be easier to flash. [2]

The Sonoff S20 is the same price as the mentioned model, and is supported by espurna. [3] Espurna is great, it has MQTT, Domoticz, Home Assistant, an HTTP API, and Alexa integration. Espurna also supports sending data directly to InfluxDB which is very handy.

If you want to monitor power consumption as well, I can highly recommend the Sonoff POW. [4] Although to get a plug you will need to butcher an extension cable or power strip. If you only want to monitor power consumption and don't want to have the relay, it's quite easy to solder across the relay in the Sonoff POW and use it only as a power monitoring device.

Just a reminder to anyone working with these devices: never, ever connect UART while the device is plugged into AC!!

[1] https://www.itead.cc/smart-socket.html

[2] https://www.itead.cc/wiki/S20_Smart_Socket

[3] https://bitbucket.org/xoseperez/espurna/wiki/Hardware.md

[4] https://www.itead.cc/sonoff-pow.html


I'm also a fan of the Sonoff products for random use cases around the house. One thing I think should be noted - you no longer need to solder in a UART header to get your own firmware on Sonoff devices with the SonOTA project [1]. This project uses the factory OTA mechanism to load your own custom firmware on the device. The result is an IOT device that is cheap, readily available, and fully under your own control with no hardware modifications necessary!

[1] https://github.com/mirko/SonOTA


Perfect, just used this to hook up my Christmas lights. Had an opened Sonoff device laying around that I had yet to flash. Put screws in and 5 minutes later had my lights working. Much easier than the 4 pin serial flash solution


Thank you for this. You just saved me lots of disassembly.


It should be noted that Sonoff devices are not UL Listed, unlike the device the article discusses. Given that and how Chinese product companies like to cut corners with these type of devices (see bigclivedotcom on YouTube), I’m not sure I’d trust connecting one of these to mains voltage.


From looking over their schematics and layout, they are fairly well designed, and they have gone through CE certification so fine for European consumers.

No UL certification could be an issue for US consumers though.


I understand CE to basically be self certified. It’s good but mostly meaningless when compared to bring UL listed or higher, which require equipment tests as well as frequent drop in visits from UL people to your manufacturing fascilies.


They have undergone testing by a third-party test house for their CE certification. While you're right that in many cases CE can be self-certified, this is not (really) the case for mains equipment, the testing required by the European standards are such that it would be difficult to perform yourself.


> never, ever connect UART while the device is plugged into AC!!

Why?


If I remember right, some very low cost ways of converting AC to DC for small electronics leave those electronics at high voltage relative to ground. So the device itself sees +5V relative to its "ground", but the device "ground" might actually be at, say, 115V and the supply at 120 to make 5V. Thus the UART pins might also be at high absolute voltage. This is fine for devices that are fully isolated.


The "POW" device is one example of a device which has GND at live potential, so should not be connected to anything else while plugged into the mains.

Not that I would recommend plugging any of them into the mains with the case removed, or while plugged into other wiring, to be sure!


> The "POW" device is one example of a device which has GND at live potential

Is that even allowed by the FCC?


Yes, that's a quite common design. It might be forbidden if you expose that outside the device, but in electronics internal to the device you can do that no problem.


It sounds to me like the ground level is exposed outside the device in this case.


Unless I'm missing something I don't think so. The case has mains voltage in and switched mains voltage out only, to touch the low-voltage bits with the weird ground level you have to crack open the case. Which is kind of encouraged by open design that's easily hackable, but something that falls under "well, if you do that you're supposed to know what you are doing".


A few months ago there was a similar post about Edimax power sockets and the Raspberry Pi. I commented that I'd like to automatically reset my WiFi router/modem when the Internet connection fails.

Someone commented to tell me about the ResetPlug, which does just that. I'm now the very happy owner of one.

I don't mean that as a advert, but as an encouragement that when you comment useful links to products that already exist, it does make a difference, and I appreciate it. (not spam, but user recommendations).


The existence of that product says so much about our industry.


I would be interested in the internals of the Edimax plug - any chance the firmware can be modified?


The most popular esp8266 based relay from Sonoff is designed for friendly reprogramming - http://randomnerdtutorials.com/reprogram-sonoff-smart-switch...


Have several of these. I run an Mqtt broker, HomeAssistant and "Sonoff Tasmota" https://github.com/arendst/Sonoff-Tasmota . I believe however, this firmware will also emulate a Philips Hue Bridge or Belkin Wemo to make integration easy with Alexa and such.


I really enjoyed reading this, but it wasn't entirely clear to me what the author planned to reprogram the unit to actually do. So from my perspective, the article ended abruptly when the author declared success even though I was looking forward to a description of the conclusion.

The story is important and often overlooked in these moments. It's what justifies spending a hundred hours and $200 to achieve something you could probably just buy for $50.


In my case, I simply wanted a plug where I could know what code runs on it. I love everything Sonoff makes for that exact reason, I've bought a lot of their stuff (including their wifi light switches).

The switches are especially handy because you can program them to do anything, not just switch lights on and off. For example, you can program your bedroom switch to turn off all lights with a long press. Theoretically, anyway, as I haven't yet gotten mine so I haven't tried it with that particular model in practice.


If you read the entire article it's clear why he's reprogramming them. You have to fully read the first two paragraphs.

But essentially, he reprograms the smart plugs to respond to a simple HTTP GET request to turn the lights on, and then turn the lights off after 11 seconds, and the 11 second countdown can be reset by hitting that HTTP endpoint again.

He has a "sensor" board that has a light sensor, and when he turns his regular light switch on, that sensor board detects the light in the room, and hits all the smart plugs endpoints to turn them on. As long as that sensor board detects light, it will keep hitting the "lights on" endpoints of the smart plugs.

When he turns his regular light switch off, the sensor board stops hitting the "lights on" endpoints, and the lights automatically turn off after 11 seconds.


I did, for the record, read the whole article. Perhaps you were more willing to assume that his stated goal was the same as his initial hack solution. Seems you were likely correct.

Question: once you turn the lights on, how would you turn them off given that there's still light in the room?


The Sonoff S22 is a good candidate for reprogramming, with the bonus option that it supports external temperature+humidity sensors.

You can definitely achieve the same functionality cheaper with a ESP8266 breakout + shield, but this way you get a nice case that can just sit on a socket.

https://www.aliexpress.com/item/Sonoff-S22-Smart-Wifi-Power-...

https://github.com/arendst/Sonoff-Tasmota/issues/627


While DIY can be fun, I prefer to buy a finished product when there's a solution readily available... Especially when dealing with home wiring.

When faced with a similar problem (big room, wanted to control multiple lights without pulling wires), I used an Insteon battery operated remote switch:

https://www.smarthome.com/insteon-2342-242-mini-remote-switc... ($42)

And an inline switch module that went up in the ceiling light housing: https://www.smarthome.com/insteon-2443-222-micro-on-off-modu... ($49)

And a couple plug in lamp modules:

https://www.smarthome.com/lamplinc-insteon-2457d2-plug-in-la... ($39)

One advantage of the off the shelf products is that they are all UL approved for the use, so if it catches fire and burns my house down, I don't have to prove that it wasn't my fault.


I've noticed a big market gap, ever since I got an electric car. Every EV owner has a 120V AC charger that they can plug in almost anywhere with an outlet, however getting permission is a challenge. Owners of the outlets rightfully want compensation. But a full commercial charger rig is like $1000 at least. That's way too much!

What I'd like is for outlets to have wifi or bluetooth connectivity on them. I just tell the outlet to turn on via some app, and the app/outlet keep track of how long the outlet is on and charges me a flat rate per unit time. Simple. The smarts for this need only cost $13 above what a regular outlet costs, as this project shows.

This would be especially useful in apartments or parking garages. Provided you already have lights, it'd be cheap to run a 120V outlet to within reach of most (or at least a large number of) parking spots. $13 of electronics plus maybe $50 (i.e. a quad outlet of $200 split among 4) to install an outdoor outlet is all it'd cost to electrify a parking space. The owner of the parking lot could offer low cost electricity and, say, make a profit off the difference between residential and commercial/industrial electrical rates (might take a few months to pay for the outlet, but not more than a year for a well-used spot, then the owner makes an easy profit). Everyone wins, and urban EVs become practical for everyone (and a slow charge is fine. of course, you would still want fast chargers to top up if you were doing a lot of driving, but that can be done elsewhere). Also would be pretty cheap to install on all parking meters.

Just need someone to develop that app and an outdoor outlet with a $13 bluetooth relay that talks to the user's app (only the user's app would necessarily need internet connectivity). Someone do this and be a hero.


A quad 120V 20A outlet suitable for charging 4 cars is going to take a lot more than $200 to install in most commercial locations, they'll either need to install an 80A subpanel near the outlet with 4 20A breakers, or home run 4 20A circuits to the main panel.

If the main panel is out of spare breaker slots (or doesn't have enough amperage left on the feeder), it's going to expensive to upgrade the panel.

Most of the cost ends up in labor, so if you're going to go to all of the expense to install a 4x20A quad outlet, you may as well install a 30A 240V level 2 charge station.

Most of that cost is labor -- I looked into installing a charge station in my condo apartment garage -- coring and installing a home run back to the main panel would have cost $3000 - $5000, and I would have had to pay for a power study for the HOA owned panel.

There wouldn't have been much difference in materials cost between installing a 120V 20A circuit for level 1 charging and a 30A 220VAC level2 charge station.


So a blockchains driven monetization approach for n, in this case electricity.

That is comimg. For sure.


I think it’s great that the author did this as a learning experience. It seems like soldering on a few wires could have saved you like 3 weeks.. but anyway, the ESP8266 is a great platform. Super cheap, minimal components, easy to program, you can write code natively using the SDK or various script based languages. And has good support from the manufacturer.


There seems to be enough room in the enclosure to solder on some pin headers to both sides of the ESP-12. That would make getting access to them a lot easier than trying to rig up a custom 3D printed pogo pin setup.

Other than that, this is exactly what I've been looking for. I have an old wireless outlet (controlled by a RF remote) that I rigged up a Raspberry Pi Zero to, but that is a lot of effort compared to soldering some headers and flashing a new firmware.

Now all we need is some good software to securely integrate this with other IoT systems.


Something like Sonoff-Tasmota (and many other similar projects) provides MQTT support, which works nicely with pretty much any IoT setup.

https://github.com/arendst/Sonoff-Tasmota


I like the explanation of the "journey" rather than just the description of "how you can do this too."


I’m looking for a direct hardware equivalent with an EU plug - anyone got references to share?


I use tp-link hs110, Wi-Fi enabled metering plugs. Highly recommended.


Cool I was actually working on this exact thing!


wifi seems overkill to send on off signals. i would use 433mzh


Given the ESP8266 brings a WiFi radio and 32bit microcontroller for < $2 on your BOM I think this sort of overkill is warranted. 433mhz provides no mechanism for link-layer security which seems irresponsible in this day and age.


You are better off with insecure/obscure radio then insecure wifi (no password or wep), and might exposit the device to the Internet which opens the attack range from your neighbors to the whole world. At least you do not have to worry about your 433mzh device becoming part of a bot net.


ITEAD do make a 433 MHz version of this stuff, but yes, that's just asking for trouble, given how trivially I can sniff and replay those codes.


Except in the US as this frequency is used for amateur radio.


Even through that's true, there's still a wealth of devices that ignore that and use it anyway unfortunately. Mostly cheap devices from other countries that I suspect aren't properly fcc certified despite any claims to the contrary. The wireless doorbell at my last place was on 433mhz.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: