PWM pump with Nextion Display

Hi everyone,

I am looking for help please ! I have a nextion display with a slider to set the pump speed. The pump is a 24V PWM pump and I am still very new to ESPHome so looking for some code examples of getting me going. I think it is ledc I need ? 24V goes direct to pump and PWM trigge lead to ESP32 to set the pulse ?

Not enough people seem to be aware of the examples page DIY Examples — ESPHome

I don’t know if you will find a solution there, but there are 2 or 3 nextion examples.

I have managed to get close I think.

I don’t know how to pass the value from nextion through to the output level

I have tried the following, but the lambda portion is wrong:

- platform: nextion
    id: pump_speed
    component_name: pumpVal
        - logger.log:
            format: "Updated pump value to %i"
            args: ['(int)id(pump_speed).state']
        - output.set_level:
            id: pump
            level: lambda: |- id(pump_speed).state();

  - platform: ledc
    pin: GPIO5
    id: pump

  - platform: speed
    output: pump
    name: "Pump Speed"   
type or paste code here