Automation not able to call service to control stepper motor?

So i’ve using ESPHome setup an esp8266 which control a stepper motor using the stepper driver.

The ESPHome setup works and i can without any problems in HA dev-services call the service

esphome.steppermotor_control_stepper with service data {"target": 2000}
and see the motor moving!.

But the frontend controls I haven’t managed to get that working yet…

I’ve on my dashboard, as ESPHome suggest created a slider as such:

# Home Assistant configuration
input_number:
  stepper_control:
    name: Stepper Control
    initial: 0
    min: -1000
    max: 1000
    step: 1
    mode: slider

And this slider is “monitored” by an automation rule

# Control stepper motor
  - alias: 'Write Stepper Value to ESP'
    trigger:
      platform: state
      entity_id: input_number.stepper_control
    action:
      - service: esphome.steppermotor_stepper_control
        data_template: 
          target: '{"target": {{ trigger.to_state.state | int }} }'

but every time I move the slider I get an error in the log that

Error while executing automation automation.write_stepper_value_to_esp. Service not found for call_service at pos 1: (ServiceNotFound(...), 'Service esphome.steppermotor_stepper_control not found')

which i know is untrue? as I can manually trigger it? so why am I getting this error, and why am I not able to control it using frontend slider?

I saw the error as I posted this question…

  • The service I am calling is the wrong one.
    The one that works in dev-services esphome.steppermotor_control_stepper
    but the one my automation is calling is esphome.steppermotor_stepper_control

Kidi3, would you mind posting the config that you have in your esphome yaml, and any other info that you might have figured out. I have been fighting with this for day, and no luck at all, thanks.

@TinyDoT

Sure…

My steppermotor.yaml looks like this

# Example configuration entry
stepper:
  - platform: uln2003
    id: my_stepper
    pin_a: D0
    pin_b: D1
    pin_c: D2
    pin_d: D3
    max_speed: 250 steps/s
    sleep_when_done: true
    step_mode: FULL_STEP

    acceleration: inf
    deceleration: inf
    
# ESPHome configuration
api:
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return target;' 

This is the slider configuration for the stepper motor

# Home Assistant configuration
input_number:
  stepper_control:
    name: Stepper Control
    initial: 0
    min: -1000
    max: 1000
    step: 1
    mode: slider

And the automation that calls the service on the esphome based on the slider position is

# Control stepper motor
  - alias: 'Write Stepper Value to ESP'
    trigger:
      platform: state
      entity_id: input_number.stepper_control
    action:
      - service: esphome.steppermotor_control_stepper
        data_template: 
          target: '{{ trigger.to_state.state | int }}'
2 Likes

What helped me debug

was first trying to figure out whether the issue was hardware or software first - does the service call work or not?

Alright, I broke things down and one found out part of the problem was the power supply. Swapped that and now a can make a service call and i can get it to work, but I am not having any luck with the automation and I appear to have the same code as you.

Edit: Ok, all is good automation working, thanks for the help

Decided to make a new post for my issue. This seemed a bit stale.

HI Everyone, just to share my experience, with a little modification in the automation.yaml file I managed to get it work on the slider UI by modifying data_template: by data:
Hope it might help