Script error when setting volume for whole house

I have the following portion of a script that sets the volume for the house prior to making a voice announcement.

    - service: media_player.volume_set
      data_template:
        entity_id: media_player.whole_house
        volume_level: >-
          {% if states.input_boolean.alert_mode.state == 'on' %}
            0.8
          {% elif states.input_boolean.school_mode.state == 'on' and now().strftime('%H')|int >= 6 and now().strftime('%H')|int < 20 %}
            0.8
          {% elif states.input_boolean.school_mode.state != 'on' and now().strftime('%H')|int < 10 and now().strftime('%H')|int >= 6 %}
            0.5
          {% elif states.input_boolean.school_mode.state != 'on' and now().strftime('%H')|int > 10 and now().strftime('%H')|int < 20 %}
            0.8
          {% else %}
            0.4
          {% endif %}

It is kicking back the following errors

Error while executing automation automation.med_check. Unknown error for call_service at pos 1:
August 27, 2019, 12:10 PM components/media_player/__init__.py (ERROR)
Error executing script script.speech_engine. Unknown error for call_service at pos 2:
August 27, 2019, 12:10 PM components/media_player/__init__.py (ERROR)
Error executing script script.speech_processing. Unknown error for call_service at pos 3:
August 27, 2019, 12:10 PM components/media_player/__init__.py (ERROR)

All 3 of these breakout into basically this.

Tue Aug 27 2019 12:10:07 GMT-0500 (Central Daylight Time)
Error while executing automation automation.med_check. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 427, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 235, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 318, in _async_call_service
    context=context,
  File "/usr/src/app/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/app/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 128, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 193, in async_turn_on
    raise err
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 188, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 235, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 318, in _async_call_service
    context=context,
  File "/usr/src/app/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/app/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 128, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 193, in async_turn_on
    raise err
  File "/usr/src/app/homeassistant/components/script/__init__.py", line 188, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 151, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 235, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 318, in _async_call_service
    context=context,
  File "/usr/src/app/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/app/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 210, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/app/homeassistant/helpers/service.py", line 334, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/app/homeassistant/helpers/service.py", line 358, in _handle_service_platform_call
    await func(entity, data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/media_player/__init__.py", line 555, in set_volume_level
    raise NotImplementedError()
NotImplementedError

I know the NotImplementedError() typically means that the entity being referred to in the service call does not support the service being called. Since when can you not set the volume on a media player? lol

Obviously I am missing something, quite probably obvious. Any help would be appreciated. One other thing, it seems to only affect the following automation

  - alias: 'Med Check'
    initial_state: 'on'
    trigger:
      - platform: time
        at: '06:30:00'

    condition:
      - condition: state
        entity_id: input_boolen.school_mode
        state: 'on'

    action:
      - service: script.speech_engine
        data:
          call_no_announcement: 1
          call_med_reminder: 1

and for completeness, here is the macro called by the automation.

          {%- macro med_reminder() -%}
            Don't leave for school yet.
            {% if states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.lola_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Eleanor, Lola and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.lola_meds.state == 'off' %}
              Eleanor and Lola have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Eleanor and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.lola_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Lola and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' %}
              Eleanor has not taken her morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.lola_meds.state == 'off' %}
              Lola has not taken her morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.william_meds.state == 'off' %}
              William has not taken his morning meds.  Please take them before leaving for school.
            {% else %}
              Everyone has taken their meds this morning!  Have a great day!
            {%- endif -%}
          {%- endmacro -%}

If you need a more complete look at the automation or scripts involved, it’s all on my GitHub.

automation
speech engine
speech processing

Remove the single quote in Don't and this happens:

          {%- macro med_reminder() -%}
            Dont leave for school yet.
            {% if states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.lola_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Eleanor, Lola and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.lola_meds.state == 'off' %}
              Eleanor and Lola have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Eleanor and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.lola_meds.state == 'off' and states.input_boolean.william_meds.state == 'off' %}
              Lola and William have not taken their morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.emmy_meds.state == 'off' %}
              Eleanor has not taken her morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.lola_meds.state == 'off' %}
              Lola has not taken her morning meds.  Please take them before leaving for school.
            {% elif states.input_boolean.william_meds.state == 'off' %}
              William has not taken his morning meds.  Please take them before leaving for school.
            {% else %}
              Everyone has taken their meds this morning!  Have a great day!
            {%- endif -%}
          {%- endmacro -%}

Compare the red (quoted) text with your original.

for some reason Atom doesn’t color code the scripts, SO freaking obvious when it is color coded. lol

Thank you!!!

VSCode FTW! :slight_smile: