Creating a charger cut-off automation

Hi,

I have a familty E-Bike which I charge in my garage, the charger is connected to a TP-LINK HS110 plug which is able to observe energy consumption. The thing is I’d like to turn off the switch when the power draw drops below let’s say 10w.

If I use the following automation the automation is triggered even when the switch has been idle and the charger hasn’t been connected to it at all, which is obviously not the desired situation

Here’s the automation for reference

Thanks all for reading through this and for your assistance

You may need to create an input_boolean and turn in on when the socket is drawing charging levels of power. Then create a condition to only run the action of the input_boolean is on.

Be sure to add an action to turn the input_boolean off at the end of your automation.

To be honest I’m not sure what you mean by “even when the switch has been idle”, but I have a similar setup for turning off an e-bike charger after the battery is full. Maybe you find this useful for your use case as well.

To turn the charger on I use some simple automations with a presence trigger (i.e. turn on if I’m home for 10 minutes) or timed triggers (turn on at 4 a.m.). I can also turn on the plug manually with a wall switch.

Then I created a template sensor that translates the state and power consumption of the plug to some discrete states:

- platform: template
  sensors:
    kg_ebike_laden_status:
      friendly_name: "KG e-Bike laden Status"
      value_template: >-
        {% if is_state('switch.kg_ebike_laden', 'off') %}
          off
        {% elif states.sensor.kg_ebike_laden_stromwert.state | int > 50 %}
          charge
        {% else %}
          nocharge
        {% endif %}

Explanation: The state of the sensor is off, if the plug is switched off, charge, if the charger draws more than 50 mA and nocharge, if the charger draws less than 50 mA.

This template sensor is then used in an automation, that switches off the plug, if the template sensor is in status nocharge for more than 15 minutes:

- id: kg_ebike_laden_ausschalten
  alias: KG e-Bike laden ausschalten (wenn fertig geladen)
  initial_state: 'on'
  trigger:
  - entity_id: sensor.kg_ebike_laden_status
    platform: state
    to: 'nocharge'
    for:
      minutes: 15
  action:
  - service: switch.turn_off
    entity_id: switch.kg_ebike_laden

This is working pretty reliable. The only thing I have to remember is to plugin the charger into the bike, when I’m coming home :slight_smile: and I always have a fully charged bike for the next tour.

1 Like

Edit: I think, I now understand what you want to achieve. You want to only trigger turning the switch off and the alexa message, if the bike has been actually charged before, right?

That’s possible, but may be sometimes a little more complicated, than one would assume at the first sight.

Depending on the model of the charger you may run into the problem, that the device produces short peaks in power consumption in different situations. For example if it is turned on, even if it’s not plugged into the bike. Or if the charger is trickle charging the battery

If you just monitor the current power consumption, your automation may be triggered in these cases as well and you have no idea, why.

To flatten out these peaks you may have to use a History Statistics Sensor, which calculates the duration of a state:

With this sensor you can measure the duration, the power consumption exceeded a certain level in a given time frame and only trigger the automation, if f.e. the charger drew more than 10 watts for at least 15 minutes in the last hour.

1 Like

Thanks for that @derandiunddasbo, I adapted your solution, let’s see if it works for me as well.
@silvrr I appreciate your answer and has learnt from it as well

Hey @ohadbenita did you get it to work? I want to do something similar for my e-scooter charger, and I would really like to see your solution.

I’m testing the following automation as we speak:

First a statistics sensor:

- platform: statistics
  name: "Taga Charger change over the last 3 hours"
  entity_id: sensor.athom_06_power
  state_characteristic: change_second
  max_age:
    hours: 3

Then the automation:

- alias: Turn off Taga Charger when charging is complete
  initial_state: true
  trigger:
    platform: numeric_state
    entity_id: sensor.taga_charger_change_over_the_last_3_hours
    below: 0.01
    above: -0.01
    for:
      minutes: 10

  condition:
    - condition: state
      entity_id: switch.athom_06
      state: 'on'

  action:
    - service: switch.turn_off
      entity_id: switch.athom_06
    - service: notify.mobile_app_benita
      data:
        title: "Appliances"
        message: "Taga Bike is charge cycle completed"

I’ll update here upon success or failure

@ohadbenita So - success or failure?

1 Like

Great success, I just had to change the trigger to be 1 hour instead of 10 minutes.