ESPHome cover component positioning controls

I have a cover that I need to control to different positions using ESPHome.

From the docs, the component is configured thus:

  - platform: endstop
    name: "Endstop Cover"

      - switch.turn_on: open_cover_switch
    open_duration: 2.1min
    open_endstop: open_endstop_binary_sensor

      - switch.turn_on: close_cover_switch
    close_duration: 2min
    close_endstop: close_endstop_binary_sensor

      - switch.turn_off: open_cover_switch
      - switch.turn_off: close_cover_switch

I have a linear potentiometer sensor that reports the cover position:

### Linear potentiometer inputs
  - id: back_height
    platform: adc
    pin: 33
    name: "Back height"
    update_interval: 0.5s
    unit_of_measurement: mm
    attenuation: auto
      - calibrate_linear:
         method: least_squares
          - 0.0 -> -2.38
          - 3.1499 -> 99.8
      - delta: 2.0
      - clamp:
          min_value: 0
          max_value: 100
          ignore_out_of_range: true
      - round: 0

My intention was to use analog threshold binary sensors for the open_endstop and closed_endstop for the cover, thereby controlling the position.

  - platform: analog_threshold
    id: open_endstop
    sensor_id: back_height
    threshold: !!!!!!!insert lambda here!!!!!!!
      - delayed_off: 0.8s

  - platform: analog_threshold
    id: closed_endstop
    sensor_id: back_height
    threshold: !!!!!!!insert lambda here!!!!!!!
      - delayed_off: 0.8s

I am stuck with the analog_threshold binary sensors threshold.

When I try to set that I get an error saying float required.

The docs suggest that the threshold accepts shorthand float or a mapping, but not !lambda.

I can’t get how to use mapping to achieve my goal.

Any suggestions?

Doesn’t look like you can use lambda/templates with that.

You could switch to a template binary sensor?

Do you want to be able to change the limits during runtime?

Or do you just want to be able to set_position?

I think the template cover allows you to integrate a sensor that gives a continuous position (if that would help).

Thanks for the reply.

I need to be able to change the endstops to adjust the position.

I actually have three actuators and have linear potentiometers that track the position.

They are fitted to a therapy bed. I need to have it operate similarly to how a car memory seat works.

The analog threshold binary sensor is the obvious solution but it just doesn’t support lambdas for the threshold.

I may have to do it the long-winded way.

I think this is similar to how standing desk presets / memory settings work.

Example Here

So maybe you could preconfigure some set_position’s similar to the above example if you integrate a position sensor into your cover?

Could be good to put a moving median filter (3 or 5?) on your adc it if it is noisey.