Control blinds with esphome

I’m trying to create a program in ESPHome to tilt the blinds. In the blind I have two relays, open and closed, and a potentiometer for the position. Also a switch to operate the blinds manually.

I want to create an automation in Home Assistant where I can move the blinds to a certain position. For example, blinds to 30%.

So far I have tried the following. In Home Assistant I can only go in one direction and how can I make the blinds move to a certain position?

Who can help me with this?

esphome:
  name: jalousie
  friendly_name: Jalousie

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: 

ota:
  password: 

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Jalousie Fallback Hotspot"
    password: 


captive_portal:

#variabelen
globals:
  - id: richting
    type: bool
    restore_value: true
    initial_value: 'true'

#potmeter
sensor:
  - platform: adc
    pin: A0
    name: "stand"
    id: potmeter
    update_interval: .2s
    filters:
      - multiply: 100
      - filter_out: 100
    accuracy_decimals: 0
    on_value_range:
      - above: 90
        then:
         - switch.turn_off: output_d5
      - below: 10
        then:
         - switch.turn_off: output_d6

      

switch:
  - platform: gpio
    pin: D5
    name: "jalousie open"
    id: output_d5
 
  - platform: gpio
    pin: D6
    name: "jalousie dicht"
    id: output_d6

  - platform: template
    name: "Handbediening richting"
    id: handb_richting
    turn_on_action:
      - globals.set:
          id: richting
          value: 'true'
    turn_off_action:
      - globals.set:
          id: richting
          value: 'false'

#handbediening schakelaar
binary_sensor:
  - platform: gpio
    pin:
      number: D4
      inverted: true
    filters:
      - delayed_on: 25ms
      - delayed_off: 25ms
    name: "hand bediening"
    id: hand_bediening
    on_press:
      then:
        if:
          condition:
            - switch.is_on: handb_richting
          then:
            - switch.turn_off: handb_richting
            - if:
                condition:
                  - lambda: return id(potmeter).state < 90;
                then:
                  - switch.turn_on: output_d5
          else:
            - switch.turn_on: handb_richting
            - if:
                condition:
                  - lambda: return id(potmeter).state > 10;
                then:
                  - switch.turn_on: output_d6
    on_release:
      - switch.turn_off: output_d5
      - switch.turn_off: output_d6

cover:
  - platform: template
    name: "Jalousie BG zij 1"
    id: Jalousie_BG_Z1
    open_action:
      - switch.turn_on: output_d6
    close_action:
      - switch.turn_on: output_d5
    stop_action:
      - switch.turn_off: output_d5
      - switch.turn_off: output_d6

Have little experience with cover, so far have couple ideas.

Add has_position: true to cover config and publish position from adc sensor to cover, like this:

    on_value:
      - lambda: |-
          float pos = x;
          if (x<10) { pos = 0; } else if (x>90) { pos = 100; }
          id(Jalousie_BG_Z1).position = pos/100.0;
          id(Jalousie_BG_Z1).publish_state();

Then on_value_range imho can be removed, as cover wil natively know position & will stop reaching end. But need to check it.

In cover defined what switches to operate to open/close/stop, so IMHO need to issue f.e. cover.close instead of simulating cover operations out of it.

Thank you very much. This is what I was looking for.
The “on_value_range” is for switching off the relays. The if in “on_value” in cover is for enable/disable the buttons in Home Assistant.

Did you get your project working? Would you mind sharing your yaml?

Here is my yaml. I now have 5 working blinds.

#variabelen
globals:
  - id: richting
    type: bool
    restore_value: true
    initial_value: 'true'

#potmeter
sensor:
  - platform: adc
    pin: A0
    name: "stand"
    id: potmeter
    unit_of_measurement: "%"
    update_interval: .2s
    filters:
      - multiply: 100
      - filter_out: 100
    accuracy_decimals: 0
    on_value_range:
      - above: 96
        then:
         - switch.turn_off: output_d6
      - below: 10
        then:
         - switch.turn_off: output_d5
    on_value:
      - lambda: |-
          float pos = x;
          if (x<10) { pos = 0; } else if (x>90) { pos = 100; }
          id(jalousie).position = pos/100.0;
          id(jalousie).publish_state();

      

switch:
  - platform: gpio
    pin: D5
    name: "jalousie open"
    id: output_d5
 
  - platform: gpio
    pin: D6
    name: "jalousie dicht"
    id: output_d6

  - platform: template
    name: "Handbediening richting"
    id: handb_richting
    turn_on_action:
      - globals.set:
          id: richting
          value: 'true'
    turn_off_action:
      - globals.set:
          id: richting
          value: 'false'
    lambda: return id(richting);

#handbediening schakelaar
binary_sensor:
  - platform: gpio
    pin:
      number: D4
      inverted: true
    filters:
      # Small filter, to debounce the button press.
      - delayed_on: 25ms
      - delayed_off: 25ms
    name: "hand bediening"
    id: hand_bediening
    on_press:
      then:
        if:
          condition:
            - switch.is_on: handb_richting
          then:
            - switch.turn_off: handb_richting
            - if:
                condition:
                  - lambda: return id(potmeter).state < 80;
                then:
                  - switch.turn_on: output_d6
                  - delay: 10 sec
                  - switch.turn_off: output_d6
          else:
            - switch.turn_on: handb_richting
            - if:
                condition:
                  - lambda: return id(potmeter).state > 20;
                then:
                  - switch.turn_on: output_d5
                  - delay: 10 sec
                  - switch.turn_off: output_d5
    on_release:
      - switch.turn_off: output_d5
      - switch.turn_off: output_d6

cover:
  - platform: feedback
    name: "Jalousie v2bg"
    id: jalousie
    max_duration : 5 sec

    open_action:
      - switch.turn_on: output_d6
    open_duration: 5 sec

    close_action:
      - switch.turn_on: output_d5
    close_duration: 5 sec

    stop_action:
      - switch.turn_off: output_d5
      - switch.turn_off: output_d6

Awesome thank you!