ESPhome peristaltic pump

Hello,

As a part of my on going project of building the ultimate HA&ESPhome Aquarium controller,I need to control a peristaltic pump controlling fertilizer dosing to the system.
the pump is connected to a relay,and has a constant flow rate of 0.5mL/Sec.
I want to be able to control the dosing amount with a slider/input box so i need to multiply the time/ml (for example, 5 ml is 10 sec for the relay to work). can I achieve this using only ESPhome? or do i have to include automatons in HA?
at any case, an example for a suitable code world be much appreciated(ESPhome+HA/ESPhome only)

my current ESPhome YAML(without any preparation for the “timed” element)

esphome:
  name: aquarium
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "ssid"
  password: "password"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Aquarium Fallback Hotspot"
    password: "tJUf7l4kshn3"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

dallas:
  pin: GPIO4
  update_interval: 30s
# Individual sensors

sensor:

## Temp sensor 
  - platform: dallas
    address: 0xED011452C0E8AA28
    name: "Aquarium Water Temp"
  - platform: dallas
    address: 0xDD0000031EFB0428
    name: "Aquarium Air Temp"  
    
## pH Sensor    
  - platform: adc
    pin: GPIO35
    id: ph
    name: "pH Level"
    icon: "mdi:mdi-flask-outline"
    update_interval: 1s
    unit_of_measurement: pH
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
      # Measured voltage -> Actual pH (buffer solution)
      - calibrate_linear:
          - 0.59 -> 7.0
          - 0.71 -> 4.0
  
switch:
  - platform: gpio
    name: "Filter"
    icon: "mdi:air-filter"
    pin: GPIO15
  - platform: gpio
    name: "Heater"
    icon: "mdi:coolant-temperature"    
    pin: GPIO2
  - platform: gpio
    name: "Air Pump"
    icon: "mdi:air-purifier"    
    pin: GPIO0
  - platform: gpio
    name: "Back Light"
    icon: "mdi:led-variant-on"    
    pin: GPIO5
  - platform: gpio
    name: "Main Light"
    icon: "mdi:lightbulb"    
    pin: GPIO14
  - platform: gpio
    name: "Fertilizer Pump"
    icon: "mdi:sprout"    
    pin: GPIO12
  - platform: gpio
    name: "CO2 Reactor"
    icon: "mdi:periodic-table-co2"    
    pin: GPIO13 
  - platform: gpio
    name: "Cooling Fans"
    icon: "mdi:fan"    
    pin: GPIO13
    

Hi, i’m having the exact same question!
Did you find any solution? Otherwise, this might be a nice bump for anyone to look into again.

Thanks in advance!

Hi,
my solution was ESPhome & Automation in order to switch off the pump after a given time.

esphome:
  name: aquarium
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: ""
  password: ""
  power_save_mode: none
  fast_connect: true
  manual_ip:
    static_ip: 10.0.0.25
    gateway: 10.0.0.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Aquarium Fallback Hotspot"
    password: "tJUf7l4kshn3"

captive_portal:

# Enable logging
logger:
 level: VERBOSE
api:

ota:

dallas:
  - pin: GPIO4


sensor:

## Temp sensor 
  - platform: dallas
    address: 0xF0011452CA69AA28
    name: "Aquarium Water Temp"
    filters:
     offset: 1
    accuracy_decimals: 1
  
switch:
  - platform: gpio
    name: "Filter"
    icon: "mdi:air-filter"
    pin: GPIO21
  - platform: gpio
    name: "Heater"
    icon: "mdi:coolant-temperature"    
    pin: GPIO23
  - platform: gpio
    name: "Air Pump"
    icon: "mdi:air-purifier"    
    pin: GPIO13
  - platform: gpio
    name: "Main Light"
    icon: "mdi:led-variant-on"    
    pin: GPIO27
  - platform: gpio
    name: "co2"
    icon: "mdi:periodic-table-co2"
    pin: GPIO25
  - platform: gpio
    name: "Fertilizer Pump"
    icon: "mdi:sprout"    
    pin: GPIO33
  - platform: gpio
    name: "Cooling Fans"
    icon: "mdi:fan"    
    pin: GPIO19

- id: timed_fertilizer_pump_4
  alias: Timed Fertilizer Dosing
  trigger:
  - entity_id: switch.pump_4
    to: 'on'
    for: 
      seconds: "{{ states('input_number.phosphate_dose') | round * 3.5 }}"
    platform: state
  condition:
    condition: template
    value_template: "{{ states('input_number.phosphate_dose') | float > 0 }}"
  action:
  - entity_id: switch.pump_4
    service: switch.turn_off
- id: timed_fertilizer_pump_4
  alias: Timed Fertilizer Dosing
  trigger:
  - entity_id: switch.pump_4
    to: 'on'
    for: 
      seconds: "{{ states('input_number.phosphate_dose') | round * 3.5 }}"
    platform: state
  condition:
    condition: template
    value_template: "{{ states('input_number.phosphate_dose') | float > 0 }}"
  action:
  - entity_id: switch.pump_4
    service: switch.turn_off

Did you use this bit inside ESPHome or just as an automation within HA?

Hello! I really dig your project and I would like to try to replicate it! Do you have a wiring diagram of it?

Yes, same question I think: where does this part of the code go?

That’s a Home Assistant automation so it needs to be in your HA config under the automation: section.