Re-Trigger automation when conditions are met

Hey :slight_smile:
Is there a go-to way to re-trigger automations once conditions are met?

I have an automation that turns off a device once it false below a certain power consumption but only when a few conditions are met:

  • witihin specific time window OR when not at home
  • etc.

The trigger is that if power is < 25W for some time.

However, if the conditions aren’t met, the power stays below 25W but later on the conditions would pass of course there is no new trigger.
I figure I could somehow add all conditions as slightly modified as triggers, add the original as condition but this feels cumbersome and I was wondering whether there is a more generic way to do this.

For reference, please find the automation attached.
Notice that I even needed a helper sensor “max power schreibtisch” with history of some minutes to be able to properly add the condition if power < x for some time t.

alias: Schreibtisch ausschalten
description: ""
  - alias: Desk power consumption below threshold for certain time
    platform: numeric_state
      - sensor.schreibtisch_shelly_switch_0_power
      hours: 0
      minutes: 10
      seconds: 0
    below: 25
  - platform: state
      - input_boolean.auto_power_off
    to: "on"
      hours: 0
      minutes: 0
      seconds: 10
  - platform: time
    at: "18:10:00"
  - platform: numeric_state
      - zone.home
      hours: 0
      minutes: 10
      seconds: 0
    below: 1
  - platform: numeric_state
      - sensor.max_power_schreibtisch
    below: 25
  - alias: Confirm Plug is on
    condition: state
    state: "on"
    entity_id: switch.schreibtisch_shelly_switch_0
  - condition: state
    entity_id: input_boolean.auto_power_off
    state: "on"
  - condition: or
      - alias: Check days and times
        condition: or
          - condition: time
            after: "18:00:00"
            before: "08:00:00"
              - mon
              - tue
              - wed
              - thu
              - fri
            alias: Confirm outside working hours on work days
          - condition: time
              - sat
              - sun
            alias: Confirm weekend
      - condition: numeric_state
        entity_id: zone.home
        below: 1
  - condition: numeric_state
    entity_id: sensor.max_power_schreibtisch
    below: 25
    above: 2
  - alias: Notify
    service: notify.notify
      title: Energie Sparen 🔋
      message: >-
        Schreibtischleiste wurde ausgeschaltet weil der Verbrauch unter den
        Grenzwert gefallen ist.
  - service: switch.turn_off
    metadata: {}
    data: {}
      entity_id: switch.schreibtisch_shelly_switch_0
mode: single
  stored_traces: 5

if you want to trigger the automation when the conditions are met (ie, when a condition goes from false to true) then you should put that condition into the trigger.

it’s ok to put a condition in both the trigger and the conditions section. in fact, it’s the right thing to do if you want the automation to be re-evaluated everytime any of the conditions are met but executed when all the conditions are met…

carefully internalize that last sentence… that’s the key here.

1 Like

No. That is the way to do it.

I have similar case I am trying to crack.
Having solar panels and battery, I’d like to power some devices off at certain conditions.

Example: power drain is greater then 500W for 10 mins and State of Charge is below 85%

Problem is, I start with SoC of 100%, than the sun goes down, power is being drained from battery and the first condition 500W for 10mins is true, but SoC is false. The automation is not triggered. The power drain is continuously over 500W and SoC is decreasing. But because power is continuously above the threshold, the automation doesn’t kick in.

I can put both conditions in “When” and “If” but I am struggling with the 10mins hysteresis on the power drain (to avoid triggering on some short power surge spike).

Any ideas?


Just as it was explained above.
Put both as your triggers.

OK, that seems to work, I was worried about the “time to trigger” but that is either true from last time it has crossed the threshold, or in case, the battery drain will leave the threshold territory, it will be taken into account next time, it crosses the threshold.

This is good.

I keep the “mode” as single, or parallel? The latter or?