Phone charger on/off by battery level

Needs a phone that reports battery level to HA and a switch controlling the charger. Automatically turns off charger when the battery level reaches the defined high value and turns back on when the battery level drops to the low value.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: Charge phone
  description: Charges phone until a percentage and then turns off until percentage
    drops below a defined point.
  domain: automation
  input:
    phone_battery:
      name: Phone Battery level
      description: This sensor will be used to determine the charge level of the phone
      selector:
        entity:
          domain: sensor
          device_class: battery
    phone_charger:
      name: Phone Charger
      description: Entity that controls supplying power to the phone
      selector:
        target:
          entity:
            domain: switch
    low_battery:
      name: Low Battery
      description: Battery below which the phone should be charged
      selector:
        number:
          min: 10.0
          max: 95.0
          unit_of_measurement: percentage
          mode: slider
          step: 1.0
    charged_battery:
      name: Charged Battery
      description: Battery above which the phone should stop charging (should be greater
        then Low Battery)
      selector:
        number:
          min: 80.0
          max: 100.0
          unit_of_measurement: percentage
          mode: slider
          step: 1.0
  source_url: https://github.com/apollo1220/blueprints/blob/39a53c112c215be2ffd2968cadd192d6a3acc261/phone_charger.yaml
mode: single
max_exceeded: silent
trigger:
- platform: numeric_state
  entity_id: !input 'phone_battery'
  below: !input 'low_battery'
- platform: numeric_state
  entity_id: !input 'phone_battery'
  above: !input 'charged_battery'
action:
- choose:
  - conditions:
    - condition: numeric_state
      entity_id: !input 'phone_battery'
      above: !input 'charged_battery'
    sequence:
      - service: homeassistant.turn_off
        target: !input 'phone_charger'
  default:
    - service: homeassistant.turn_on
      target: !input 'phone_charger'
    - wait_for_trigger:
      - platform: numeric_state
        entity_id: !input 'phone_battery'
        above: !input 'charged_battery'
      continue_on_timeout: false
    - service: homeassistant.turn_off
      target: !input 'phone_charger'
3 Likes

I don’t see how to specify the charger controlling switch using the UI. Am I missing something?

It’s the “Phone Charger”, second item in the list.

1 Like

Ah, got it, thanks. The row of buttons rather than a drop down threw me. I read “Area” and stopped looking at that line :wink:

is it broken ? since update i must unlock phone and open HA to get relay on / off

Yeah something has messed it up. It’s been seemingly randomly working and not working for me lately.

Maybe you want to test Wallpanel Battery Management - #15 by seamus65 which is basically doing the same (and there are no reports it doesn´t work anymore).

1 Like

still a noob to all this, I have 2 automations for my wallpanel one for on and one for off for charging, but that still works so glad I did not install any of these as I thought it would be cleaner ill try to adapt it to a blueprint to help out

It isn’t universal. There isn’t actually anything wrong with the blueprint itself. It is certain phones not sending their current charge level to Home Assistant in a timely matter that makes them “not work”. There is nothing that can be done from a blueprint or an automation to get the battery level correctly, they can only read the value Home Assistant makes available. So it still completely works, just there is a delay at the Home Assistant level in some cases.

1 Like

On IOS, you can use Shortcuts to: When: “battery level is 80%” Do: “Home Assistant - Update Sensors”.

1 Like

For info … Android 12 now has this functionality built in: Settings - Battery and Device Care - Battery - More Battery Settings - Protect Battery

3 Likes