I don’t want to leave our ebike battery charger powered on all the time, so let’s have Home Assistant monitor the charging process and switch off the charger when done.
Hardware
I used a Tuya TS011F_plug_3 Zigbee wallplug (available under various brand names). It only supports polling for energy consumption, but that is fine for this purpose. The bike charger plugs into this wallplug.
Usage
To start charging, connect the battery to the charger and press the “on/off” switch on the wallplug. Once Home Assistant determines that the battery is fully charged, it switches off the wallplug. It also sends a notification to our iPhones / Apple Watches informing us that charging is complete, with the actual amount of energy consumed.
Software
The automation is triggered when the wallplug changes from “off” to “on. Also, it triggers when the power is below 5 Watts for over 10 minutes - this indicates that the battery is charged. You may need to play with these numbers for your specific charger and battery.
At the start of charging, the wallplug energy counter is stored in “sensor.var_schuur_acculader_kwh” (I use the Variables+History integration, but you could also create Helpers to store this value)
When charging is done, the wallplug is switched off. Consumed energy is calculated and sent as part of the notification message.
The Home Assistant automation YAML looks like this:
alias: Schuur - Acculader
description: Fietsaccu lader in de schuur
trigger:
- platform: state
entity_id:
- switch.schuur_acculader
from: "off"
to: "on"
id: schuur_acculader_start
- platform: numeric_state
entity_id: sensor.schuur_acculader_power
for:
hours: 0
minutes: 10
seconds: 0
below: 5
id: schuur_acculader_finish
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: schuur_acculader_start
sequence:
- service: variable.update_sensor
data:
replace_attributes: false
value: "{{ states('sensor.schuur_acculader_energy') }}"
target:
entity_id: sensor.var_schuur_acculader_kwh
- service: notify.all_iphones
data:
title: Fietsaccu
message: >-
Acculader is ingeschakeld, beginstand {{
states('sensor.var_schuur_acculader_kwh') }} kWh.
- conditions:
- condition: trigger
id: schuur_acculader_finish
- condition: state
entity_id: switch.schuur_acculader
state: "on"
sequence:
- type: turn_off
device_id: 4b2c9083c0ffee1d3fffa35ddeadbeef
entity_id: switch.schuur_acculader
domain: switch
- service: notify.all_iphones
data:
title: "Fietsaccu is opgeladen "
message: >-
De fietsaccu is opgeladen met {{ ( ( 1000*
states('sensor.schuur_acculader_energy') | float ) - ( 1000*
states('sensor.var_schuur_acculader_kwh') | float ) ) | round()
}} Wh, de lader is uitgeschakeld.
mode: single