Speech helper template macros for Home Assistant
Pluralize a word when required.
- word - word to pluralize [string]
- qty - numerical quantity [number]
- show_qty - preceed the word with the quantity [boolean]
{% from 'speech_helpers.jinja' import plural %}
You need to leave for work in {{ plural('minute', 10, true) }}!
You need to leave for work in 10 minutes!
Display proper verb for given quantity.
- qty - numerical quantity [number]
{% from 'speech_helpers.jinja' import plural_verb %}
{% from 'speech_helpers.jinja' import plural %}
{% set qty_apple = 5 %}
{% set qty_orange = 1 %}
There {{ plural_verb(qty_apple) }} {{ plural('apple', qty_apple, true) }}.
The {{ plural('orange', qty_orange, false) }} {{ plural_verb(qty_orange) }} yummy.
There are 5 apples.
The orange is yummy.
Convert an array of items to a comma separated list.
- arr - array of items [list]
- title - list items with title case [boolean]
{% from 'speech_helpers.jinja' import array_to_clist %}
{% set active_types = ['garbage', 'recycle', 'yard waste'] %}
Don't forget to take out the {{ array_to_clist(active_types, false) }} today!
Don't forget to take out the garbage, recycle, and yard waste today!
Add the apropriate indefinate article (a, an) before a word. Numerical values will automatically be coverted to the text equivelent.
- word - word to preceed with an indefinate article [string]
{% from 'speech_helpers.jinja' import iarticle %}
There is {{ iarticle(50) }} percent chance of rain today.
There is {{ iarticle(85) }} kilometer difference in the commute.
That was {{ iarticle('honourable') }} thing to do.
There is a fifty percent chance of rain today.
There is an eighty five kilometer difference in the commute.
That was an honourable thing to do.
Convert a numerical value to it's text equivelent.
- number - a numberical value [integer]
{% from 'speech_helpers.jinja' import number_words %}
{{ number_words(123456789) }}
one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine
Convert a numerical compass bearing to cardinal direction short form. (eg. NNW)
- bearing - a numberical bearing value (0-360) [integer]
{% from 'speech_helpers.jinja' import cardinal_direction %}
{{ cardinal_direction(250) }}
WSW
Convert a numerical compass bearing to cardinal direction long form. (eg. North-Northwest)
- bearing - a numberical bearing value (0-360) [integer]
{% from 'speech_helpers.jinja' import full_cardinal_direction %}
{{ full_cardinal_direction(250) }}
West-Southwest