Relay Automation Assistance

Good Day!
PREFACE:
I’m trying to setup an automation that waters my plant based on a soil moisture sensor. I’ve seen topics similar to this but none really fully automate the process like I’m looking to do. So let me break it down, The object of my automation is to wait for the sensor to hit “500” which is the number I have identified as the soil being just about right for moisture level. It then waits 3 minutes to make sure it consistently stays at or above 500 before firing the actions. The action then turns on a relay connected to a pump for 3 seconds and then turns it off again and waits for the cycle to repeat until the sensor is at or below 500. A note, for some reason on is off and off is on for my relay. I probably got something backwards but that’s how it is. I hate it too, but lets be real I’ve just been living with it.

PROBLEM:
Aside from the obvious relay reversal, the pump never engages. Ive tried a few different ways and I’ve gotten the pump to engage and then it never turned off…that was a disaster.

CONCLUSION:
Please take a look at my automation and help me perfect this. I would greatly appreciate any assistance!

alias: Water Plant
description: ''
trigger:
  - platform: state
    entity_id: sensor.tasmota_analog_a0
    from: '500'
    for: 3 minutes
condition: []
action:
  - type: turn_off
    device_id: 467427113d088280d85f31438af34fbf
    entity_id: switch.tasmota
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - type: turn_on
    device_id: 467427113d088280d85f31438af34fbf
    entity_id: switch.tasmota
    domain: switch
mode: single

If I understood your requirements correctly, you want this behavior:

  • Trigger when sensor is above 500 for 3 minutes.
  • Turn on (reversed: off) a relay for 3 seconds and then turn it off (reversed: on) for 3 seconds.
  • Repeat this toggling action until the sensor is <= 500.

If that’s correct, then I believe this does what you want:

alias: Water Plant
trigger:
  - platform: numeric_state
    entity_id: sensor.tasmota_analog_a0
    above: '500'
    for: '00:03:00'
action:
  - repeat:
      sequence:
        - service: switch.turn_off
          entity_id: switch.tasmota
        - delay: '00:00:03'
        - service: switch.turn_on
          entity_id: switch.tasmota
        - delay: '00:00:03'
      until:
        - condition: template
          value_template: "{{ states('sensor.tasmota_analog_a0') | int <= 500 }}"
mode: single
1 Like

Perhaps you connected the pump between NC and COM?
That will make it “reversed”.
I suggest you fix that or if you have a power supply failure on the device that triggers the relay, the pump will be on until you notice/get home.

1 Like

Also the relay will be constantly held closed. A bit of a waste of energy and it may get warm

1 Like

This is exactly what I was looking for, I didnt even think to use the “repeat” action! Thank you so much!

1 Like

And that fixed that problem! Heck yes. It works like a charm now!!!

Glad to hear the suggested automation answers the original question.

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title and a link below your first post that leads to the Solution post. This signals to other users that this topic has an accepted solution and helps them find answers to similar questions.

Please note that only one post in the entire topic can bear the Solution tag. Typically, the Solution post answers/solves the original question/problem. In other words, a topic can have many questions but the goal of the Solution post is to resolve what’s presented in the first post.