esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
285 stars 34 forks source link

Servo component: do not restore servo position when moved manually #5735

Closed giovi321 closed 3 weeks ago

giovi321 commented 3 weeks ago

The problem

I am controlling a servo using esphome. If I move the servo 50% with my hand, and then I tell the servo to go to that position from esphome, instead of not moving at all, it spins back to the original position it was in and then goes to 50%. It would be nice to have an option like restore: false but global, not only at startup. This is especially useful if you have an encoder (or a rotary switch, if the positions of the servo are not continuous) that tracks the position of the servo.

Which version of ESPHome has the issue?

2024.4.1

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

2024.4.4

What platform are you using?

ESP8266

Board

Wemos D1 Mini

Component causing the issue

Servo

Example YAML snippet

binary_sensor:
  - platform: gpio
    pin:
      number: 4
      mode:
        input: true
        pullup: true
      inverted: true
    id: rotary_switch_1
    name: "Off"

  - platform: gpio
    pin: 
      number: 5
      mode:
        input: true
        pullup: true
      inverted: true
    id: rotary_switch_2
    name: "LED only"

  - platform: gpio
    pin:
      number: 14
      mode:
        input: true
        pullup: true
      inverted: true
    id: rotary_switch_3
    name: "LED & fan 1"

  - platform: gpio
    pin:
      number: 12
      mode:
        input: true
        pullup: true
      inverted: true
    id: rotary_switch_4
    name: "LED & fan 2"

  - platform: gpio
    pin:
      number: 13
      mode:
        input: true
        pullup: true
      inverted: true
    id: rotary_switch_5
    name: "LED & fan 3"

servo:
  - id: servo1
    output: pwm_output
    auto_detach_time: 0.1s
    transition_length: 5s

output:
  - platform: esp8266_pwm
    id: pwm_output
    pin: GPIO0
    frequency: 50 Hz

number:
  - platform: template
    id: servo_position
    name: "Servo position"
    min_value: 1
    max_value: 5
    step: 1
    set_action:
      - if:
          condition:
            lambda: |-
              return x == 1;
          then:
            - logger.log: "Condition 1 triggered: Moving servo to -100%"
            - servo.write:
                id: servo1
                level: -100.0%
      - if:
          condition:
            lambda: |-
              return x == 2;
          then:
            - logger.log: "Condition 2 triggered: Moving servo to -50%"
            - servo.write:
                id: servo1
                level: -50.0%
      - if:
          condition:
            lambda: |-
              return x == 3;
          then:
            - logger.log: "Condition 3 triggered: Moving servo to 0%"
            - servo.write:
                id: servo1
                level: 0.0%
      - if:
          condition:
            lambda: |-
              return x == 4;
          then:
            - logger.log: "Condition 4 triggered: Moving servo to 50%"
            - servo.write:
                id: servo1
                level: 50.0%
      - if:
          condition:
            lambda: |-
              return x == 5;
          then:
            - logger.log: "Condition 5 triggered: Moving servo to 100%"
            - servo.write:
                id: servo1
                level: 100.0%

Anything in the logs that might be useful for us?

Nothing useful.

Additional information

No response

ssieb commented 3 weeks ago

This is a feature request, not an issue. If you set the transition time to 0, it should do what you want.