Hi
I’ve added two hobby servos to a dumb pet door so I can lock my pets in overnight. I’m using a Lock component. Its mostly working, but its using “optimistic: true” to reflect lock state. I’d like it to properly reflect its real state, ie LOCK_STATE_LOCKING, LOCK_STATE_LOCKED, etc. I know I have to use lambdas. I’m sure its pretty simple but my software skills are not 100%. I’ve tried copying from other examples online without success. Appreciate any tips.
servo:
- id: left_servo
output: left_servo_output
auto_detach_time: 1s
transition_length: 2s
- id: right_servo
output: right_servo_output
auto_detach_time: 1s
transition_length: 2s
output:
- platform: ledc
id: left_servo_output
pin: 14
frequency: 50 Hz
- platform: ledc
id: right_servo_output
pin: 26
frequency: 50 Hz
lock:
- platform: template
name: "Lock"
icon: "mdi:lock"
optimistic: True
lock_action:
- servo.write:
id: right_servo
level: -80.0%
- servo.write:
id: left_servo
level: -60.0%
unlock_action:
- servo.write:
id: right_servo
level: 25.0%
- servo.write:
id: left_servo
level: 50.0%
number:
- platform: template
name: Right Servo
min_value: -100
initial_value: 0
max_value: 100
step: 1
optimistic: true
set_action:
then:
- servo.write:
id: right_servo
level: !lambda 'return x / 100.0;'
- platform: template
name: Left Servo
min_value: -100
initial_value: 0
max_value: 100
step: 1
optimistic: true
set_action:
then:
- servo.write:
id: left_servo
level: !lambda 'return x / 100.0;'