Switch off Plug after two conditions reached

Hi,

i have a smart plug and want to automatic turn it off, when two conditions reached one by one.
It only must turn off, when the Plug had a Power Consumption OVER 100 but only when it fells than under 8.

So it MUST be one time over 100 and when it drops than under 8, it must turn off.

The Problem is, that the two conditions cannot reached together.

alias: P1P unter 8 Watt ausschalten
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.cr_6_se_energy_power
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 8
    id: "1"
  - platform: numeric_state
    entity_id: switch.cr_6_se
    for:
      hours: 0
      minutes: 0
      seconds: 0
    above: 100
    id: "2"
condition:
  - condition: and
    conditions:
      - condition: trigger
        id: "1"
      - condition: trigger
        id: "2"
action:
  - type: turn_off
    device_id: ***
    entity_id: switch.cr_6_se
    domain: switch
mode: single

Thats my try.
But i think the problem is, that the two conditions never can reached together, cause it cannot be over 100 and under 8 at the same time.

Is there a way, that he remember that the 100 was reached before or is there something like “from over 100 to under 8” in one trigger?

What if you use above 100 as the first trigger then use the action “wait for trigger” where you specify it to wait until the value is under 8?

Did you have an example? I dont now what you mean with “wait for trigger” i dont have some condition like that :confused:

Example I just made, ignore the entities.

alias: test
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.740_cpu_temperature
    above: 100
condition: []
action:
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.740_cpu_temperature
        below: 8
  - service: light.turn_off
    data: {}
mode: single

i will try it, the idea is good

It triggers, but the plug doesnt turn off :confused:

Also when i click the button to trigger, it doesnt turn off

Any other ideas? Looks like he doesnt do that :frowning:

You need to post your automation again with the changes you did.

alias: P1P finished
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.cr_6_se_energy_power
    above: 50
condition: []
action:
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.cr_6_se_energy_power
        below: 8
  - type: turn_off
    device_id: *************
    entity_id: switch.cr_6_se
    domain: switch
mode: single

That is it… Its really the same.
But i dont know why it doesnt turn off. The turn off alone works if i dont have wait_for_trigger, but both together is not working

what does the automation trace say? I don’t use these conditions myself so just shooting blind here :slight_smile:

I will check next time the trace/logs again and post it. Its gone, cause i changed something, but i will try again.

Lets see what it says, but was not working :confused:

just trigger it manually.

My printer is running on that plug right now, it triggers over 50 on power few times already. When printer its done, it drops under 8 Watt and the wait_for_trigger must be fired and than it must be turn off, right?

Sounds right, but if your printer is already above the threshold in the automation the automation should already be running and you should see that in the trace.

If you are simply waiting for the printer to drop under 8 watts (I assume thats when its idle), why do you need the first condition for above 50 ?

Are you simply trying to turn off your printer when its idle ?

Yes, i see that the numeric_state above 50 is executed

Executed: 8. Januar 2023 um 18:38:01

the wait_for_trigger has that:

This node was not executed and so no further trace information is available.

Yes, the idea is to turn the printer (smart plug) offline, when its done after a print.

But i cannot use just turn off under 8, cause than i never can start a print, cause it turns off everytime while i will start a print…

Sometimes i need 10 Mins to check something, sometimes more or not that much.

So my idea was, when it was over 50 Watt, than i know it was running before. And when it drops under 8 when it was over 50 before, than it must turn off.

Then perhaps add a condition that it has to be under 8 watts for say 5 minutes ?:-

  - platform: numeric_state
    entity_id: sensor.tuya_plug_kitchen_speaker_and_monitor_active_power_3
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 8

That is what if tried first, but sometimes i need more than 5 or 10 or 15minutes… sometimes i going to get a drink while it doesnt need to turn off or something.

It just need to turn off when it has a print done (so when it was over 50 watt), cause every other case is that i just started it before. And if i started it, it doesnt need to turn off after 5 mins.

ok, so you want the printer to be idle for an unknown amount of time before executing the switch off ?
I’m not sure how having the extra above 50 helps with that.

The above would give you 5 minutes from turning the smart plug on to starting a print. Assuming the printer stays above 8 whilst its printing, it would then stay on until its done.

Just add a condition after the 5 minute wait to check again that the power is still under 8 watts, then it won’t switch off mid print:-

  - platform: numeric_state
    entity_id: sensor.tuya_plug_kitchen_speaker_and_monitor_active_power_3
    for:
      hours: 0
      minutes: 5
      seconds: 0
    below: 8
condition:
  - condition: numeric_state
    entity_id: sensor.tuya_plug_kitchen_speaker_and_monitor_active_power_3
    below: 8