I didnt find an example of what I needed so I modified what I did see. It seems to work but I'm not sure if I did it correctly. Also is there a reason to have the api services because I took it out. All feedback appreciated.
esphome:
name: window_lr_right
platform: ESP8266
board: nodemcuv2
wifi:
ssid:
password:
manual_ip:
static_ip: 192.168.1.211
gateway: 192.168.1.1
subnet: 192.168.1.0
web_server:
port: 80
captive_portal:
# Enable logging
logger:
ota:
api:
# services:
# - service: control_blind
# variables:
# target: int
# then:
# - stepper.set_target:
# id: my_stepper
# target: !lambda 'return target;'
# - sensor.template.publish:
# id: position
# state: !lambda 'return target;'
cover:
- platform: template
name: "Living Room Windows"
id: my_window
device_class: window
open_action:
- stepper.set_target:
id: my_stepper
target: 30000
- sensor.template.publish:
id: position
state: !lambda return id(my_stepper).target_position;
close_action:
- if:
condition:
# reached past the 'top' but still haven't triggered the endstop yet
lambda: "if(id(endstop).state == 0) { return 1; } else { return 0; }"
then:
- stepper.set_target:
id: my_stepper
target: -30100
- sensor.template.publish:
id: position
state: !lambda return id(my_stepper).target_position;
stop_action:
- stepper.set_target:
id: my_stepper
target: !lambda return id(my_stepper).current_position;
- sensor.template.publish:
id: position
state: !lambda return id(my_stepper).current_position;
optimistic: true
assumed_state: true
sensor:
- platform: template
name: "My Window Position"
id: position
stepper:
- platform: a4988
id: my_stepper
step_pin: D3
dir_pin: D4
sleep_pin:
number: D2
inverted: TRUE
max_speed: 700
acceleration: inf
deceleration: inf
binary_sensor:
- platform: gpio
pin:
number: D7
mode: INPUT_PULLUP
name: "Endstop Window LR right"
id: endstop
filters:
- invert:
on_press:
then:
# hit the endstop, store the current steps value and reset stepper position to 0
- stepper.report_position:
id: my_stepper
position: 0
# just in case set the target to 0
- stepper.set_target:
id: my_stepper
target: 0
1 Like