Smart plug, switch off when power consumption is less than.. switches off straight away each time!

Hi all,

New to this so may be being very silly… would appreciate your thoughts on what may be wrong. I have a smart plug attached to a vacuum cleaner. To try out automation, I am wanting to write a script that turns off the smart plug when it goes below a certain power threshold (basically protect the batteries from going above 80% charge). In my case thats 15 watts. So I have two entities;

  1. The switch itself, “switch.X”
  2. The power reported by the switch “sensor.Y”

I wrote the following, however whilst the charger is well above 15 watts, when I click to run the automation it switches the power off straight away every time… so does not appear to be monitoring the request to switch off only after 1 minute of below 15w

alias: Vacuum charger manager
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.Y
    below: 15
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - type: turn_off
    device_id: 799e39eaf00b4afaeb55f93307c61999
    entity_id: switch.X
    domain: switch
mode: single

The trigger will only fire when the state crosses the threshold. Meaning, it will need to go from 16+ to less than 15, then if it stays below 15 for 1 minute, you’ll get the trigger.

It will not trigger if the threshold is not crossed. I.e. if your state is 14 and it changes to 13, it will not trigger.

1 Like

Running an automation from the UI only tests the action part, not the trigger. To test that you could change the value of sensor.Y in Developer Tools.

1 Like

Thanks, noted. Its kind of weird in that it was at 15.4w when I press ‘Run’ on the rule and it immediately turned off… (obviously I am expecting to observe it turn off after falling below 15). But, now I have left it alone (ie the rule is still ‘ON’, I did not press ‘Run’ again)… I turned on the switch and it left it alone and it worked!

When you press run you skip the triggers as stiltjack pointed out. So it doesn’t matter what the value is, it’s just going to run when you press run.

1 Like

Sorry I am with you both now. For a novice, it does seem a little confusing that clicking run on a automation would skip part of the rules you have written.

1 Like