Help needed with an automation trigger

Hi,

I have been think / googling how to create this trigger for my sump pump automation, I am not sure if it’s possible hence the question.

I need an automation to detect if the sump pump has not been on for long enough ie failed for some reason. I have a sonoff POW to detect it’s current and an input slider to say how long should be on for.

I need my trigger to be “when current > 1 amp for less than input slider duration”

On the automation wizard it’s only possible to have a duration for more than xx time. Is it / how is it possible to have a duration that is less than?

Regards
James

I think you are going to run into a problem with a trigger like that.

As soon as you turn the pump on (current > 1amp) if you use a “< time” it’s pretty much going to trigger immediately. So as soon as the pump turns on it will trigger.

Then it will never trigger again until the pump turns back off (current < 1amp) and turns back on. At which point it will immediately trigger again.

I don’t think that’s what you want.

What I would do is to create a input_datetime to store the time the pump turned on which is set in an automation.

Then you can trigger your failure test automation by the pump going to off and a condition that the time < input_datetime timestamp + minimum time in seconds.

There might be an easier way to do it but right off the top of my head I think it will work.

You could try something like this:

- alias: pump
  trigger:
    platform: numeric_state
    entity_id: sensor.current
    above: 1.0
  action:
    - wait_for_trigger:
        platform: numeric_state
        entity_id: sensor.current
        below: 1.0
      timeout:
        minutes: "{{ input_number.time }}"
    - condition:
        condition: template
        value_template: "{{ not wait.completed }}"
    - service: persistent_notification.create
      data:
        message: "Pump not on long enough!"

Essentially, when the pump turns on, it waits until either the specified time has elapsed (the timeout) or the current drops below the threshold. If it doesn’t time out, the current dropped before the timeout and you can take some action.

1 Like

Many thanks for your reply. Over the last few days I have had a play with this automation, the problem is that it triggers after the ‘duration’ regardless if the current has been above 1A for the duration or not.

- id: '1616536061782'
  alias: Irrigation alert
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.sump_pump_energy_current
    above: '1.0'
  condition:
  - condition: state
    entity_id: input_boolean.irrigation_error_alert
    state: 'on'
  action:
  - wait_for_trigger:
    - platform: numeric_state
      entity_id: sensor.current
      below: '1'
    timeout:
      minutes: '{{ states.input_number.duration.state | int }}'
  - condition:
      condition: template
      value_template: "{{ not wait.completed }}"
  - service: notify.james_pushover
    data:
      message: Pump not on long enough!
  mode: single

How about something like this:

binary_sensor:
- platform: template
  sensors:
    sump_pump_running:
    - value_template: "{{ states('sensor.sump_pump_energy_current')|float > 1 }}"
automation:
- trigger:
  - platform: state
    entity_id: binary_sensor.sump_pump_running
    to: 'off'
  condition:
  - >
      {{ trigger.from_state is not none and
         (now() - trigger.from_state.last_updated).total_seconds() <
         states('input_number.duration')|float|multiply(60) }}
  action:
  - ...