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
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:
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 and I always have a fully charged bike for the next tour.
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.
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