Create switch from cover postition

Hi
I’m trying configure my custom switch for dafan camera
someone can give me a hint what i’m doing wrong

- platform: template
  switches:
    pos1:
      friendly_name: Przedpokoj3
      value_template: >
       {% if is_state_attr('cover.dafang_move_left_right', 'current_position', 71) %}
       on 
       {% else %}
       off
       {% endif %}
      turn_on:
        service: cover.set_cover_position 
        data:
          entity_id: cover.cam_dafang_move_left_right          
          position: 71

      turn_off:
        service: cover.set_cover_position 
        data:
          position: 0
          entity_id: cover.cam_dafang_move_left_right 

value_template should only return true or false.

- platform: template
  switches:
    pos1:
      friendly_name: Przedpokoj3
      value_template: "{{ is_state_attr('cover.dafang_move_left_right', 'current_position', 71) }}"
      turn_on:
        service: cover.set_cover_position 
        data:
          entity_id: cover.cam_dafang_move_left_right          
          position: 71

      turn_off:
        service: cover.set_cover_position 
        data:
          position: 0
          entity_id: cover.cam_dafang_move_left_right 
1 Like

I tried with you example but behavior is this same after turn on 3 second and button return to state off and cover value is not changed https://gfycat.com/gracefulbronzebird

Does your cover report a position? If the cover position does not equal 71, then it will appear off. That’s what the value template is doing. It’s how the switch gets a state.

Hi

Cover return position in attribute Screenshot%20from%202019-09-12%2006-36-48
So what i should use for set custom cover position.

Thank you for you patience
Br
Dzaczek

Ok it was my typo mistake . I used wrong cover name . Sorry for for the confusion .