Sonoff/tasmota as switch with a delay

i use one of my sonoff basics to turn on/off a water pump. it has a little swimmer switch that turn GPIO14 on when the water reaches a certain level. then the pump needs only seconds to pump off the water and turn off. there are a lot of waves as some water runs back through the pump off pipe and the switch turns on again, and off and on and … you get it.

i would need some kind of delay, before the switching can happen again. unfortunately all the “logic” happens inside the sonoff. is there a better way to configure it?

Maybe this can help.


The sonoff ignores the switch and sends only a mqtt payload to the switch topic.
Then you can make an automation in HA with the mqtt and state trigger for x seconds to switch the relay.

great. thanks rainer. seems exactly what i was looking for - a way to decouple the switch input from the relais output.

omg. i’m sooo bad in programming stuff it hurts, and my brain is twisted …

i got this setup now in a way, that the external switch does NOT trigger the relais, but the sonoff sends a mqtt message:

15:12:13 MQT: cmnd/schachtrelais/POWER1 = ON (retained)

this is what i see when i trigger the schachtpumpe directly in HA

15:16:55 MQT: stat/schachtpumpe/RESULT = {"POWER":"ON"}
15:16:55 MQT: stat/schachtpumpe/POWER = ON (retained)
15:16:55 MQT: tele/schachtpumpe/STATE = {"Time":"2018-07-15:16:55 MQT: tele/schachtpumpe/SENSOR = {"Time":"2018-07-22T15:16:55","Switch1":"ON","SI7021":{"Temperature":22.8,"Humidity":94.9},"TempUnit":"C"}

i added an automation to check for “ON” to turn on the relais

- alias: 'Schachtpumpe EIN'
  trigger:
    platform: mqtt
    topic: cmnd/schachtrelais/POWER1
    payload: ON
  action:
    service: switch.turn_on
    entity_id: switch.schachtpumpe

this does NOT work. nothing happens. triggering the automation in HA directly makes the pump start/stop (well, that’s the easy part even for me).

wha is also missing is an idea on how to add some timer or delay. i want the pump to be activated for at least a minute as soon as it receives an ON-trigger signal. then check for it after 60s and sees if it’s still on, etc …

how could i achieve that?

Try it with quotes around the payload:

- alias: 'Schachtpumpe EIN'
  trigger:
    platform: mqtt
    topic: cmnd/schachtrelais/POWER1
    payload: 'ON'
  action:
    service: switch.turn_on
    entity_id: switch.schachtpumpe

Use another automation:

  - alias: schachtpumpe_off
    initial_state: True
    hide_entity: False
    trigger:
      platform: state
      entity_id: switch.schachtpumpe
      to: 'on'
      for:
        minutes: 1
    action:
      service: homeassistant.turn_off
      entity_id: switch.schachtpumpe
1 Like

thanks rainer. that works better than anything i was able to do yet :slight_smile:
still it does NOT stay on, or extend the relais time. it seems it only reacts on state change.
this leads to the following situation: schachtrelais is ON, schachtpumpe turns ON for a minute, then turns off, and STAYS off. is this the expected behaviour?

Forgot your swimmer switch from post 1.
Sorry, i’m out of ideas.

no no. it works fine so far. normally acitvating the pump for 1min is long enough to empty the well. i could set that to 2min to be super sure.
BUT in case the sensor state switch to ON is missed, OR there is more water to be pumped away, it will never turn on again, as the well will fill more and more.
i guess i’ll just raise the timer. :slight_smile: