stonito logo
Log in

Smarter smart charger

Smart outlets little hacking.

Smart outlets are actually plug-in outlets. You plug them into a wall outlet or a power strip, and have your own outlet to plug into with the device you want to automate. You are neither gaining nor losing any outlets in the process.

I bought an affordable set of those recently. I got them at a regular price of about 26 EUR, so they didn't cost much.

After reading a short manual included in a package, I got an understanding of what they do and what they are capable of. In short, they are operated by a remote controller. They come without any setup, so you can switch them on and off manually bry pressing the single button they have on them. Before being able to operate them remotely, you have to setup them to any of the groups A, B or C. Every switch could belong to one, two or even all three of the groups. To add an outlet to the group, long press the button (3-6 seconds), than release, if the LED is blinking, press the appropriate button on the remote controller, and that makes the outlet member of the group on whose button you clicked on the remote controller. If you want to clear the setup of the outlet, press the same button longer than 6 seconds, and then release it. And this is all you need to know about using the outlets. With remote it functions well.

But if you want to operate smart outlets without a remote controller you will need some hacking. One is to hack into a remote controller, destructive and dirty approach. Second is to sniff the communication between remote controller and outlets and reproduce it, which is a way better solution. To try this solution you need a RF 433MHz transmitter and receiver pair, and I bought the most common one I could find. Both have VCC, GND and DATA pins (receiver has two DATA pins but you use only one), it transmits and receives signal present or not, binary code. You control it with the digital output or read it from digital input.

For sniffing onto communication between remote controller and the outlets, I used the Arduino with a receiver, and the code found in this github project. This software works great and I got my codes in no time.

It is protocol 4, 24 bit, recognized by RC Switch library. Remote controller use two codes for each button and changes them regularly. The change is not necessary for the smart outlets, so one of those two codes is all you need to simulate button press.

With all this under control, an idea of having smarter smart charger project comes into existence.

This smarter version of the older project solves one big problem of its design. Bluetooth sometimes hangs and without restart connection can't be reastablished. And without that connection smart charging can not function.

How does smarter version work?

Hardware is simple and affordable. All this project needs is:

Raspberry Pi

All the code for Raspberry was written in Python 3 and is available on Github. Although the software is simple, it is fully fledged Tcp/Ip Server, has logging and waiting for network connection on boot before starting (pinging the local router), maintains configuration file which is updated by the phone remotely.

Android Software

Software is written in Visual Studio 2022 Community Edition, using Xamarin.

Although the source code is available on the github, just a basic explanation and APK for download, for those who want to use it.

Application expects running Raspberry Pi from the project above.

Application Form

The two sliders defining the upper and lower limits of battery charge level operating range dominates the form.

The lower value means that the charger will always be ON when the battery level is less than that value.

The upper value means that the charger will always be OFF when the battery level is greater than that value.

Third slider is a ping interval in minutes. It defines how often does the phone reports its status to the server.

Ping timeout occurs when there is no status received by the server in 2.5 ping intervals..

Commands to switch the charger on or off are going via server. Upon click on the button appropriate command is set to the server, and server executes it by sending correct RF code.

Foreground Service is started on first run. It is a special type of service in Android, that can survive for a longer time.

Android system is notorious for silently killing background services when it senses a lack of memory or other resources.

But foreground service has to maintain notification in the notification area of your phone, as long as it is active.

Service periodically checks (every Ping interval set above) the battery level and reports it to the server.