You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Daniel Lashua edited this page Oct 27, 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.
fromhomeassistant.helpers.templateimportTemplatedefrender_template(template, **kwargs):
tpl=Template(template, hass)
returnstr(tpl.async_render(kwargs))
defsay_weather():
message=render_template("Hello! It is {{ states('weather.home') }}!")
tts.google_translate_say(message=message)
While there may be cases where rendering a Home Assistant Template is exactly what you need, keep in mind that, effectively, pyscriptIS a template language of because of its syntax. The above say_weather() function could be written like this:
defsay_weather():
message=f"Hello! It is {weather.home}!"tts.google_translate_say(message=message)