To make voice and text messages sound more natural, it is important that the grammar is flawless.
Unfortunately, I haven’t yet found an elegant way to have my location notifications phrase out into complete sentences.
So far I maintain a monster of a data template, but it is hardcoded and any addition to it creates a risk to the functionality of the automation. The auto-formatting of the YAML code is also doing its part to frustrate me, and I don’t like the working solution below at all.
I have also considered whether I can and should extend the zone entities with attributes for prepositions and articles.
I am sure that the following automation can be optimized. And I am aware that in the meantime there are no data_templates at all.
Maybe you guys have some good tips for me on how to slightly improve the correct naming of the zones in my notifications.
- id: '1623768194152'
alias: Zonenwechsel Benachrichtigung
description: ''
trigger:
- platform: state
entity_id: person.me,person.her,person.him
condition:
- condition: template
value_template: '{{ trigger.to_state is not none and (trigger.from_state is none
or trigger.to_state.state != trigger.from_state.state) }}'
action:
- service: notify.mobile_app_galaxy_note
data_template:
message: ->
{% set name = trigger.to_state.name %}
{% set enter_zone_map = {
"home": "zu Hause",
"not_home": "unterwegs",
"altdorf": "in Altdorf",
"arzt": "beim Arzt",
"buro": "im Büro",
"evi_fynn": "bei Evi und Fynn",
"friseur_yasemin": "beim Frisör Yasemin",
"gassi_wald": "im Gassi-Wald",
.
.
.
"verena": "bei Verena",
"zim": "im ZIM",
"zimmermannspark": "im Zimmermannspark"
}
%}
{% set leave_zone_map = {
"home": "das Haus",
"not_home": "unterwegs",
"altdorf": "Altdorf",
"arzt": "den Arzt",
"buro_steffi": "das Büro",
"evi_fynn": "Evi und Fynn",
"friseur_yasemin": "den Frisör Yasemin",
"gassi_wald": "den Gassi-Wald",
.
.
.
"verena": "Verena",
"zim": "das ZIM",
"zimmermannspark": "den Zimmermannspark"
}
%}
{% set from = trigger.from_state.state if trigger.from_state.state is not none else "unknown" %}
{% set from = leave_zone_map.get(from, from) %}
{% set to = trigger.to_state.state %}
{% set to = enter_zone_map.get(to, to) %}
{{ name }} {% if from != "unterwegs" %}hat {{ from }} verlassen{% endif %}
{% if from != "unterwegs" and to != "unterwegs" %} und {% endif %}
{% if to != "unterwegs" %}ist {{ to }} angekommen{% endif %}.'
data:
tag: '{{ trigger.to_state.name }}'
group: Location