Automation - Current below value not triggering

I have a smart power switch that I want to shutdown when I power off the connected device. However the automation is not triggering. I built the automation using the GUI, but to make it easy to share, here is the YAML:

alias: Turn off Office Bitch
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.tp_link_smart_plug_4f5b_current
    below: 50
    for:
      hours: 0
      minutes: 0
      seconds: 5
conditions: []
actions:
  - type: turn_off
    device_id: fea2ba64d330ac07c81eb3f0a701b1ef
    entity_id: 20f08ca09bdba6144ee887b2cafa0522
    domain: switch
mode: single

When using the device connected to the switch, the Current being used is 200w+ and when the device turns off, it uses around 11w.

Can anyone see an issue with my automation and suggest why it is not firing for me.

Thanks

Is there a reason you’re not using the on/off state of the switch as the trigger instead?

EDIT Oops, I skim-read the OP, my bad. So if you need to power the device down, before switching off the smart plug, that would make sense.

Weird that it won’t trigger from the change in current, but you have options. For example, you could make a template binary sensor that shows an on state when the current is above 50W and off when below 50W, then use that as your trigger.

Something like this -

template:
  - binary_sensor:
      - name: "Device Status" #(name it whatever you want)
        unique_id: device_status
        state: >
          {{ states('sensor.tp_link_smart_plug_4f5b_current') | float(0) > 50 }}
        device_class: power

As far as the actions, it’s best to avoid using device_id’s, as those can change for a multitude of reasons. Stick to just using the entity_id if you can. The entity_id should be the name of the switch, like switch.tp_link_smart_plug_4f5b < This is probably why your automation isn’t working to begin with if I had to guess…

Also make sure this isn’t biting you. It has to be above the trigger level and will trigger when it falls below it. Automations #1: trigger only fires when it changes from not true to true

and as Matt said, Why and how to avoid device_ids in automations and scripts

I think you’re mixing up power and current.

Power is measured in Watts (W), current in Amps (A). It looks like you’re reading the current sensor from the smart switch — if that gets anywhere near 50A you will have a pool of molten cheap electronics on your floor.

Look for an entity ending in _power instead.

I was using the wrong measurement, this is the device options:

I have changed it over to Current consumption now, on the computer now so when I turn it off later, the automation theoretically should work.

As to using device IDs, I used the GUI to build the automation, so that is what it generated. I would have used names if creating by hand, makes more sense to me.

That’s really misleading naming. The “current” in “Current consumption” means “right now” (power), whereas the “Current” on its own means “Electricity flow”.

You can use entities in the UI too: they’re just not presented as the primary option. Select Switch (bottom of list) rather than Device.

Changing the measurement worked a treat.

As to the IDs, this is what it looks like in the editor with your new option added (both mine and the new actions are there for reference only):

In the YAML it looks like this:

actions:
  - type: turn_off
    device_id: fea2ba64d330ac07c81eb3f0a701b1ef
    entity_id: 20f08ca09bdba6144ee887b2cafa0522
    domain: switch
  - action: switch.turn_off
    metadata: {}
    target:
      entity_id: switch.tp_link_smart_plug_4f5b
    data: {}

I get the distinction in my head, but I don’t understand the difference from the editor’s point of view.

I really appreciate the assistance in getting this working.