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:
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…
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.
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.