One of the popular questions on r/Tasker forum is how to prevent mobile phone from charging when it reaches 100%. Even though modern phones are smart enough to minimise the damage caused by overnight charging, some people would sleep better knowing that their phone isn’t constantly hooked up, so let’s fix that. The project aims at Sonoff Micro (review), but you can use it with other smart switches and sockets.
I’m going to use a wireless stand for 2 reasons.
Reason 1: I use a wireless stand. There are many wireless stands, but this one is mine – Choetech Wireless Charger (review).
Reason 2: I can show you how to use Any Sensor to “recognise” a charger, or a position the phone is in, to be specific.
Gyro – position in 3D space
The new Tasker trigger has the ability to read raw sensor data. A stream of information usually reserved for the Android OS. One of the sensor – gyroscope, defines the phone orientation in 3D space. I can use this data to “save” the position of the phone when on the wireless stand.
Place the phone on the stand and wait a couple of seconds. Record the gyroscope values. I set a very low tolerance
1. This profile should trigger only when my phone is resting on the stand and not being held in my hand in a similar orientation.
Now, the phone knows when it’s connected to this particular charger. And guess what else is connected to this charger? Sonoff Micro! I defined the charger, I will use eWeLink API to control my Sonoff Micro.
If you don’t know what NodeRED is and why you should care, take a look at this NodeRED series for beginners. Thanks to eWeLink API, I don’t even have to flash a custom firmware to control the Sonoff Micro. Simply install
node-red-contrib-ewelink node in the Palette Manager.
I’m going to use HTTP requests to control when to turn the charger on and off. The flow is simple – receive the payload from my mobile phone, change the values to match eWeLink interface and submit the
on|off to my Sonoff Micro when needed.
I could resolve this with a single function node, but I want to keep the flow as visual as possible.
There is more than one way we can skin this cat. You can modify my scenario to your liking but it works like this by default:
- Sonoff Micro power on logic keeps it OFF
- Mobile phone turns the charging ON when the battery is lower than 90%
- Mobile phone turns the charger OFF when the battery is at 100%
- Charger doesn’t turn off when the phone is removed (can be done)
With these rules set, my phone will turn on the charger (if needed) and charge the battery till 100%. Once charged the power is cut off, unless the battery power drops down under 90%.
To send the
ON|OFF command I use HTTP Post action. The action is wrapped in IF condition, and sent after 5 seconds, as I want to make sure the phone is placed on the charger and it is not moving. An associated profile responsible for charger detection sets a variable when the phone is resting on the wireless stand.
If the phone is in that position for 5 seconds, then the HTTP Post is sent to start the charger (battery
0-90%) or stop the charging process (battery
In my overnight test, this
100%>90%>100% happened just once. It will depend on the discharge speed of your mobile and the threshold set.
Is it good for battery?
The battery tech improved a lot over the years and your phone should be fine being plugged overnight as is. The gain of using this profile is not going to be amazing, but it can reduce the number of charging cycles. If this profile helps you sleep better at night, that will be its biggest contribution to your wellbeing.
I have done this “because I could” and to illustrate how you can interact with Tasker, NodeRED and other systems to create something interesting.
Playing with Tasker is always fun. Now you should know how to use sensors to define the phone’s location and how to take advantage of it. Feel free to modify, add more features and share this profile with others, as it’s fun to work on projects when locked indoors! Let me know if you have any questions in this Reddit thread.
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.