Template cover lambda

Could anyone give assistance on this? I have a cover that is operated by 2 relays, one for up and one for down. I have this working fine as a time based cover but I have now introduced a magnetic encoder to give real feedback on position. I dont know coding but have spent years with home assistant so used to yaml and trying to work things out but unfortunately lambdas are well above me!

I tried using AI but this did not get to resolution and the lambda got longer and longer so I have started from scratch.

The rotary encoder (magnetic encoder) has steps as the position and 0 is open, 225 is closed. I want to open the cover and it stop when it gets to 0 and vice versa for closed. I think I need to define the position values first but this is what I have so far.

Any advice?

sensor:
  - platform: rotary_encoder
    id: right_blind_position_raw
    name: "Right Blind Rotary Sensor Raw"
    pin_a: GPIO21
    pin_b: GPIO19
	
switch:
  - platform: gpio
    pin: GPIO27
    inverted: true
    id: right_blind_close
    name: "Right Blind Close"

  - platform: gpio
    pin: GPIO26
    inverted: true
    id: right_blind_open
    name: "Right Blind Open"
	
cover:
  - platform: template
    name: "Right Blind"
    id: right_blind_cover
    has_position: true
    optimistic: false

    open_action:
      - lambda: |-
          int current_steps = id(right_blind_position_raw).state;
          int target_steps = 0;

          if (current_steps > target_steps) {
            id(right_blind_open).turn_on();

    close_action:
      - lambda: |-
          int current_steps = id(right_blind_position_raw).state;
          int target_steps = 225;

          if (current_steps < target_steps) {
            id(right_blind_close).turn_on();

    stop_action:
      - cover. turn_off
			id: right_blind_close
			id: right_blind_open

I think it should be something close to this:

cover:
  - platform: template
    name: "Right Blind"
    id: right_blind_cover
    has_position: true
    optimistic: false
    lambda: |-
        float position = id(right_blind_position_raw).state / 255.0;
        return position;

    open_action:
      - switch.turn_on: right_blind_open
    close_action:
      - switch.turn_on: right_blind_close
    stop_action:
      - switch.turn_off: right_blind_open
      - switch.turn_off: right_blind_close
    on_open:
      - switch.turn_off: right_blind_open
    on_closed:
      - switch.turn_off: right_blind_close

You need to invert the encoder, 0 is closed, 255 is open