Thought I’d share my config, I’ve done things a little differently. I set up a template cover in home assistant and used that to control the esphome stepper, rather than using a template cover in esphome.
This config gives me open, close and a slider for position. I can also set position with google home (or any other automation).
I worked out, by a bit of trial and error, that it’s 11000 steps from fully closed to fully open. So all values passed from the ha template cover, which has a range of 0 - 100, are multiplied by 1100. A sensor is configured in esphome which stores the position and ha uses that as the position_template in ha. This keeps the position accurate if ha is restarted.
To keep the position accurate when the esp device is restarted, I’ve set it to move 11000 steps towards 0, wherever it is, when it hits the actual 0 position the motor stalls (which I understand is not a problem for steppers, although time will tell). So, when it’s finished it’s definitely at 0 and I can safely set that as the current position.
Anyhow here’s the HA config for the template cover:
cover:
- platform: template
covers:
boxroom_blind:
friendly_name: "Boxroom Blind"
position_template: "{{ states('sensor.boxroom_blind_position') }}"
open_cover:
service: esphome.boxroom_window_control_blind
data:
target: 0
close_cover:
service: esphome.boxroom_window_control_blind
data:
target: 100
set_cover_position:
service: esphome.boxroom_window_control_blind
data_template:
target: "{{ position }}"
and here’s the esphome config:
esphome:
name: boxroom_window
platform: ESP8266
board: d1_mini
on_boot:
priority: 80
then:
- stepper.set_target:
id: my_stepper
target: -11000
- delay: 20s
- stepper.report_position:
id: my_stepper
position: 0
- stepper.set_target:
id: my_stepper
target: 0
- sensor.template.publish:
id: position
state: 0
wifi:
ssid: xx
password: xx
ota:
logger:
api:
services:
- service: control_blind
variables:
target: int
then:
- stepper.set_target:
id: my_stepper
target: !lambda 'return target * 110;'
- sensor.template.publish:
id: position
state: !lambda 'return target;'
sensor:
- platform: template
name: "Boxroom Blind Position"
id: position
stepper:
- platform: uln2003
id: my_stepper
pin_a: D2
pin_b: D1
pin_c: D4
pin_d: D3
max_speed: 500 steps/s
sleep_when_done: true
I don’t know if there are simpler / better ways of doing this, but it works