Condition with for

Hey folks,

I have this small automation:

alias: Energiesparen - Marc 2
description: ''
trigger:
  - platform: time_pattern
    minutes: /15
condition:
  - condition: numeric_state
    entity_id: sensor.wall_plug_switch_electric_consumption_w
    above: '5'
  - condition: or
    conditions:
      - condition: device
        device_id: b11360d1f6e5807fba47c5cdd5e9084f
        domain: device_tracker
        entity_id: device_tracker.redmi_note_7_mob
        type: is_not_home
      - condition: time
        before: '06:00'
action:
  - type: turn_off
    device_id: e98be3e524f21981c6f29ca1da5202d2
    entity_id: switch.wall_plug_switch_marc
    domain: switch
mode: single

The Problem I have is, that I only want to do the action, when the entity_id: sensor.wall_plug_switch_electric_consumption_w is above: '5' for at least 15 minutes.

How can I do this?

thanks and regards

Trigger on that then.

  trigger:
    - platform: numeric_state
      entity_id: sensor.wall_plug_switch_electric_consumption_w
      above: 5
      for:
        minutes: 5

I had that allready but it didn’t work

It is a valid trigger and will do what you asked for. As soon as the power goes from below 5W to above 5W and stays there for 5 minutes the automation will trigger.

I use this in several automations, but do use a different for: syntax.
Both should work, but it’s worth a try. One of my triggers` yaml:

for: '00:05:00'
platform: template
value_template: >-
  {{ states("sensor.grid_power")|int(default=0) >
  states("input_number.threshold") | float(default=440) }}
alias: Energiesparen - Marc 2
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.wall_plug_switch_electric_consumption_w
    above: '5'
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: b11360d1f6e5807fba47c5cdd5e9084f
        domain: device_tracker
        entity_id: device_tracker.redmi_note_7_mob
        type: is_not_home
      - condition: time
        before: '09:00'
action:
  - type: turn_off
    device_id: e98be3e524f21981c6f29ca1da5202d2
    entity_id: switch.wall_plug_switch_marc
    domain: switch
mode: single

What does the automation trace say?

No trace available, yet.

Almost a year ago I posted this issue. I am not sure if you bumped into the same issue but for as far as I know, this issue is never fixed. I worked around it by using a helper that stores now + the “for-period” and use that as a trigger. For example:

service: input_datetime.set_datetime
data:
  datetime: '{{ now() + timedelta( minutes = 15 ) }}'
target:
  entity_id: input_datetime.trigger_me

and trigger:

platform: time
at: input_datetime.trigger_me

In your case it’s a messy solution, but with 3 triggers you could make it work.
One trigger above 5, one below 5 and one on the helper.

  1. Above sets the helper
  2. Below sets the helper in the past?
  3. Handles the turn-off
1 Like