Help turnin on a switch twice a day

Hello all,

I am attempting my first automation: a plan watering system using a small submersible pump, a relay, an ESP32 WEMOS LOLIN32 (I think it is called this way) and a water level sensor (when the water is above the sensor it stays horizontal and when it goes below it tilts and breaks a connection).

I have managed using the following yaml configuration loaded on the ESP32 to create a switch that when I trigger it manually, stays open for a number of seconds and then turns itself off if the binary sensor is off and it will only turn on for a very short amount of time if the sensor is on:

binary_sensor:
  - platform: gpio
    pin: 
      number: 21
      mode: INPUT_PULLUP
    name: "Level Sensor"
    id: lvldn

switch:
  - platform: gpio
    pin: 26
    name: "Pump Switch"
    id: ps
    on_turn_on:
      then:
        if:
            condition:
              binary_sensor.is_on: lvldn
            then:
              - switch.turn_on: ps
              - delay: 500ms
              - switch.turn_off: ps
            else:
                if:
                  condition:
                    binary_sensor.is_off: lvldn
                  then:
                    - switch.turn_on: ps
                    - delay: 10s
                    - switch.turn_off: ps

What I would like to do from here is the following:

  1. is there a way to avoid turning on the pump for a short while when the sensor state is on?

  2. instead of manually turning on the pump like I do now for testing I would like to have the pump turn on once in the morning (say at 6 am) for 10 mins and once in the evening at 8 pm (for 10 mins) every day and only if the water level sensor is in the off position. If the sensor is on the ideally I would like the pump to not turn on at all (I place the water level sensor in the tank so that the pump will not run on empty but it is better to not turn it on at all if possible) and maybe send me a notification somehow through the HA interface.

Can anyone help a complete beginner with automations?

Cheers,

Lucian

thank you for your reply. can you please clarify it a bit more please? where do I load these automations? on the esp32 yaml file? in the configuration.yaml file of home assistant?

Those are home assistant docs. Use the same as any other automation.

Ok, thank you! I have not made any other automation until this point and I was a bit confused about where these scripts reside, and how to make them work.

I tried last night from the HA interface to create an automation using a set time as a trigger, a condition and the action but I couldnā€™t make it to fire the automation at the set time. The automation would work when I would hit execute manually but not at the set time I wanted. This adds to my confusion.

Anyway thank you for your time.

Could you please post the code generated by that? It will be in automations.yaml

This is the code I have now. I changed it from the one I tried last night. I was hoping to get something going but nothing triggers:

- id: '1586674481614'
  alias: water plants
  description: ''
  trigger:
  - entity_id: switch.pump_switch
    for: 10s
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: 09:55:00
    before: '10:00:00'
    condition: time
  action:
  - data: {}
    entity_id: automation.water_plants
    service: automation.turn_on

I figured if I manage to get the switch to turn on at a set time and then off after 10s I can then add an extra condition to check if the binary sensor is in a certain state too. But I set the time (in this case it was (9:55) and the time went and passed and nothing happened

I think what you want is nearer to this:

- id: '1586674481614'
  alias: water plants
  description: ''
  trigger:
     platform: time
     at: "06:00:00"
  condition:
    condition: state
      entity_id: binary_sensor.water_level
      state: off
  action:
    - service: switch.turn_on
      entity_id: switch.pump_switch
    - delay: 
      minutes: 10
    - service: switch.turn_off
      entity_id: switch.pump_switch
  • The trigger is ā€œwhen you want something to happenā€ - ie 6am

  • The condition is ā€œlimit when it happensā€ - ie when the level switch is off (or it might be on, I am not sure of its configuration)

  • the action is what you want to happen - ie turn the pump on, wait 10 mins, turn it off.

1 Like

Ok so I have created a new automation using your code and I have made some progress:

- id: '1586681358987'
  alias: water plants
  description: ''
  trigger:
  - at: '11:53:00'
    platform: time
  condition:
  - condition: device
    device_id: ff54ec668570462c886fdfcdc35790cf
    domain: binary_sensor
    entity_id: binary_sensor.level_sensor
    type: is_on
  action:
  - data: {}
    entity_id: switch.pump_switch
    service: switch.turn_on
  - delay: 10s
  - data: {}
    entity_id: switch.pump_switch
    service: switch.turn_off

As you can see I put a trigger time to test it and a small delay. What happens is as follows: the automation triggers at the set time but unfortunately the switch just stays on. It is as if the automation does not proceed to delay for 10 seconds and then switch off. Any idea what could be the cause of this behavior?

Thank you so much for your help btw!

P.S.: this code above is how it was generated by the UI. I have no idea what is with the - data: {} sections in the action block.

Could this be the problem with delay not working?

But the switch is not triggered again during the delay timeā€¦

It works if I do this:

- id: '1586681358987'
  alias: water plants
  description: ''
  trigger:
  - at: '12:08:00'
    platform: time
  condition:
  - condition: device
    device_id: ff54ec668570462c886fdfcdc35790cf
    domain: binary_sensor
    entity_id: binary_sensor.level_sensor
    type: is_on
  action:
  - data: {}
    entity_id: switch.pump_switch
    service: switch.turn_on
  - delay: 00:00:10
  - data: {}
    entity_id: switch.pump_switch
    service: switch.turn_off

Notice the - delay: 00:00:10 format instead of just 10s.

Thank you very much again!

Sorry if this a somewhat unrelated question: what pump are you using? I tried with a couple of different pumps, but I canā€™t even get enough pressure to water one plant ā€“ I was hoping I could use the same pump for 2-3 plants, but again, the water coming out of one mini sprayer is not enough for one single plant.

Hi,

Sorry I took so long to answer by only now I saw your post. I got this pump:

It works ok for my application. I have three rectangular planters about 10 cm x 50 cm with three or four plants in each. I get the water from a 70l plastic bin where the pump is submerged. The distance between the bin and the planters is about 70 cm. The length of the tube I use is about 2.5 m. I push the water through a 8mm diameters tube and then it goes into the 2.5 m long tube with a diameter of 5 mm. I used that because I used some Gardena micro drippers. They are not ideal mind you. I do not have a sprayer so I have no idea how well it works with one.

Hope that helps you!

1 Like

Thanks!! Iā€™ll try that, but I have a similar one and when I add the sprayer, it starts ā€˜drippingā€™ instead. Perhaps, I should just eliminate the sprayer and have ā€˜starā€™ like arrangement of dripping ends.
Again, thanks for the help!!
Cheers,

Hi, no problem. I do not have a sprayer connected to it. I have these dripping heads from Gardena. Microdrippers they are called I believe. I have no idea if it will work with a srayer. Maybe the pump isnā€™t strong enough to generate that much pressure. For that particular arrangement of flowers I find the drippers to work wonders!