Automation for a pump with a trigger

This pump connected to Sonoff S31 and consumes about 1A under load and less then .2A when pumping water/air mixture.
The automation should turn ON the pump every 10min and turn OFF after 2min ( this part works)
But the trigger that should turn OFF the pump in 10 sec after condition detected (current < 0.2A.) never fires. By the way It takes about 90 seconds for Sonoff to reports actual current) Need some ideas. what am I missing?
Thank you.

alias: Pump automation
description: ""
triggers:
  - trigger: time_pattern
    minutes: /10
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_s31_sonoff_s31_current
    below: 0.2
    id: Sonoff S31 current less then .2A
    for:
      hours: 0
      minutes: 0
      seconds: 10
conditions: []
actions:
  - choose:
      - conditions: []
        sequence:
          - type: turn_on
            device_id: 1649d5b870e984d9b980198b5f
            entity_id: c41c41b3b8fa09b358ac1a9f1fc30
            domain: switch
          - delay:
              hours: 0
              minutes: 2
              seconds: 0
              milliseconds: 0
          - type: turn_off
            device_id: 1649d5b870e984d973fb980198b5f
            entity_id: c41c41b3b8fa0964858ac1a9f1fc30
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - Sonoff S31 current less then .2A
        sequence:
          - type: turn_off
            device_id: 1649d5b870e984dfb980198b5f
            entity_id: c41c41b3b8fa09648358ac1a9fc30
            domain: switch
mode: single

You need to change the automation mode to restart if you want the current-based trigger to be able to break the automation out of the delay.

Thank you for the link. Always great to learn, the HA is complex, amazing how mach effort poured in the development and documentation.
And unfortunately changing the
mode: restart
did not fix the problem.
Just wondering how the automation part related to the Current trigger reacts to the current that is = 0.0 A when the Timer starts because the pump is not running yet.

I flashed a bunch of S31s with ESPHome and they seem to reliably report current changes within way less than 10 seconds with this line:
cse7766_throttle_interval: "5s"

Triggers are events. In order for the current-based trigger to fire, the value of the sensor’s state has to go from above your specified value to below that value for 10 seconds. If the sensor is only reporting every 90 seconds, and you need, at least, 2 sensors state changes between the pump turning “on” and the trigger firing… then it stands to reason you may never see the current-based sensor trigger within the 2 minute.

@chairstacker and @Didgeridrew Thank you. Let me experiment and report back.

I wish I can mark both post as the Solution. Yes, updating Current sensor in shorter intervals made it work. And good to know that 2 sensor’s state changes required to trigger automation.
In addition I missed to include a trigger in First option.

Glad it worked.
You might want to keep an eye on the size of your history database as you’re now recording 12x the number of current values.
Probably not a big deal for one sensor, though, I guess.

1 Like

I was not thinking about it. Install base is small now but expanding fast :slight_smile:

Like Didgeridrew says and I discovered later the automation was not reliable in some corner cases. When water is low the Current does not change above and the below trigger level during run and the automation will fail.
So a template and If - then is what works for me now.

alias: Pump with trigger based on template
description: ""
triggers:
  - trigger: time_pattern
    id: Triggered every xxx minutes
    hours: /2
    enabled: true
conditions: []
actions:
  - type: turn_on
    device_id: 1649d0e984d88a973fb980198b
    entity_id: c41c41fa09648b358ac1a9f1fc
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - if:
      - condition: template
        value_template: "{{ states('sensor.sonoff_s31_sonoff_s31_current') | float < 0.2 }}"
    then:
      - type: turn_off
        device_id: 1649d0e984d88a973fb980198b
        entity_id: c41c41fa09648b358ac1a9f1fc
        domain: switch
    else:
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
          milliseconds: 0
      - type: turn_off
        device_id: 1649d0e984d88a973fb980198b
        entity_id: c41c41fa09648b358ac1a9f1fc
        domain: switch
mode: restart