Help with template error

I can’t figure out why this template isn’t working. If I go to services in Developer Tools, I am able to run ffmpeg.start with the entity_id, but this error seems to indicate that ffmpeg.start isn’t valid?

- alias: Wyzecam Noise Detection
  trigger:
    platform: state
    entity_id: input_boolean.wyzecam_noise_detect
  action:
    data_template:
      entity_id: binary_sensor.wyzecam_noise 
    service_template: >-
      {% if (trigger.to_state) == 'on' %}
        ffmpeg.start
      {% elif (trigger.to_state) == 'off' %}
        ffmpeg.stop
      {% endif %}
2020-05-03 13:39:06 ERROR (MainThread) [homeassistant.components.automation] Wyzecam Noise Detection: Error executing script. Unexpected error for call_service at pos 1: Template rendered invalid service:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 115, in async_prepare_call_from_config
domain_service = cv.service(domain_service)
File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 411, in service
raise vol.Invalid(f"Service {value} does not match format <domain>.<name>")
voluptuous.error.Invalid: Service does not match format <domain>.<name>
- alias: Wyzecam Noise Detection
  trigger:
    platform: state
    entity_id: input_boolean.wyzecam_noise_detect
  action: 
    service_template: "ffmpeg.{{ 'start' if trigger.to_state.state == 'on' else 'stop' }}" 
    entity_id: binary_sensor.wyzecam_noise 
1 Like

Ah, was the .state I was missing.

Thanks! Your solution was more elegant than mine anyway.

1 Like