Is it possible to control a Stepper through a box input number?

yep, I did restarted before trying again. Still no reset.

I think I see the issue, we need to change:

    - service: stepper_position
      variables:
        position: int

to

    - service: stepper1_position
      variables:
        position: int

Now, neither the stepper nor the reset automation work.

Make sure you valid the esphome config, to check for errors.

Ok, I will check this tomorrow and will let you know. Thank you again for so much help! :slight_smile:

Hi again, sorry for only being able to check this atm. I double checked the ESPHome config, it validates ok. The stepper motor is working again (it was a misplaced cable).
But Im still unable to reset the position.

For convenience, here is the code I currently have:
ESPHome device:

esphome:
  name: stepper1

esp8266:
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxx"
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - logger.log: "Speed updated"
        - stepper.set_target:
            id: stepper1
            target: !lambda 'return target;'
    - service: stepper1_position
      variables:
        position: int
      then:
       - stepper.report_position:
            id: stepper1
            position: !lambda 'return position;'

stepper:
  - platform: uln2003
    id: stepper1
    sleep_when_done: true
    pin_a: D1
    pin_b: D2
    pin_c: D3
    pin_d: D4
    max_speed: 250 steps/s 

sensor:
  - platform: template
    name: "Stepper Position"
    unit_of_measurement: steps
    lambda: return id(stepper1).current_position;
    update_interval: 1s
    
ota:
  password: "xxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:
    

My automation for reset:

alias: Stepper Reset to Zero
trigger:
  - platform: numeric_state
    entity_id: sensor.uptime_sensor_stepper1
    below: -120
action:
  - service: esphome.stepper1_position
    data:
      position: "0"
  - service: esphome.stepper1_control_stepper
    data:
      target: "0"

My automation for writing value:

- id: '1661897634736'
  alias: Write Stepper Value to ESP
  trigger:
  - platform: state
    entity_id: input_number.stepper_control
  action:
  - service: esphome.stepper1_control_stepper
    data_template:
      target: '{{ trigger.to_state.state | int }}'

My HA config:

  stepper_control:
    name: Stepper Control
    initial: 0
    min: -50000
    max: 50000
    step: 100
    mode: box

Once again, tank you for all the help!

Ok first thing I found, that I missed we need to change to this:

alias: Stepper Reset to Zero
trigger:
  - platform: numeric_state
    entity_id: sensor.uptime_sensor_stepper1
    below: -120
action:
  - service: esphome.stepper1_stepper1_position
    data:
      position: "0"
  - service: esphome.stepper1_control_stepper
    data:
      target: "0"
1 Like

And it is working!!!
Thank you so much for you kind help!
I will try now to figure how can I set an automation so that whenever the stepper stops, it resets to 0, wish me luck!
Meanwhile, @TinyDoT, you’re one of the reasons why I believe in sharing in this community. Thank you really.

1 Like

I am very glad we got it working. Now you are moving to the next step, of resetting after the stepper stops. So, I have a question, does it have to happen the second after the stepper stop, or does it really not matter, cause you could time how long it take and then reset it after so many minutes after the run automation is triggered.

1 Like

In principle, it does not need to reset the next second after the stepper stops. Still, I will need to have some sort of structured timing, since I will need to trigger other automations right after. So a typical sequence for a complete fertigation process would be:
0 - a (stonger pump) collects a fixed (helper) amount of water in a common container;
1 - The first step docing pump pumps a fixed number of steps in order to drive the liquid fertilizer from its container to the point it is ready to be poured from the pipe;
2 - The pump auto-resets its position;
3 - The pump pumps a given amount (helper) of liquid fertilizer to a container;
4 - The pump auto-resets its position;
5 - The pump retracts a fixed number of steps in order to drive the liquid fertilizer present in the pipe back to its original container;
6 - The pump auto-resets its position;
7 - Next dosing pump sequence activates (similar to this first one), and so on and so forth;

  • At some point a mixer is activated in the common container where all the fertilizers (and water are already dosed);
  • Then there is an automation to measure the pH level;
  • possibly more fertigation pumps enter in scene, in order to correct the pH
  • New mix, new pH level measure, if okay, the final pump (stronger) pumps the final mix to its final destination, veggies are happy :slight_smile:

Well here is a thought, in the additions that we just made to your setup, you now have a position senor:

sensor:
  - platform: template
    name: "Stepper Position"
    unit_of_measurement: steps
    lambda: return id(stepper1).current_position;
    update_interval: 1s

You can track this sensor, so once the position hits x then do this.

Yes, I thought this could do, but the thing is that the end position would be variable, since the dosages are different in different stages of the veggies growth. My second possibility would be to have a helper specifying the dosage, in reference to the timing of growth, and then instead of creating an automation triggering on a fixed value, it can trigger when the value reaches the value of the helper in question. I still need to convert this helper units (ml) in steps for the motor as well.
A third possibility I thought was to somehow measure the Watts spent by the pumps, and every time this value goes down (e.g. <1W), the reset automation triggers.
Since I will need to code anyway the second possibility, maybe it is the best way to go. Not sure yet.

So, you are basically making a Peristaltic Pump, so yes finding the the amount of ml per step is very important. I imagine this feeding drip can happen the same time every x day, so that is a constant, but the drip amount will change due to growth, so the helpers are necessary to determine the drip amount. Is the grow rate of the plant pretty predictable? Say, the first 3 weeks you are in infant stage, so 7 ml drip. Three weeks later you are in the toddler stage so now 21 ml drip is needed. I think you can see the point to base your helpers off of days, and you could possibly tie in the new calendar helper in HomeAssistant.

Now you have motivated me into creating my own Peristaltic Pump for my Aquariums : )

1 Like

Yes! I’m trying to make a system of peristaltic pumps, based on step motors, fed by a 5V Power supply. My plan is to connect these pumps to a 8 way relay and create the necessary automations for mixing and ph level measuring. A more detailed idea is in this ongoing thread.

Yes, but still it depends of the plant, if it is tomatoes it is one thing, and if it is cucumbers is another thing. So, I most likely will need to have different helpers that are used/activated according to whatever is growing. Since I’m currently growing one type of vegetable each time, It shall not be too complicated.

Thats the point of this community isn’t it? :slight_smile: If I can help you somehow, please let me know. If you only need small doses directly to your aquarium, it shall be much easier, and I can pass you a BoM of the stuff you’ll need.

1 Like

Now, you have me looking up 3d parts to print and I have extra stepper motors around here from my automated Roller Blind build, and I think I even have the tubing. Time to get it all together.

I will be very curious as to how you finish your project, keep in informed if you don’t mind : )

1 Like

Is there a sensor in HA that has the current position of your stepper? If so you don’t actually need an automation or an input number for this, you can just make a template number like this:

template:
  - number:
      - name: Stepper control
        state: "{{ states('sensor.stepper_current_position') }}"
        min: "-50000"
        max: "50000"
        step: "100"
        set_value:
          service: esphome.stepper1_control_stepper
          data:
            target: '{{ value }}'

Then this number entity will always contain the current position the stepper is in regardless of how it was changed (from HA or externally). And if the number entity is changed in the UI it will adjust the stepper by calling the service.

I assumed the stepper’s current position would be in a sensor like sensor.stepper_current_position, feel free to replace that with whatever it is called. If this sensor doesn’t exist then I suppose an input_number + automation is your best bet.

1 Like

I can’t do less than encouraging you! Really very happy that this is actually reaching out more people in this nice community :slight_smile: I have updated my configuration and now the reset is automated as I need. I shared everything in the original thread, and will keep it updated in the next steps. Thank you!

Thank you for reaching out and thinking about this alternative. I now have everything working as I needed, and I updated the original thread with the code I’m using. Thanks!

This is an amazing community. If everyone in the world worked this way, there would be nothing we couldn’t solve. Thank for the link to your original thread, now I have you BOM, and I can borrow some code.

1 Like

Indeed :slight_smile: If you go with the same stl I used, make sure you get the 2mm ID x 3mm OD silicon tubes (instead of the 3mm ones). See you around! Meanwhile, do enjoy your project!