Servo Position with Rotary Encoder

Hi I have a setup with wemos d1, rotary encoder and a servo. i want to control the position of the servo with the rotary encoder conected to the wemos d1 , but i dont know how to write the value of the rotary encoder to the servo write function. can someone help me please?. many thanks

Does the rotary encoder give an absolute or incremental output?

i think its absolute .

sensor:

  • platform: rotary_encoder
    name: “Rotary Encoder”
    id: encoder_value
    pin_b:
    number: D6
    mode: INPUT
    pin_a:
    number: D5
    mode: INPUT
    max_value: 100
    min_value: 0
    resolution: 1

It’s actually an incremental encoder but fortunately the ESP component appears to make it an absolute one.

Try this:

sensor:
  - platform: rotary_encoder
    name: "Rotary Encoder"
    id: encoder_value
    pin_b:
    number: D6
    mode: INPUT
    pin_a:
    number: D5
    mode: INPUT
    max_value: 100
    min_value: -100
    resolution: 1
    on_clockwise:
    - then:
      - servo.write:
        id: your_servo # change this id to your servo
        level: !lambda |-
          return id(encoder_value).state / 100;
    on_anticlockwise:
    - then:
      - servo.write:
        id: your_servo # change this id to your servo
        level: !lambda |-
          return id(encoder_value).state / 100;

Thank you so much!!

Hi all,
I do the same project, my servo run ok . I add Number template to control from HA front end. It works, too. But I don’t know how to control servo from rotary encoder and value update to Number template to sync status on HA front-end. Thanks for all advices