diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index 18b743d06ca..11f1826549e 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -12,6 +12,7 @@ import threading import json import homeassistant.core as ha +from homeassistant.exceptions import TemplateError from homeassistant.helpers.state import TrackStates import homeassistant.remote as rem from homeassistant.util import template @@ -377,11 +378,16 @@ def _handle_post_api_template(handler, path_match, data): """ Log user out. """ template_string = data.get('template', '') - handler.send_response(HTTP_OK) - handler.send_header(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN) - handler.end_headers() - handler.wfile.write( - template.render(handler.server.hass, template_string).encode('utf-8')) + try: + rendered = template.render(handler.server.hass, template_string) + + handler.send_response(HTTP_OK) + handler.send_header(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN) + handler.end_headers() + handler.wfile.write(rendered.encode('utf-8')) + except TemplateError as e: + handler.write_json_message(str(e), HTTP_UNPROCESSABLE_ENTITY) + return def _services_json(hass): diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index 37e9b39079e..98f0435e9f3 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) FRONTEND_URLS = [ URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState', - '/devEvent', '/devInfo', '/states'] + '/devEvent', '/devInfo', '/devTemplate', '/states'] _FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE) diff --git a/homeassistant/components/frontend/index.html.template b/homeassistant/components/frontend/index.html.template index c0631c9d9db..e21d00e86bc 100644 --- a/homeassistant/components/frontend/index.html.template +++ b/homeassistant/components/frontend/index.html.template @@ -13,7 +13,7 @@