Moves the servomotor incrementally

Good evening everyone, I am creating an automatic fish feeder using a servomotor, all powered by an esp8266 and HA obviously.
I would need a script that every 3 hours starting from 9 am (9:00 - 12:00 - 15:00) moves the servomotor incrementally by 20, 20, 10 respectively.

In practice at the end of the first day it must go from -100 to -50, the following day to 0 etc until it reaches the maximum and goes back.

I can move the servo at a given time to position x but I can’t implement what would be this cycle in Arduino:

void startFeedern(int number){
  int pos;
  if(number==1){
    for(pos=posfinale;pos<=posfinale+20;pos+=1){
      Servo1.write(pos);
    }
  }else if(number==2){
    for(pos=posfinale;pos<=posfinale+20;pos+=1){
      Servo1.write(pos);
    }
  }else if(number==3){
    for(pos=posfinale;pos<=posfinale+10;pos+=1){
      Servo1.write(pos);
    }
  }
  posfinal=pos;
}

Can someone help me?

this is actually my code:

time:
  - platform: homeassistant
    id: homeassistant_time 
  - platform: sntp
    # ...
    on_time:
      - minutes: /5
        then:
          - servo.write:
              id: my_servo
              level: 0

font:
  - file: "arial.ttf"
    id: my_font
    size: 20

# Example configuration entry
i2c:
  sda: D1
  scl: D2

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      it.strftime(0, 60, id(my_font), TextAlign::BASELINE_LEFT, "%H:%M", id(homeassistant_time).now());

# Example configuration entry
servo:
  - id: my_servo
    output: pwm_output

# Example output platform
# On ESP32, use ledc output
output:
  - platform: esp8266_pwm
    id: pwm_output
    pin: D8
    frequency: 50 Hz

number:
  - platform: template
    name: Servomotore
    min_value: -100
    max_value: 100
    step: 5
    
    set_action:
      then:
        - servo.write:
            id: my_servo
            level: !lambda 'return x / 100.0;'

Why are you trying to figure it out for Arduino?

All of this is pretty basic stuff that is covered in the Docs. It shows you examples for making time based automations. Then the time based automation needs to trigger a servo.write for each feeding time. After all the tinme automations have run, reset the servo back to 0.

Speaking of resetting it to 0, why are you resetting the servo to 0 every 5 minutes?

Thanks for the answer. I dont know how to get the actual position of a servo or a stepper motor in order to write the actual position + offset.

I’m resetting every 5 just for testing

Read the documentation… Thats a good place to start.

can you please provide me some hint? maybe a link for the docs?

i think the answer is in this part Stepper Component — ESPHome

`stepper.report_position` Action
All steppers start out with a target and current position of `0` on boot. However, if you for example want to home a stepper motor, it can be useful to **report** the stepper where it is currently at.
With this action, you can set the stepper’s internal position counter to a specific value (in steps). Please note that reporting the position can create unexpected moves of the stepper. For example, if the stepper’s target and current position is at 1000 steps and you “report” a position of 0, the stepper will move 1000 steps forward to match the target again.
on_...: then: - stepper.report_position: id: my_stepper position: 250 # It's best to call set_target directly after report_position, so that the stepper doesn't move - stepper.set_target: id: my_stepper target: 250 # Templated - stepper.report_position: id: my_stepper position: !lambda |- if (id(my_binary_sensor).state) { return 0; } else { return -1000; }
Configuration variables:
* **id** (**Required**, [ID](https://esphome.io/guides/configuration-types#config-id)): The ID of the stepper.
* **position** (**Required**, int, [templatable](https://esphome.io/guides/automations#config-templatable)): The position to report in steps.

but i dont understand where i have to put this code