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.
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'
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.
after doing something along those lines i thought maybe trying to making it a little more complex but figured i should see if anyone already done it.
Right now I’ve only added zone to my automation that only work if i’m at home.
Thinking of adding a condition to only work between hours so i don’t accidently wake up with my phone on 30% or something. Not really a huge deal since it’s plugged during the drive to work and i can always charge it at my desk but i tend to leave it unplugged if i can help it.
The last thing is to validate it’s actually charging and if not turn off(maybe in a 3rd automation).
Haven’t jumped to node red yet, still verry new to the whole thing of home assistant but i think it’ll be easier there where you can do it in one script.(maybe?)
I’m guessing that if you set the “Charged Battery” to “100” , the charger will never turn off, since the value of the battery will never be above 100 % ?
The intent is to not set to 100 as not is not generally good for phone batteries and there can also be delays in your phone updating HA with the current battery level. I personally set to 90%
This blueprint was setup to be triggered on and off by a battery level within HA (typically a phone’s battery level). If your boat’s battery is registered in HA then you can use this blueprint, but if it isn’t you might want to look at other options.
thanks for the reply - Ive learned more about how automations trigger and work and the one Ive made based on yours is working great (it monitors the SOC on my house bank and enables a Shelly plug to turn on my charger until it reaches target SOC then shuts off (and sends notifications for Charging started and Done)
Works well with my “Honor Magic5 Pro”, many thanks for this automation!
I have set 60% as the lower value and 80% as the upper value. In the history (of the automation), the switching of the plug to “On” appears (below 60% was reached), but not the nightly switching of the plug to “Off” (over 80% was reached). Also does not appear in the automation log, strange.
However, the automation had worked. I can see this in the charge status of the mobile phone in the morning and also in the progress of the plug status.
Any idea what the problem could be? It’s not really important, the automation is working. But I’ve only had it running since yesterday…maybe I should wait a few days first.
The automation is dependent on HA getting your battery status from your phone. When not in use, to save battery, phones go into a sort of sleep state and won’t let background updates, like sending HA the current battery level, as often.
HA receives the required information from the phone, even in the middle of the night. Otherwise the automation would not work and the charging plug would not be switched off when 80% is reached.
Last night, the behaviour was exactly the same as before. Only the last time the plug was switched on is documented in the history, at below 60%. See the following screenshot:
But: If you now click on this message on the screenshot, you will see a different display where the nightly switch-off is shown, see the following screenshot:
So it just seems to be a “problem” with the display in HA as shown in the first screenshot. I would have expected the night-time running of the automation to be displayed there as well. So you just have to search properly to find a place in HA where it is displayed.
So everything is OK, the automation works fine and I have also found a place in HA where this is documented. Thanks again!