Home Assistant

Battery charge limiter with a timed failsafe

A battery below the low mark turns an energy-monitoring plug on. The plug turns off at the high mark, when a max time elapses, or when it never draws power, and a failsafe cut-off sends a notification.

Difficulty · BeginnerSetup · 20–40 minutesHA · current stable (blueprint)
Get the pack · from $9Have us set it up

Some hardware links on this page are affiliate links. As an Amazon Associate I earn from qualifying purchases. We may earn a commission if you buy through them, at no extra cost to you. See the affiliate disclosure.

A charger left on a full battery all night is a dumb timer. A charger that never started, because the cable is loose, is worse if the only signal you trusted was “the plug is on.” This blueprint turns the plug on when a battery sensor drops below a low percent. It starts a failsafe timer only after the plug reports real watts. It turns the plug off at a high percent, when that timer finishes, or when the watts never show up, and it notifies you on those last two.

Entity ids are blueprint inputs. Do not publish which phone, tablet, or battery this is.

A plug that runs for a fixed time after you switch it on is the relay auto-off timer. A plug that cares about a schedule and whether the room is occupied is the space-heater plug manager. This one cares about a battery percent and a deadline.

What problem it solves

You want a battery to stop charging at a percent you pick, and you want the plug to drop out on its own if the session runs too long or the charger never actually draws power.

How it works

Needs a battery sensor in percent and a plug that exposes both a switch and a power sensor in watts. The Companion app’s battery sensor is the usual source. Any other battery entity with a percent works the same way.

  1. Low percent turns the plug on — the battery falls below the low mark (pack default 20). The switch turns on. One automation per battery. A second device gets a second automation and its own timer.
  2. Watts have to show up — for the no-draw window (pack default 2 minutes) the blueprint watches the plug’s power sensor. At or above the floor (pack default 2 W) it starts the failsafe timer for the max duration (pack default 3 hours). The timer helper is created with restore, so a Home Assistant restart keeps the remaining time.
  3. High percent is the normal stop — at or above the high mark (pack default 80) the plug turns off and the timer is cancelled. That path does not notify. Charging finished.
  4. The timer is the failsafe — if it finishes while the plug is still on, the plug turns off and the notify service runs. The message says the max time elapsed and includes the battery percent at the cut-off.
  5. No watts is the other failsafe — if the plug is on and power stays under the floor for the whole no-draw window, the plug turns off and the notify service runs. The message says no power was seen. The timer is not started, because charging never began.
  6. A restart mid-session — below the high mark, with the plug on and the timer still running, the blueprint does not turn the plug off just because Home Assistant booted. The restored timer is still the deadline.

The blueprint takes a switch or a light for the plug, because some energy plugs show up as lights. The power sensor is still required. A switch with no watt sensor cannot run this pack.

Hardware notes

  • Plug. A switch plus a power sensor in watts. The linked plug is a Kasa 15 A energy-monitoring plug. A switch-only plug can turn on and off, and it cannot tell a loose cable from a real charge.
  • Battery sensor. Home Assistant Companion, or any percent sensor from 0 to 100. The device has to be online enough to report that percent. A battery that is fully off does not update, and this blueprint will not see it cross the low mark.
  • Timer. One timer helper per battery, duration left at 00:00:00. The blueprint sets the duration when watts confirm. Turn restore on.
  • Notify. Companion or any notify service. The token stays in the integration. Never paste it into the blueprint.

Snippet

Inputs replace real entity ids. This is the branch structure, not every condition:

trigger:
  - trigger: numeric_state
    entity_id: !input battery_percent
    below: !input low_percent
    id: low
  - trigger: numeric_state
    entity_id: !input battery_percent
    above: !input high_percent
    id: full
  - trigger: event
    event_type: timer.finished
    event_data:
      entity_id: !input charge_timer
    id: failsafe
action:
  - choose:
      - conditions:
          - condition: trigger
            id: low
        sequence:
          - action: homeassistant.turn_on
            target:
              entity_id: !input charger_plug
          - wait_template: "{{ states(power) | float(0) >= power_floor }}"
            timeout:
              minutes: !input no_draw_minutes
          - if:
              - condition: template
                value_template: "{{ states(power) | float(0) >= power_floor }}"
            then:
              - action: timer.start
                target:
                  entity_id: !input charge_timer
                data:
                  duration: !input max_charge
            else:
              - action: homeassistant.turn_off
                target:
                  entity_id: !input charger_plug
              - action: !input notify_service
                data:
                  title: "Charger cut off"
                  message: "No power draw on the plug."
      - conditions:
          - condition: trigger
            id: failsafe
        sequence:
          - action: homeassistant.turn_off
            target:
              entity_id: !input charger_plug
          - action: !input notify_service
            data:
              title: "Charger cut off"
              message: "Max charge time elapsed."

power, power_floor, and the high-percent turn-off are the rest of the blueprint. Pack defaults are 20 percent, 80 percent, 2 W, 2 minutes, and 3 hours. Reaching the high mark cancels the timer and does not notify.

Setup outline

  1. Create a timer helper. Restore on. Leave the duration at zero.
  2. Import the blueprint. Select the battery percent, the plug switch, the plug power sensor, the timer, and the notify service.
  3. Leave the defaults for a first session, or set the high mark to the percent you actually want to stop at.
  4. Discharge below the low mark, or set the low mark above the current percent for a test. The plug should turn on. Within two minutes the power sensor should be above 2 W and the timer should be running.
  5. Unplug the cable from the device and run it again. The plug should turn off and the no-draw notification should arrive. Plug it back in, let the timer run, and confirm a normal stop at the high mark sends nothing.

Troubleshooting

  • The plug never turns on. The percent sensor is unavailable, or it is already above the low mark. Read the sensor in Developer Tools. A device that is off does not report.
  • The plug turns on and off two minutes later. Power stayed under 2 W. The cable, the brick, or the watt sensor is the problem. Raise the window only after you have seen a real charge sit above the floor. Do not set the floor to 0. That makes “no draw” impossible to see.
  • It charges past the high mark. The percent sensor stopped updating while the device slept. The timer is the backstop. Shorten the max duration if the sensor goes quiet for hours.
  • A restart turned the plug off. The timer helper does not have restore on, so the blueprint treated a missing timer as finished. Turn restore on and start a new session.
  • You wanted a heater schedule. That is the space-heater plug manager. You wanted “I turned it on, turn it off in an hour.” That is the relay auto-off timer.
  • Two batteries, one timer. They will cancel each other. One timer helper per blueprint instance.

Credits

Based on the community blueprint Safer Battery-Controlled Charging & Timed Failsafe Manager (source). That blueprint starts a timer when the device reports a charging state and cuts the plug at a high percent or when the timer finishes. This write-up is an original overview that keeps the percent marks and the max-time cut-off, and adds the watt check: no power on the plug turns it off and notifies. The tag trigger and the discharge grace period from that blueprint are not in this pack.

Changelog

v1.0 · Oct 28, 2026: First publish.