Error on apiai component when upgrade from 0.49.0 to 0.50.2

Hi,
After my holidays I’ve been able to update from version 0.49.0 to version 0.50.2.
After upgrade I have a problem I cannot find any solution.
My apiai configuration looks like https://github.com/hokus15/home-assistant-config/blob/master/apiai.yaml

If I run /srv/hass/bin/hass --script check_config with version 0.49.0 I don’t get any error.
If I run /srv/hass/bin/hass --script check_config with version 0.50.2 I get the following error:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 571, in async_process_component_config
    config = component.CONFIG_SCHEMA(config)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 221, in __call__
    return self._compiled([], data)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 538, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 370, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['apiai']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/logging/__init__.py", line 980, in emit
    stream.write(msg)
UnicodeEncodeError: 'ascii' codec can't encode character '\xf3' in position 311: ordinal not in range(128)
Call stack:
  File "/srv/hass/bin/hass", line 11, in <module>
    sys.exit(main())
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/__main__.py", line 346, in main
    return scripts.run(args.script)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/__init__.py", line 57, in run
    return script.run(args[1:])  # type: ignore
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 99, in run
    res = check(config_path)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 251, in check
    bootstrap.from_config_file(config_path, skip_pip=True)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 168, in from_config_file
    config_path, hass, verbose, skip_pip, log_rotate_days)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 271, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 244, in run_forever
    self._run_once()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 1081, in _run_once
    handle._run()
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/setup.py", line 160, in _async_setup_component
    conf_util.async_process_component_config(hass, config, domain)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 573, in async_process_component_config
    async_log_exception(ex, domain, config, hass)
  File "/usr/lib/python3.4/unittest/mock.py", line 896, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/usr/lib/python3.4/unittest/mock.py", line 962, in _mock_call
    ret_val = effect(*args, **kwargs)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 215, in mock_except
    MOCKS['except'][1](ex, domain, config, hass)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 342, in async_log_exception
    _LOGGER.error(message)
Message: 'Invalid config for [apiai]: not a valid value for dictionary value @ data[\'apiai\']. Got OrderedDict([(\'intents\', OrderedDict([(\'heating.check\', OrderedDict([(\'speech\', \'{%- set status ={"on": "conectada", "off": "desconectada"} -%} La calefacci\xf3n est\xe1 {{ status[states("switch.termostato")] }}. {% if is_state("switch.termostato", "on") %}{% if states("climate.termostato") != "0"%} A una temperatura de {{ states("climate.termostato") }} grados.{% endif -%} {% if is_state_attr("climate.termostato", "operation_mode", "idle") %} No est\xe1 en marcha{%- else %} Est\xe1 en marcha{% endif -%}.... (See /home/hass/.homeassistant/configuration.yaml, line 280). Please check the docs at https://home-assistant.io/components/apiai/'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 571, in async_process_component_config
    config = component.CONFIG_SCHEMA(config)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 221, in __call__
    return self._compiled([], data)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 538, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/srv/hass/lib/python3.4/site-packages/voluptuous/schema_builder.py", line 370, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['apiai']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/logging/__init__.py", line 980, in emit
    stream.write(msg)
UnicodeEncodeError: 'ascii' codec can't encode character '\xf3' in position 306: ordinal not in range(128)
Call stack:
  File "/srv/hass/bin/hass", line 11, in <module>
    sys.exit(main())
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/__main__.py", line 346, in main
    return scripts.run(args.script)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/__init__.py", line 57, in run
    return script.run(args[1:])  # type: ignore
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 99, in run
    res = check(config_path)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 251, in check
    bootstrap.from_config_file(config_path, skip_pip=True)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 168, in from_config_file
    config_path, hass, verbose, skip_pip, log_rotate_days)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 271, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 244, in run_forever
    self._run_once()
  File "/usr/lib/python3.4/asyncio/base_events.py", line 1081, in _run_once
    handle._run()
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/setup.py", line 160, in _async_setup_component
    conf_util.async_process_component_config(hass, config, domain)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 573, in async_process_component_config
    async_log_exception(ex, domain, config, hass)
  File "/usr/lib/python3.4/unittest/mock.py", line 896, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "/usr/lib/python3.4/unittest/mock.py", line 962, in _mock_call
    ret_val = effect(*args, **kwargs)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/scripts/check_config.py", line 215, in mock_except
    MOCKS['except'][1](ex, domain, config, hass)
  File "/srv/hass/lib/python3.4/site-packages/homeassistant/config.py", line 342, in async_log_exception
    _LOGGER.error(message)
Message: 'Invalid config for [apiai]: not a valid value for dictionary value @ data[\'apiai\']. Got OrderedDict([(\'intents\', OrderedDict([(\'heating.check\', OrderedDict([(\'speech\', \'{%- set status ={"on": "conectada", "off": "desconectada"} -%} La calefacci\xf3n est\xe1 {{ status[states("switch.termostato")] }}. {% if is_state("switch.termostato", "on") %}{% if states("climate.termostato") != "0"%} A una temperatura de {{ states("climate.termostato") }} grados.{% endif -%} {% if is_state_attr("climate.termostato", "operation_mode", "idle") %} No est\xe1 en marcha{%- else %} Est\xe1 en marcha{% endif -%}.... (See /home/hass/.homeassistant/configuration.yaml, line 280). Please check the docs at https://home-assistant.io/components/apiai/'
Arguments: ()
2017-08-16 20:48:53 ERROR (MainThread) [homeassistant.setup] Setup failed for apiai: Invalid config.

I also tried to modify the config files to use the new intent_script component with the same results.

Any idea what I’m doing wrong?

Thanks!

In your configuration change it to:

apiai:

intent_script: !include apiai.yaml

In your apiai.yaml you no longer need the first line with “intents:”

Hi,

Thanks for your response. I also tried your suggested change and got the same error. It seems to be related with spanish characters like “ó”, “é”,… But what I don’t understand is why with 0.49.0 it worked and with 0.50.2 no.

Any other suggestion?

Have you tried updating to the latest version of HASS 51.2? I just started from scratch a new api.ai webhook with intents and it worked. If the issue is with the spanish characters, has the apiai.yaml changed encoding from .49?

Thanks!

Yes also tried with the latest version.

Regarding the encoding I don’t the encoding of the file is the problem. If I downgrade to version 0.49 without changing the file it works perfectly. So it seems to be related with the new version (starting on 0.50)

The only thing that has really changed from 0.49 with 0.50+ is the way the intents are handled. Are you able to try and simpify your apiai.yaml to just:

  heatingcheck:
    speech: >
      {%- set status ={"on": "conectada", "off": "desconectada"} -%}
      La calefacción está {{ status[states("switch.termostato")] }}. {% if is_state("switch.termostato", "on") %}{% if states("climate.termostato") != "0"%} A una temperatura de {{ states("climate.termostato") }} grados.{% endif -%} {% if is_state_attr("climate.termostato", "operation_mode", "idle") %} No está en marcha{%- else %} Está en marcha{% endif -%}{%- if is_state("switch.termostato_modo_ausente", "on") %} y tiene el modo ausente activado.  {%- else %} y tiene el modo ausente desactivado. {% endif %}{% endif %}

Hi.
Thanks for your suggestion. It worked!
Now I’ll try to add the other intent scripts step by step to see where the error is.
Maby thanks for your support.

Hi,

I’ve recreated all my scripts following your recomendation and it worked. I’m getting the following error : This intent is not yet configured within Home Assistant.

My configuration file looks like:

apiai:

intent_script: !include intent_scripts.yaml

My intent_scripts.yaml configuration.yaml looks like https://github.com/hokus15/home-assistant-config/blob/master/intent_scripts.yaml

The log file:
[homeassistant.components.apiai] Received unknown intent device.check

But the intent device.check exists in the intent_scripts.yaml file.
What I’m doing wrong?

Hi,

I didn’t realize that in the intent configuration you need to add the text field into the speech. I did it and it solved my problem.

I’ve just send a pull request to update the documentation of the api.ai component,

Thanks!