ESPHOME ESP32 issue with motor controller

Hello all! after hand writing and going back and with chatgpt it appears I can’t win this battle ;(. I need the ability to change the motor speed on the fly using a slider or input value. This is being used to control a l298n motor controller that’s controlling a 12v peristaltic speed. From what I’ve read Automation: used to be a valid thing but has since been removed? or possibly I’m just not familiar enough with the history of esphome.

  - platform: ledc
    pin: GPIO4
    id: motor_1_pwm

  - platform: gpio
    pin: GPIO5
    id: motor_1_a

  - platform: gpio
    pin: GPIO14   
    id: motor_1_b

  - platform: automation
    id: set_motor_speed
    alias: "Set Motor Speed"
    platform: state
    entity_id: input_number.motor_speed
    - output.set_level:
        id: motor_1_pwm
        level: "{{ (states('input_number.motor_speed') | int) * 2.55 }}"
    - gpio.output:
        id: motor_1_a
        level: LOW
    - gpio.output:
        id: motor_1_b
        level: HIGH

Hi and welcome…

We are happy to assist here but first you need to edit your post so you yaml is enclosed in preformatted text tags. They are accessed using the </> button on the posting toolbar.

Also have a read of item 11 in the following:

1 Like

Thank you! My apologies for the improper upload format. I was just reading the sticky post about that.

So far so good, and you are correct - platform: automation is invalid.

I assume your input_number is defined in HA? You will need to import that as a platform: homeassistant sensor first.

You can also define numbers and selects directly on the ESPHome device - whatever suits your needs.

In case you are still struggling, something like this:

  - platform: homeassistant
    entity_id: input_number.motor_speed
    id: motor_speed
      - output.set_level:
          id: motor_1_pwm
          level: !lambda "return x * 2.55"
      - output.turn_off: motor_1_a
      - output.turn_on: motor_1_b

Thank you, I’ll give it a try. It appears an esp8266 board is more well laid out for what I’m attempting to configure. I’ve ordered some arriving saturday. They natively allow PWM control and a perfect example is available. I got the entire unit to work with Arduino code. I’m still attempting on the esp32 as curiosity and hype fixation have set in. :rofl:

Ummm so does the ESP32 and it’s done in hardware - not software. From. the Espressiff ESP8266 reference:

The ESP doesn’t have hardware PWM, so the implementation is by software.