Skip to content

Rendering Templates Example

Philipp Hack edited this page Oct 24, 2020 · 3 revisions

The following example shows how to render a template and play the result via the TTS Integration. You will need to set hass_is_global: true in your pyscript configuration.

Please check the related Home Assistant documentation for information on how to use templates.

from homeassistant.helpers.template import Template
def render_template(template, **kwargs):
    tpl = Template(template, hass)
    return str(tpl.async_render(kwargs))

def say_weather():
    message = render_template("Hello! It is {{ states('weather.home') }}!")
    tts.google_translate.say(message=message)