When building ESP8266 or ESP32 based gadgets you soon get to the point where you want to mount them into a nice casing with a power supply and hide them somewhere in your rooms.
Thinking about possible solutions I stumbled over the fact that many Wifi based smart power plugs (i.e.Tuya plugs) already contain ESP8266 hardware, nicely packed into a casing, with power supply and ready to be plugged into a wall socket. And they can easily be flashed with ESPHome. So basically all I was looking for!
What I am not so sure of is whether it will be possible to access any free GPIO pins on the integrated ESP8266 modules to connect add-ons through I2C or SPI.
If this would be possible, I would try to mount additional hardware right within the power plug, like air quality sensors or humidity sensors. The sensor programming could also very easily control the power outlet, the push button and the LED that all come with the plug. And all this for just 10 bucks.
I couldn’t find anything on the web about this way to build complete sensors that could easily be plugged into the next wall socket.
Sounds like a great idea to me.
But is it possible? Has anybody done this?
This is feasible. ESPhome or Tasmota will allow you to configure any pins that are unused by your “donor” device as SPI or I2C.
I would guess for something like a power outlet it would have 2 or 3 pins reserved for an external power button and a relay. The rest can be reused, depending on how the rest of the board is wired. From what I’ve seen In devices I’ve opened, pins not used by the device are simply not connected to the board, but you’ll have to open your device and trace it to know for sure.
Check the documentation for those projects how to assign SDA,SCL,SCK,MOSI, etc to whatever gpio pins you want.
You’ll have to solder jumpers from those pins on the chip to your spi/I2c bus.
Over the weekend I did some testing with a couple of Gosund SP1 smart plugs (rebranded Tuya, 8 € each). Using their internal ESP8266 with ESPHome works like a charm. What you see in the image below are two SP1s that do the following, all at the same time:
Measure analog voltage through ADC A0 pin (potentiometer attached)
Control an MC23017 over I2C bus with 16 additional GPIOs (8 LEDs attached in my case)
Send serial data through UART0 (left SP1)
Receive serial data through UART0 (right SP1)
I think the possibility to use such a ready-made component instead of single parts is often overlooked. I myself did not think of it at first. Guess I will write a dedicated article about it to make people aware of this nice, cheap and very simple option.
Yeah, sure.
And I have all these parts (except for the case) lying around here.
But just when I was looking for an appropriate case I realized that there are cases with power supply and MCU already built in!
When you add up the single components in your list they easily sum up to 15 €. The SP1 is about half of that price. And the components are already nicely installed. And it comes with an additional relay with driver, a button with blue and red leds and a voltage and power measuring component. Actually quite unbeatable.
Another factor is the design of the smart plugs vs. the empty plug cases. IMHO the casings of most smart plugs on the market are way more attractive than any empty plug case that I have seen so far. Somehow they all look like crap from the 1970s.
BTW: I chose the SP1 because it has a bit more spare room inside. It can easily hold an additional air quality sensor or similar components.
If you go for the hunt, make sure that you buy a plug that is really based on the ESP8266. There is an increasing number of Tuya based plugs that contain a Realtek MCU instead. The Realteks cannot be flashed with Tasmota nor with ESPHome. There are even plugs that exist in older ESP8266 versions and newer Realtek versions and they look identical from the outside (i.e. the Teckin SP22).
My approach to make sure that I get an ESP8266 version is two-fold:
Also check the customer revisions at Amazon. Search them for “Tasmota”. Usually some customers report whether they were able to flash the plug. Make sure these reports are not too old, because the vendor might have changed the same model from ESP to Realtek.