Roller blind using hall effect pulse sensor

Hi folks - newbie here!

Ive taken an IKEA rollerblind and replaced the awful “spring back at any random time” mechanism out, replacing it with a 12v geared motor and a hall effect/magnet sensor that pulses every once for each revolution of the blind. What I think I want is a cover component, but Im not sure how to proceed. At the moment, this is what I use - it sets up some variables for the current position and length etc, then remembers where it is. I have four buttons on my lovelace, one to fully open, one to fully close, one to go up one turn, one to go down one turn.

Code:

esphome:
  name: office_blind
  platform: ESP8266
  board: d1_mini_lite

wifi:
  ssid: "verysecret"
  password: "evenmoresecret"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

globals:
  - id: counter
    type: int
    restore_value: no
    initial_value: '0'
    
  - id: direction
    type: int
    restore_value: no
    initial_value: '0'
  
  - id: length
    type: int
    restore_value: no
    initial_value: '14'
    

binary_sensor:
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
      inverted: yes
    id: pulse_r1
    internal: true
    on_press:
      - delay: 0.2s
      - lambda: !lambda |-
          if(id(direction) == -1) {
            id(counter) -= 1;
            id(mtr_1).turn_off();
            id(mtr_2).turn_off();
            id(direction) = 0;
          }
          if(id(direction) == 1) {
            id(counter) += 1;
            id(mtr_1).turn_off();
            id(mtr_2).turn_off();
            id(direction) = 0;
          }
          if(id(direction) == -2) {
            id(counter) -= 1;
              if(id(counter) <= 0) {
                id(direction) = 0;
                id(mtr_1).turn_off();
                id(mtr_2).turn_off();
                ESP_LOGD("main", "Reached the top.");
              }
          }
          if(id(direction) == 2) {
            id(counter) += 1;
              if(id(counter) >= id(length)) {
                id(direction) = 0;
                id(mtr_1).turn_off();
                id(mtr_2).turn_off();
                ESP_LOGD("main", "Reached the bottom.");
              }
            }
            ESP_LOGD("main", "Counter = %d", id(counter));

switch:
  - platform: gpio
    pin:
      number: D3
    id: mtr_1
    interlock: [mtr_2]
    

  - platform: gpio
    pin: 
      number: D4
    id: mtr_2
    interlock: [mtr_1]
    

  - platform: template
    name: "Down"
    icon: "mdi:axis-z-rotate-clockwise"
    turn_on_action:
    - lambda: !lambda |-
        if(id(counter) < id(length)) {
          id(mtr_1).turn_on();
          id(direction) = 1;
          ESP_LOGD("main", "Rotating clockwise");
        }
      
  - platform: template
    name: "Up"
    icon: "mdi:axis-z-rotate-counterclockwise"
    turn_on_action:
    - lambda: !lambda |-
        if(id(counter) < 0) {
        id(counter) = 0;
        }
        id(mtr_2).turn_on();
        id(direction) = -1;
        ESP_LOGD("main", "Rotating anti-clockwise");

  - platform: template
    name: "Top"
    icon: "mdi:arrow-up-bold"
    turn_on_action:
    - lambda: !lambda |-
        if(id(counter) >= 0) {
          id(mtr_2).turn_on();
          id(direction) = -2;
          ESP_LOGD("main", "Moving to the top.");
        }
  
  - platform: template
    name: "Bottom"
    icon: "mdi:arrow-down-bold"
    turn_on_action:
    - lambda: !lambda |-
        if(id(counter) < id(length)) {
          id(mtr_1).turn_on();
          id(direction) = 2;
          ESP_LOGD("main", "Moving to the bottom.");
        }

###################

Can anyone start me off with a cover control?

Welcome to the HA forums. Impressive first post.

In future could you please post your config properly - see point 11 in this post How to help us help you - or How to ask a good question

esphome has a cover component https://esphome.io/#cover-components - I would look at the Cover Core and Template Cover pages.

There is also a template cover home assistant component. It really depends whether you want the implementation on the esp or in HA. https://www.home-assistant.io/components/cover.template/

Thank you, and sorry! Ive amended my post.

There isnt an option in the cover core and cover component that will do what I want.

Id like to be able to open and close the blind, and also have a slider that I can use to set a position.

Great, makes it so much easier to read.

The HA template cover has a “set position” command, which could be linked to a gui component.