Trigger switch off based on current power usage

Hi there,

I’m very new to Home Assistant and have had some success with basic automations but not much with anything more complex.

I have my washing machine connected to a TP-Link KP115 smart plug with energy monitoring and I’d like to set it up so that when a load is finished and power draw is at idle (approx 2.5w) for 5 minutes that it switches the plug off and notifies me on my phone. I can’t seem to get this working using the UI editor and I’m not confident with YAML yet.

Could I please get some feedback and advice on how to set this automation up correctly?

Many thanks

alias: Washing machine finished
description: Switch off and notify when finished
trigger:
  - platform: device
    type: turned_on
    device_id: 
redacted
    entity_id: switch.washing_machine
    domain: switch
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: switch.washing_machine
        attribute: current_power_w
        state: below 3
        for: '00:05:00'
action:
  - type: turn_off
    device_id: 
redacted
    entity_id: switch.washing_machine
    domain: switch
  - device_id: 
redacted
    domain: mobile_app
    type: notify
    title: Washing Machine
    message: Your washing is done.
mode: single

Your trigger should be the power under 2.5 for 5 minutes and there is no need for a condtion.

Thanks for the feedback nickrout. Would this be more appropriate? I chose 3w instead of 2.5 because at idle (e.g. when the washing cycle is done and the lights are on) the power usage can be anywhere between 1.5-2.7 w.

 alias: Washing machine finished
description: Switch off and notify when finished
trigger:
  - platform: state
    entity_id: switch.washing_machine
    attribute: current_power_w
    to: below 3
    for: '00:05:00'
condition: []
action:
  - type: turn_off
    device_id: ***
    entity_id: switch.washing_machine
    domain: switch
  - device_id: ***
    domain: mobile_app
    type: notify
    title: Washing Machine
    message: Your washing is done.
mode: single

Wouldn’t it be better to use the “from” in the trigger?
from: above 20???
to: below 3

Like this?

alias: Washing machine finished
description: Switch off and notify when finished
trigger:
  - platform: state
    entity_id: switch.washing_machine
    attribute: current_power_w
    to: below 3
    for: '00:05:00'
    from: above 20
condition: []
action:
  - type: turn_off
    device_id: ***
    entity_id: switch.washing_machine
    domain: switch
  - device_id: ***
    domain: mobile_app
    type: notify
    title: Washing Machine
    message: Your washing is done.
mode: single

FYI, I tried the above automation and nothing happened.
I manually ran the action and both of the actions worked fine - the switch turned off and the notification appeared on my phone.
It had been more than 5 minutes since the washing machine finished (in which time the watts remained below 3).
Is it possible to access a log or something to determine if HA and the plug are playing nice?

yes, on the automations page.

Unless this is an alternate syntax I’m not aware of, it should be

  - platform: numeric_state
    entity_id: switch.washing_machine
    attribute: current_power_w
    below: 3
    for: '00:05:00'
5 Likes

Hooray! That worked :slight_smile: thank you koying.

Found this when searching for a way to switch something on & off depending on the level of Solar PV generation. I am new to Home Assistant and was struggling to get the “terms” & “syntax” right.

The solution helped, and I have now been able to get the following to work in 2 separate Automations:

To Turn On:

platform: numeric_state
entity_id: sensor.power_production_now
above: '3000'

To Turn Off:

platform: numeric_state
entity_id: sensor.power_production_now
below: '2500'

Thanks

1 Like

My entity is a Power Meter from a energy monitor on a cord.

Just getting confused here by the Attribute that was mentioned attribute: current_power_w. Is this actually needed? I Checked the Dev Tools and don’t see that listed as an attribute for the energy monitor entity.

It should be its own sensor now.

This topic seems to capture my problem as well and none of the solutions work in my case. I want to essentially do the same thing (switch a smart plug off when power draw drops below a threshold).

The action works fine, but the trigger just does not. I‘ve also tried using current, but to no success. No errors either. Have confirmed the entity and state in the dev tools. It must be something I‘m not understanding about the plugs, I believe.

This is my very simple code:

alias: Entryway off
trigger:
  - platform: numeric_state
    entity_id: sensor.plug_1_power
    for:
      hours: 0
      minutes: 0
      seconds: 10
    below: "10"
action:
  - service: switch.turn_off
    target:
      entity_id: switch.plug_1_switch
mode: single

Interestingly, this works if I specify the power state of the plug as a condition, not a trigger. Could it be that this only works when switching to a state that the trigger applies to? Then my misunderstanding would be a fairly basic one. Glad if anybody could illuminate.

alias: Entryway off
description: ""
trigger:
  - platform: time
    at: "21:00:00"
condition:
  - condition: numeric_state
    entity_id: sensor.plug_1_power
    below: 2
action:
  - service: switch.turn_off
    target:
      entity_id: switch.plug_1_switch
    data: {}
mode: single

Trigger means the sensor must go from above to below. It won’t trigger if it is already below.

I’m looking to do the opposite. I want to turn a switch off for 5-10min if too much power is being used. Basically like a self-resetting circuit breaker. I have an outdoor wyze outlet and don’t want too much power being drawn.