I was using a servo for a blast gate and it had a rotation of about 70 degrees. I’ve redesigned the blast gate and want the servo to have 180 degrees of rotation.
But nothing I’ve done to change the code seems to change the angle of rotation - it turns about 70 degrees, or it doesn’t respond at all.
Here’s the relevant section of yaml…
# Define servo positions and state
globals:
- id: open_position
type: float
initial_value: '100.0' # 180° position
- id: closed_position
type: float
initial_value: '0.0' # 0° position
- id: servo_state
type: bool
initial_value: 'false' # Default: closed
# PWM output for servo
output:
- platform: esp8266_pwm
id: pwm_output
pin: GPIO2
frequency: 50 Hz
# Servo configuration covering full range
servo:
- id: my_servo
output: pwm_output
min_level: 3% # 0° position
max_level: 12% # 180° position
auto_detach_time: 2s # Release after 2s
# Button to toggle servo state
binary_sensor:
- platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLUP
inverted: True
name: "Blast Gate 1 Button"
on_press:
then:
- lambda: |-
bool state = id(servo_state);
auto pos = state ? id(closed_position) : id(open_position);
id(my_servo).write(pos / 100.0);
id(servo_state) = !state;
# Home Assistant switch to control servo
switch:
- platform: template
name: "Blast Gate Servo"
lambda: 'return id(servo_state);'
turn_on_action:
- lambda: |-
id(my_servo).write(id(open_position) / 100.0);
id(servo_state) = true;
turn_off_action:
- lambda: |-
id(my_servo).write(id(closed_position) / 100.0);
id(servo_state) = false;
I have tried varying the minlevel of 3 percent and maxlevel of 12 percent and it either makes no difference or it stops working.
Any idea what I’m doing wrong here?