Topic:
Hacking low cost "smart" wifi enabled plugs to work with HomeKit
Topic type:
Thanks to a number of open source projects and tutorials, I managed to set up PowerTech Wi-Fi Smart Plug to be controlled via Apple's Home app. [Update: just buy Belkin wemo smart plug with Thread]
[Update: Thread support and a reasonable price means that I don't recommend this workaround anymore. Search for "belkin wemo thread plug" in Apple store, etc.]
Better formatted instructions and resources to come in next draft of this post, but here are the basics that I relied on to get the PowerTech MS6106 Wi-Fi Smart Plug working with HomeKit.
This process is mainly derived from this tutorial on reddit. I had to trial and error a few times to get a working `json-string` config string for the MS6106. The overall process will likely work with other tuya based accessories available at Jaycar, but I haven't gotten them figured out yet. Will do follow up posts on other devices as I figure them out.
I used a Wemos D1 Mini for the "donor" because I wanted to make the process quick and repeatable. Cost me NZD ~$5 plus shipping off of TradeMe.
Required hardware:
- raspberry pi (I used 4 w/ 2gb mem) (w/ power supply, noobs as micro sd, hdmi to hdmi micro adapter - adapter optional if you set up headless from start)
- wemos d1 mini
- usb a to micro usb cable (connects wemos d1 mini to raspberry pi)
- ethernet cable (goes to your router - raspberry pi onboard wifi is needed for the flashing process)
- this guide assumes a mac
- usb connected keyboard is setting up raspberry pi non-headless to start, there are keyboard shortcuts to navigate GUI without mouse, so usb mouse is optional even if going non-headless
Raspberry Pi set up steps:
- set up headless raspberry pi to liking (ssh enabled, follow steps from maker snack: https://www.youtube.com/watch?v=OgHmrB5scTk) - I started out slightly differently with pre-installed NOOBS on micro SD to start, but ssh and wifi enabling steps are similar
- install tuya-convert and set up on raspberry pi:
- ssh in, git clone https://github.com/ct-Open-Source/tuya-convert; cd tuya-convert; sudo ./install_prereq.sh; sudo reboot
- ssh in again, grab HAA bin file and place it in correct directory: `cd tuya-convert/files/; wget https://github.com/maslyankov/haa-single-binary/raw/master/haa-single.bin`
Wemos D1 mini set up steps (on your mac):
- get tasmotizer (`pip3 install tasmotizer`, see https://github.com/tasmota/tasmotizer)
- get https://github.com/digiblur/Tuya-Convert-Donor bin file by cloning
- flash doner bin file onto wemos d1 mini on mac by running `tasmotizer.py` and following steps from youtube video: https://www.youtube.com/watch?v=_UnI6cnzF3k, but using donor bin file instead
- after it's flashed, remove it from your mac, and plug it into the raspberry pi via usb, on raspberry pi reboot, it should have blinking blue led
Flashing with tuya-convert via Raspberry Pi:
- boot your raspberry pi
- ssh in
- `cd tuya-convert; sudo ./start_flash.sh` on raspberry pi to start tuya-convert (reference https://www.youtube.com/watch?v=dt5-iZc4_qU)
- wemos will flash blue on start up of raspberry pi, on connecting to vtrust wifi after start_flash, will be solid blue to indicate connection
- plug in your plug, it may be in set up mode out of the box, indicated by flashing blue power button (if not, press and hold for six seconds)
- back on raspberry pi `start_flash` process, say `y` to turning off services that tuya-convert needs
- press enter to confirm
- choose firmware software (haa-single.bin), 2 when I did it
- confirm with `y`
- if you have another device to flash, plug it in, make sure it is in set up mode, and say "y" to "Do you want to flash another device?"
- repeat as before
- answer "n" to "Do you want to flash another device?" when done and tuya-convert will exit, shutdown or reboot the raspberry pi as appropriate for your set up
Now your flashed plugs will have created wifi networks for each of them, they will be named with "HAA-" prefix and then random six character string with numbers and letters.
This is the `json-string` config that I used from a github issue comment (NOTE: trim off any extra spaces at the beginning and end of config before pasting it in):
{"c":{"b":[{"g":13,"t":5}]},"a":[{"t":2,"0":{"r":[{"g":2,"v":1},{"g":15}]},"1":{"r":[{"g":2},{"g":15,"v":1}]},"b":[{"g":13}]}]}
For each one of the plugs, do the following:
- have the json string for configuring the device ready, you'll need to paste it into the configuration shortly
- connect to the plug's `HAA-...` network as your wifi network from your mac
- the join network dialog will open, paste in json config, choose your normal wifi network (the one that you use for your iphone, etc.), enter your network password, click save
- "save" will cause plug to reboot (you'll have to "send" even though the form is insecure), wait up to 8 minutes for it to fully restart, you can also check your router for the device and get its ip (handy if you need to troubleshoot)
- in the meantime, your mac should have rejoined your normal network, double check this is the case
- on your iPhone, go to Home app, click "+" icon to add accessory, click "I don't have a code or cannot scan" button, under "Manual Code", click the "Enter code..." link, enter 021 82 017, wait
- confirm that you want to add uncertified device by clicking "Add Anyway"
- wait
- configure the plug (rename, choose room, etc.) as you want
- repeat for next plug
Troubleshooting:
- With my first attempts, I had to trial and error the json string code. The Home app wouldn't recognize the plug after I had done the "join the network" step. The way around this was thanks to this reddit comment. The trick was to go to the full configuration form by visiting the ip for the plug (on the main wifi network) in a browser, enter a json string that you think works for your device, make sure to "Reset HomeKit ID" before saving.
There are 0 comments in this discussion.
join this discussion