Cheap Smart Plugs (With power monitoring!)
The Mission:
Based on this thread about cheap, wifi-based smart plugs, it was suggested I do a write-up on how to flash them and how not to brick them (like I did )
Why:
Smart plugs are probably the first or second thing you’ll want to do with your new smart home. But, there are a number of issues to smooth before you can use them. Once smoothed you’ll see that it’s actuallly a doddle to get these plumbed in to your system.
Why not use the stock firmware?
- Because it phones home to China
- Because they use proprietary protocol and you would need a new binding
- Because it phones home to China (did I mention that?)
Requirements:
- Buy some of the plugs from Amazon, AliExpress etc.
- Try to ensure they are listed on this website: Tasmota Templates (Note that a lot of the plugs seem to be the same but are rebranded. I got some unlisted ones working by trying different templates.
- Get yourself a spare Raspberry Pi 3B+ onwards (It must have LAN and WiFi)
Steps:
(I am doing this from memory so might miss-step a bit)
1. Setup Tuya-Convert:
Assuming you have a spare RPi up, running, patched and git installed, follow the very well documented steps on his site: https://github.com/ct-Open-Source/tuya-convert
2. Flash the device
Long-Press the button on the plug. This will put it into recovery mode. It should be flashing rapidly.
As per the instructions, install it all and then run
./start_flash.sh
This will go through the various steps needed to flash. One very important step is to ensure you connect your phone / tablet / other device to the new wifi hotspot. TBH, I don’t know why but it does not work without doing this step. Don’t be lazy
3. Select the firmware to push
At this point, you have the choice to install the basic Espurna or Tasmota. Personally I prefer Espurna but, while the basic option boots and works, it has no features like mqtt. I tried various options and eventually bricked it. All you need is Tasmota. Install that
4. Connect it to your WiFi.
Once you reboot your plug you should see a new WiFi hotspot. Connect to this and setup the credentials for your own WiFi.
Be sure to enable MQTT. You don’t need to change any of the settings if you don’t want to.
Be sure to click on the Information button and grab the hostname. eg “tmPowCoffeeMachine-2011”
5. Get the topic root from Tasmota
Once it’s all back up and logged into your network, go back to the new plug by typing in the hostname into your browser. If this does not work you’ll need to find the IP address from your router.
Again, clicking on the Information page you can see that mqtt is connected and take not of the full topic.
6. Plumb it in
Once you have all that you can plumb it into the item in question like this:
Switch PlugsChristmasTree1 "White ChristmasTree" {
mqtt="
>[mqtt:cmnd/tmPowChristmasTree/POWER:command:*:default],
<[mqtt:stat/tmPowChristmasTree/POWER:state:default]
"
}
Number PlugsChristmasTree1_Power "White ChristmasTree - Power"
{mqtt="<[mqtt:tele/tmPowChristmasTree/SENSOR:state:JSONPATH($.ENERGY.Power)]"}
Number PlugsChristmasTree1_Voltage "White ChristmasTree - Voltage"
{mqtt="<[mqtt:tele/tmPowChristmasTree/SENSOR:state:JSONPATH($.ENERGY.Voltage)]"}
(Yes, I used the mqtt 1. method which is not (the current) best but full mqtt setup is out of scope of this )
Final notes
All in all it looks quite long winded but really, after the first plug, it took me maybe two minutes per plug to flash. All of it is automated and very slick. It’s really straightforward.
Let me know if I’ve missed anything or something breaks en route. I will review the steps when I flash the next batch.
C