Error in log: Error executing script. Template rendered invalid service

I’m fighting with an error but can’t get to understand why it’s here… Here’s my automation script

alias: Thermostat - Fan Only
description: ''
  - platform: mqtt
    topic: Tasmota_HVAC/HASS/Mode
condition: []
  - service_template: >
      {% if is_state('climate.study_mqtt', 'fan_only') and
      is_state('switch.hvac_fan','off') %}
      {% elif not is_state('climate.study_mqtt', 'fan_only') and
      is_state('switch.hvac_fan','on') %}
      {% endif %}
      entity_id: switch.hvac_fan
mode: single

And I get this error in the log: Error executing script. Unexpected error for call_service at pos 1: Template rendered invalid service
Interestingly, the automation works with no problem…

Here is the detailed log:

Logger: homeassistant.components.automation.thermostat_fan_only
Source: helpers/
Integration: Automation (documentation, issues)
First occurred: January 2, 2021, 10:38:29 AM (32 occurrences)
Last logged: 1:04:15 PM

Thermostat - Fan Only: Error executing script. Unexpected error for call_service at pos 1: Template rendered invalid service:
While executing automation automation.thermostat_fan_only
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/", line 166, in async_prepare_call_from_config
    domain_service = cv.service(domain_service)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 463, in service
    raise vol.Invalid(f"Service {value} does not match format <domain>.<name>")
voluptuous.error.Invalid: Service  does not match format <domain>.<name>

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

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

Any idea of what’s wrong here?

Sorry to insist, but am I the only one with this error (which would mean it’s due to my code) or not?