From 8551c30b39894850b8c4b997ece4fadc6e7d8cff Mon Sep 17 00:00:00 2001 From: demichiel Date: Wed, 16 Mar 2022 20:22:31 +0100 Subject: [PATCH] Add simpler Home Assistant configuration for servo control (#1960) * Add simpler Home Assistant configuration for servo control Co-authored-by: Michiel Ryvers --- components/servo.rst | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/components/servo.rst b/components/servo.rst index 341eae970..9e1eb85b8 100644 --- a/components/servo.rst +++ b/components/servo.rst @@ -14,7 +14,7 @@ interface to the Arduino Servo library. First, create an :ref:`output component ` (here ``esp8266_pwm``) for the pin the servo is connected to. Then connect that output to the servo component by assigning an ID. -Please note the frequency of the output must be around 50Hz, as most servo controllers +Please note the frequency of the output should be around 50Hz, as most servo controllers only operate in this frequency range. .. note:: @@ -141,46 +141,22 @@ this will make the servo motor stop immediately and disable its active control. Home Assistant Configuration ---------------------------- -This component will not show up in the Home Assistant frontend automatically because Home Assistant -does not support servos natively (raise this issue in Home Assistant forums to make this a -higher priority for Home Assistant). You can add this to your Home Assistant configuration to -be able to control the servo from the frontend. +The easiest way to control your servo from Home Assistant is to add a ``number`` to your ESPHome +configuration. See :ref:`Number ` for more information. .. code-block:: yaml - # Home Assistant configuration - input_number: - servo_control: + number: + - platform: template name: Servo Control - initial: 0 - min: -100 - max: 100 + min_value: -100 + max_value: 100 step: 1 - mode: slider - - automation: - - alias: Write Servo Value to ESP - trigger: - platform: state - entity_id: input_number.servo_control - action: - # Replace livingroom with the name you gave the ESP - - service: esphome.livingroom_control_servo - data_template: - level: '{{ trigger.to_state.state | int }}' - -.. code-block:: yaml - - # ESPHome configuration - api: - services: - - service: control_servo - variables: - level: float + set_action: then: - servo.write: id: my_servo - level: !lambda 'return level / 100.0;' + level: !lambda 'return x / 100.0;' servo: - platform: ...