Service_template & data_template within 1 automation

Excellent, I’ll remember that.

I assume the same applies, if the entity_id for both service calls is equal, but one of the service calls requires additional information?

In my specific case I try to drive a roller shutter to a specific position, when the down button is pressed. However if the position is already reached, or the shutter is already below that position, the button press should fully close the roller shutter.
cover.set_cover_position requires an entity and a position, whereas cover.close_cover only requires the entity to be defined.

        - service: >
            {% if states.cover.kids_room.attributes.current_position > 10 %}
              cover.set_cover_position
            {% else %}
              cover.close_cover
            {% endif %}
          data:
            entity_id: cover.kids_room
            position: 10

I helped myself by using choose instead of a service template. In case anybody is questioning how, this is how I solved it:

        - choose:
          - conditions:
              condition: template
              value_template: "{{ states.cover.kids_room.attributes.current_position > 10 }}"
            sequence:
              service: cover.set_cover_position
              data:
                entity_id: cover.kids_room
                position: 10
          default:
            - service: cover.close_cover
              entity_id: cover.kids_room
1 Like