Cover Template: set_cover_position Help

I am trying to setup a cover template but am confuse of what to add to the set cover position. This is my current setting and both the open and close work. What do I need to add to the set_cover_position part?

  - platform: template
    covers:
      computer_room_curtains:
        device_class: curtain
        friendly_name: "Computer Room Curtains"
        position_template: "{{ states('sensor.cr_curtain_left_position') }}"
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.computer_room_curtains
        close_cover:
          service: switch.turn_off
          data:
            entity_id: switch.computer_room_curtains
        set_cover_position:
          service: 
          data:
            entity_id: 
            position: 
        icon_template: >-
          {% if states('sensor.cr_curtain_left_position')|float < 90 %}
            mdi:blinds-open
          {% else %}
             mdi:blinds
          {% endif %}

switch.yaml

  - platform: command_line
    switches:
      computer_room_curtains:
        friendly_name: Computer Room Curtains
        command_on: 'curl -k "http://192.168.1.30:5004/?id=c5c6df6834df&cmd=open"'
        command_off: 'curl -k "http://192.168.1.30:5004/?id=c5c6df6834df&cmd=close"'
      computer_room_curtains_position:
        friendly_name: Computer Room Curtains Position
        command_on: 'curl -k "http://192.168.1.30:5004/?id=c5c6df6834df&cmd=pos&set={{position}}"'
        command_off: 'curl -k "http://192.168.1.30:5004/?id=c5c6df6834df&cmd=pos&set={{position}}"'

I got it working now. This thread gave me a clue as to what I needed to set up the cover position. The switch method would not work but a shell command would.

shell command:

  computer_room_curtains_position: 'curl -k "http://192.168.1.30:5004/?id=c5c6df9448bc&cmd=pos&set={{position}}"'

cover:

  - platform: template
    covers:
      computer_room_curtains:
        device_class: curtain
        friendly_name: "Computer Room Curtains"
        position_template: "{{ states('sensor.cr_curtain_left_position') }}"
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.computer_room_curtains
        close_cover:
          service: switch.turn_off
          data:
            entity_id: switch.computer_room_curtains
        set_cover_position:
          service: shell_command.computer_room_curtains_position
          data_template:
            position: "{{ position }}"
        icon_template: >-
          {% if states('sensor.cr_curtain_left_position')|float < 90 %}
            mdi:blinds-open
          {% else %}
             mdi:blinds
          {% endif %}

Now that I got the cover template working, I notice the state (open | closed) does not change when the curtains opens or closes. I think that is because the position number do not indicate as fully open (0) or closed (100). It hovers around 2 or 97.

Also my device reads the opposite. HA reads fully open as (100) and fully closed as (0).

Update:
After some more searching and tinkering with the code, I have got my curtains to read and trigger proper.

  - platform: template
    covers:
      computer_room_curtains:
        device_class: curtain
        friendly_name: "Computer Room Curtains"
        value_template: >-
          {% if states('sensor.cr_curtain_left_position')|float < 90 %}
            open
          {% else %}
            closed
          {% endif %}
        open_cover:
          service: switch.turn_on
          data:
            entity_id: switch.computer_room_curtains
        close_cover:
          service: switch.turn_off
          data:
            entity_id: switch.computer_room_curtains
        set_cover_position:
          service: shell_command.computer_room_curtains_position
          data_template:
            position: "{{ position }}"
        icon_template: >-
          {% if is_state('cover.computer_room_curtains', 'open') %}
            mdi:blinds-open
          {% else %}
             mdi:blinds
          {% endif %}
1 Like