Control phone charger to prolong phone battery life

My last phone died due to battery failure so I want to try to prolong the battery life of my new phone. As an Android developer I am a heavy phone user and need to recharge it every day, which might be bad for the phone anyway but I need to make the best of it. Although I do not possess the physics background to check if the theory is correct that stopping to charge the battery when it’s at 80% charge will put less strain on the battery per charge cycle I will give it a try. I usually plug my phone in when going to sleep but instead of just letting it charge to full no matter what the current battery charge it, the following automation will only start charging the phone when it falls below 50% and will stop charging once it reaches 80%.

Used hardware/software

  • Xiaomi Zigbee Smart Plug
  • Phone charger of choice, connected to the smart plug
  • Home Assistant companion app to act as the device tracker sending the battery data
  • Home Assistant automation interface (All of the below code can be clicked together in the UI, no need to write anything by hand)

Automation 1: Turn on phone charger
This automation is responsible for turning on the charger if the phone battery falls below 50% (20% would also be a good choice if you just want to follow the 80/20 rule). I played around with conditions for the device location here (e.g. if the phone is not home there is no use in turning on the charger) but with our local-only Home Assistant setup this is not relevant for us at the time.

- id: '1595610566823'
  alias: Turn on phone charger
  description: ''
  trigger:
  - below: 50
    device_id: 0bade40460214b3b91f7a531661a5d46
    domain: sensor
    entity_id: sensor.mi_note_10_lite_battery_level
    platform: device
    type: battery_level
  condition: []
  action:
  - device_id: fc1aef35dfca459799e9ab15a448e5b7
    domain: switch
    entity_id: switch.smart_plug_phone_birgit
    type: turn_on
  mode: single

Automation 2: Turn off phone charger
This automation is responsible for turning off the phone charger once the phone reaches 80% battery charge. For simplicity I am ignoring if the phone is connected to this charger or somewhere else, I just want to make sure that I can plug the phone in at my bedside table knowing it will not continue charging if the phone is full enough already.

- id: '1595610794021'
  alias: Turn off phone charger
  description: ''
  trigger:
  - above: 80
    below: 101
    device_id: 0bade40460214b3b91f7a531661a5d46
    domain: sensor
    entity_id: sensor.mi_note_10_lite_battery_level
    platform: device
    type: battery_level
  condition: []
  action:
  - device_id: fc1aef35dfca459799e9ab15a448e5b7
    domain: switch
    entity_id: switch.smart_plug_phone_birgit
    type: turn_off
  mode: single

Problems encountered
The only real problem I encountered was the companion app. My new phone uses Android 10, and the newer the Android version the stricter is the handling of background services. And if the phone decides to kill a background service to preserve battery it will do that unless that app has a persistent notification which the companion app does not have. My goal is to switch to a custom Home Automation app in the future where I will directly observe the device battery and based on that trigger the smart plug switch via the deconz REST API (just an idea so far). In the meantime I just make sure to open the Home Assistant app when I notice that the battery state is no longer changing in Home Assistant or if I have an important day coming up where I need to make sure my battery is charged up.
UPDATE: Since version 2.4.0 of the Home Assistant companion app the location updates use a notification, which means this automation now works reliably. :smiley:

Automation in action
On the screenshot you can see that after the phone drops below 50%, the charger turns on, charges the phone for about 1.5 hours, and is then turned off once 80% is reached. I have seen it charge to 84% before turning off, it just depends on when the companion app sends the next location update which includes the battery data. With an actual native Android app that listens to the system battery changes this would be more accurate, but it’s not a big deal.



UPDATE (1.5 years later)

I’m still using the automation and I still own and use the exact same phone.
The big question: Does it help? Does it actually prolong battery life?
Scientifically speaking, I don’t have enough data to conclusively answer this question. With only 1 device under test I can’t tell if it improved anything. But I can present the data I gathered. To monitor battery health I use the “AccuBattery” app. According to this app, the battery health has declined to 82%.

I wonder if this data is actually correct. Looking at the plot with the individual charging cycles there are 2 distinct areas where the dots appear. One at around 5200mAh which is near the design capacity of this battery, and another at around 3000mAh. If the battery health was declining I would expect a gradual change in capacity, but not this jump of 2000mAh. I can’t explain this. Maybe never charging a phone to it’s full capacity messes with the measurement somehow.

If anyone can shed some light on this, I would appreciate it. :open_hands:

https://github.com/Nucifera8472/homeassistant

2 Likes

Nice project! It would be interesting whether this actually prolongs your battery life. So, please do an update in one year :wink:

A little late with the 1y update, but here it is :+1:

1 Like