Roller blind as cover with controllable slider

Today I am trying to build an esphome controllable cover with slider. I have found workable code on here:

Below is my code which kinda works. I get:
image

All works, I can up and down it, and the slider follows…
image

But if I “set” the slider nothing happens. I think this is behavior as expected but I can’t find how to make that work.

Found this:

But I think I am overthinking this and I need a push in the right direction…

#https://community.home-assistant.io/t/motor-on-a-roller-blind-esphome-version/116179/109

substitutions:
  esp_name: esp32-07
  ssid: IOTDOM
  password: !secret IOTDOM_wifi_key

esphome:
  name: $esp_name
  platform: ESP32
  board: wemos_d1_mini32
  on_boot:
    priority: -100
    then:
      - stepper.report_position:
          id: blind_stepper
          position: !lambda "return id(current_position);"
      - stepper.set_target:
          id: blind_stepper
          target: !lambda "return id(current_position);"
      - stepper.set_speed:
          id: blind_stepper
          speed: 500 steps/s
      - cover.template.publish:
          id: kitchen_blind
          current_operation: IDLE
          position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'

globals:
  - id: open_position
    type: int
    initial_value: '10000'
  - id: middle_position
    type: int
    initial_value: '3760'
  - id: current_position
    type: int
    initial_value: '10000'
    restore_value: true

wifi:
  ssid: $ssid
  password: $password
  use_address: 192.168.6.68
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${esp_name} FBHS"
    password: !secret Fallback_Hotspot

captive_portal:

esp32_touch:
  setup_mode: False

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - stepper.set_target:
            id: blind_stepper
            target: !lambda 'return target;'
        - globals.set:
            id: current_position
            value: !lambda 'return target;'
    - service: set_speed
      variables:
        speed: int
      then:
        - stepper.set_speed:
            id: blind_stepper
            speed: !lambda 'return speed;'
    - service: middle
      then:
        - stepper.set_speed:
            id: blind_stepper
            speed: !lambda |-
              if (id(middle_position) >= id(blind_stepper).current_position) {
                return 500;
              } else {
                return 800;
              }
        - stepper.set_target:
            id: blind_stepper
            target: !lambda 'return id(middle_position);'
        - while:
            condition:
              lambda: |-
                return id(blind_stepper).current_position != id(middle_position);
            then:
              - cover.template.publish:
                  id: kitchen_blind
                  current_operation: !lambda |-
                      if(id(middle_position) >= id(blind_stepper).current_position) {
                        return COVER_OPERATION_OPENING;
                      } else {
                        return COVER_OPERATION_CLOSING;
                      }
                  position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'
              - delay: 1000 ms
        - cover.template.publish:
            id: kitchen_blind
            current_operation: IDLE
            position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'
        - globals.set:
            id: current_position
            value: !lambda 'return id(middle_position);'

ota:

stepper: #https://community.home-assistant.io/t/motor-on-a-roller-blind-esphome-version/116179/11
  - platform: uln2003
    id: blind_stepper
    pin_a: GPIO17
    pin_b: GPIO18
    pin_c: GPIO19
    pin_d: GPIO23
    max_speed: 500 steps/s
    sleep_when_done: true    
    acceleration: inf
    deceleration: inf

i2c:

cover:
  - platform: template
    device_class: shade
    name: Kitchen Blind
    id: kitchen_blind
    open_action:
      - stepper.set_speed:
          id: blind_stepper
          speed: 500 steps/s
      - stepper.set_target:
          id: blind_stepper
          target: !lambda "return id(open_position);"
      - while:
          condition:
            lambda: |-
              return id(kitchen_blind).position != 1;
          then:
            - cover.template.publish:
                id: kitchen_blind
                current_operation: !lambda |-
                    return COVER_OPERATION_OPENING;
                position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'
            - delay: 1000 ms
      - cover.template.publish:
          id: kitchen_blind
          current_operation: IDLE
          position: !lambda 'return 1;'
      - globals.set:
          id: current_position
          value: !lambda 'return id(open_position);'
    close_action:
      - stepper.set_speed:
          id: blind_stepper
          speed: 500 steps/s
      - stepper.set_target:
          id: blind_stepper
          target: 0
      - while:
          condition:
            lambda: |-
              return id(kitchen_blind).position != 0;
          then:
            - cover.template.publish:
                id: kitchen_blind
                current_operation: !lambda |-
                    return COVER_OPERATION_CLOSING;
                position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'
            - delay: 1000 ms
      - cover.template.publish:
          id: kitchen_blind
          current_operation: IDLE
          position: !lambda 'return 0;'
      - globals.set:
          id: current_position
          value: !lambda 'return 0;'
    stop_action:
      - stepper.set_target:
          id: blind_stepper
          target: !lambda return id(blind_stepper).current_position;
      - cover.template.publish:
          id: kitchen_blind
          current_operation: IDLE
          position: !lambda 'return (float(float(id(blind_stepper).current_position) / float(id(open_position))));'
      - globals.set:
          id: current_position
          value: !lambda 'return id(blind_stepper).current_position;'
    has_position: true

time:
  - platform: homeassistant
    id: homeassistant_time
    
web_server:
  port: 80
  
sensor:  
  - platform: uptime
    name: Uptime Seconds
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
              ).c_str();
      
text_sensor:
  - platform: template
    name: Uptime
    id: uptime_human
    icon: mdi:clock-start
  - platform: version
    name: "ESPHome Version"
  - platform: wifi_info
    ip_address:
      name: "${esp_name} IP Address"
    ssid:
      name: "${esp_name} Connected SSID"
    bssid:
      name: "${esp_name} Connected BSSID"
    mac_address:
      name: "${esp_name} Mac Wifi Address"
  - platform: version
    name: "ESPHome Version"
    
switch:
  - platform: restart
    name: "${esp_name} - ESP Restart"
2 Likes

have a look at this if you have the time. it works with a slider, perhaps you can get ideas from there what you might be missing.

Looking briefly at your code it looks as if you’d only have to change the stepper driver from a4988 that I’m using to yours ULN 2003.

Hi, did you get the slider working?
Thanks

No, not in this way. I moved to Z2M now all problems are gone.

Hi, I would also be interested in motorising my roller blinds.
I used your script on Esphome an Home Assistent and I can control the stepper 28BYJ (down and up), but I would need the slider to control the position of the curtains and control them, could you tell me what you used with Z2M so I can buy the components?
Thanks and bye