What problem does it solve?
Battery life is the number of charge-discharge cycles, and if you leave charging “overnight”, some smartphones will charge to 100% when the charge drops to 99%, which also slightly reduces the battery life, and to solve this problem I created this automation.
What it does
Automatically manages your phone’s charging by turning a smart plug on or off based on the battery level and a defined schedule. Ideal for preserving battery longevity and saving power.
Features
Turn on the socket when battery drops below a user-defined minimum (e.g., 20%)
Turn on during a time window (e.g., between 6:00–8:00) if battery is below a maximum threshold (e.g., 80%)
Turn off automatically when battery reaches 100%
Required devices
A smart plug configured as a switch in Home Assistant
A phone battery-level sensor from the HA companion app or another source
Inputs
Input
Description
Charging Socket
Select your smart plug (switch entity)
Phone Battery Level
Sensor showing the phone’s battery (0–100%)
Minimum Battery Level
Threshold (%) to trigger charging immediately
Maximum Battery Level
Upper limit for scheduled charging
Scheduled Charging Start/Stop
Time window during which charging is allowed if needed
How to use
Go to Settings → Automations & Scenes → Blueprints, click Import Blueprint, and paste the GitHub or Gist URL after you publish the YAML.
Once imported, select the blueprint and click Create Automation.
Configure the required inputs (socket, battery sensor, thresholds, schedule), give your automation a name, and save.
Reload automations if needed (via Settings → Server Controls).
Why you’ll love it
Prevent overcharging: Automatically stops charging at 100%
Smart scheduling: Only charges during a time window when plugged in
Highly customizable: Adjust thresholds and time window to your needs
Reusable: Easy to import and tweak for multiple devices
Thank you for clarifying that it is advisable to keep your smartphone charged at 20-80%. It is true that it is better to keep the smartphone at 20-80% during the day if you have a phone that is often sitting down, but that is not the whole issue.
Battery life is the number of charge-discharge cycles, and if you leave charging “overnight”, some smartphones will charge to 100% when the charge drops to 99%, which also slightly reduces the battery life, and to solve this problem I created this automation.
I will add my answer 100% is not evil for smartphones, most manufacturers put a reserve in advance in order not to overcharge the battery. Charging it 100% is normal, it is an additional 1-2 hours of work
While in this case the AI answer is definitely the consensus, I’ve seen it make terrible mistakes more then once. Google even says so below in tiny letters: “AI responses may include mistakes”. It is in the forum rules that you can not use AI to answer questions for this reason. So please answer in your own words from your own knowledge. We can all Google or use a LLM if we want to.
Depending on the integration used, smart plugs in Home Assistant can appear under different domains:
switch — used by most integrations (e.g., Zigbee2MQTT, LocalTuya, Wi-Fi plugs)
light — used mainly by ZHA, which exposes some plugs as lights
Two blueprint versions are provided to match both cases. Both versions implement the same functionality — managing your phone’s charging based on battery level and schedule — but are adapted to the type of entity your plug uses.
To find out which one you need, check your plug’s entity ID (e.g., switch.smart_plug or light.smart_plug).