[Solved] Need help with irrigation system automation

Hy everyone, need some advice on automating my irrigation system. The scenarios is: when moisture is below 40% , the pump must turn ON for 5 seconds and then turn OFF. If moisture is still below 40% the pump should turn On again.
this is my code

- id: '1584717420577'
  alias: Laistymas
  description: ''
  trigger:
  - below: '50'
    entity_id: sensor.moisture
    platform: numeric_state
  condition: []
  action:
  - data: {}
    entity_id: switch.laistymas
    service: switch.turn_on
  - delay: 00:00:05
  - data: {}
    entity_id: switch.laistymas
    service: switch.turn_off

The pump just turn On for 5 sec , then Turn OFF and thats it. Does not activate for second time . So what am I doing wrong?

well, I can see nothing about 40% in your config… did you mean 50%?
on the reason why it does not trigger for the second time - please read how numeric_state trigger works.
basically, it won’t until the moisture won’t get above and then fall below afaik so you need to change your strategy:
add a condition to test the moisture value and if it’s below the level, call turn_on (but who will turn it off?)

The problem is that the Automation start when the Trigger is triggered.

Try like this:

  • add a trigger on the status change of switch.laistymas
  • add a condition to check again the moisture
- id: '1584717420577'
  alias: Laistymas
  description: ''
  trigger:
  - below: '50'
    entity_id: sensor.moisture
    platform: numeric_state
  - entity_id: switch.laistymas
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - below: '50'
    condition: numeric_state
    entity_id: sensor.moisture
  action:
  - data: {}
    entity_id: switch.laistymas
    service: switch.turn_on
  - delay: 00:00:05
  - data: {}
    entity_id: switch.laistymas
    service: switch.turn_off

If this will not work, you can try to separate the pumping in 2 cycle with 2 identical scrips that check the moisture and call the other script:

  1. Automation triggered
  2. Call Script 1 (First cycle)
  3. Call Script 2 (Second cycle)
  4. Call Script 1
  5. Call Script 2
1 Like

Thx Menelao, your solution works as i expected :slight_smile: