Error with script include service template

Hello
First, excuse me for my poor english…
I have a script which include service_template.

What I want to do :
I have tilt cover, and I want to verify if the covers are closed before send the tilt position.

This is my script :

bso_ouvre_cuisine_autres_tilt_100:
  alias: Ouvre BSO Cuisine et lamelles autres
  sequence:
  - service: cover.open_cover
    data:
      entity_id: cover.bso_cuisine
  - service_template: >
      {% if is_state('cover.bso_bv_cuisine', 'open') %}
        cover.close_cover
      {% else %}
      {% endif %}
    data:
      entity_id: cover.bso_bv_cuisine
  - service_template: >
      {% if is_state('cover.bso_sam', 'open') %}
        cover.close_cover
      {% else %}
      {% endif %}
    data:
      entity_id: cover.bso_sam
  - service_template: >
      {% if is_state('cover.bso_bv_salon', 'open') %}
        cover.close_cover
      {% else %}
      {% endif %}
    data:
      entity_id: cover.bso_bv_salon
  - service_template: >
      {% if is_state('cover.bso_pf_salon', 'open') %}
        cover.close_cover
      {% else %}
      {% endif %}
    data:
      entity_id: cover.bso_pf_salon
  - service: cover.set_cover_tilt_position
    data:
      entity_id:
      - cover.bso_bv_cuisine
      - cover.bso_sam
      - cover.bso_bv_salon
      - cover.bso_pf_salon
      tilt_position: 100

But I have this error :

Error executing script. Unexpected error for call_service at pos 2: Template rendered invalid service:
Traceback (most recent call last):
File « /usr/src/homeassistant/homeassistant/helpers/service.py », line 166, in async_prepare_call_from_config
domain_service = cv.service(domain_service)
File « /usr/src/homeassistant/homeassistant/helpers/config_validation.py », line 463, in service
raise vol.Invalid(f"Service {value} does not match format .")
voluptuous.error.Invalid: Service does not match format .

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File « /usr/src/homeassistant/homeassistant/helpers/script.py », line 250, in _async_step
await getattr(
File « /usr/src/homeassistant/homeassistant/helpers/script.py », line 429, in _async_call_service_step
domain, service_name, service_data = service.async_prepare_call_from_config(
File « /usr/src/homeassistant/homeassistant/helpers/service.py », line 172, in async_prepare_call_from_config
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Template rendered invalid service:

Could you help me please ?

Thanks

None of your service templates have an else, so if the covers aren’t open the service doesn’t resolve to anything.

Your templates don’t make sense anyway, just use the close cover service in each case.

Thank you for your answer.

This is what I do. But there is 50 seconds (the time to close the knx cover) between the first action and the action “tilt position” if I just use close cover service, and if the the tilt position is already 100%, when I execute the script, the cover closes (so tilt position = 0%) and go to the position 100% after 50 seconds.

Maybe try:

- service_template: >
      {% if is_state('cover.bso_bv_salon', 'open') %}
        cover.close_cover
      {% else %}
        cover.stop_cover
      {% endif %}

Unless the cover is currently moving it shouldn’t do anything, and it will prevent passing an undefined service if the cover isn’t open.

1 Like

This - but in addition unless you you’re using an old version of homeassistant then service_template is deprecated, just use service. Forgot to mention it earlier.

Thank you very much!

With service in place of service_template and with the else instruction, the covers do what I want :slight_smile: