Hello,
I’ve created this automation with the help of ChatGPT, but I can’t get it to work. Maybe it’s not possible to achieve yet? I’ve tried many versions, and it’s still not functioning.
I’m very new to Home Assistant and don’t know how to write in Jinja and YAML, which is why I rely on ChatGPT.
What I want is to receive a greeting when one person arrives home and the door opens. I want to wait 5 seconds and then trigger the automation. So far, this part seems to work. However, I also want it to check if more people are arriving home at the same time, so It can greet them by name. This part seems impossible to get working.
Additionally, I would like it to check if all members arrive home together, in which case it should play a “Welcome Home” greeting without any names.
I’ve even tried to simply add a “Welcome Home” greeting if more than one person arrives, but I couldn’t get that to work either.
I’m not sure if this is achievable, but ChatGPT just repeated itself, so I gave up. Now, I’m hoping someone can help me with this or let me know if it’s not possible, so I can move on to something else.
Thanks!
alias: Welcome Home
description: ""
trigger:
- platform: state
entity_id:
- person.bogdan
- person.burcu
- person.deva
- person.oscar
to: home
action:
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.aqara_door_sensor_ingang_door_2
to: "on"
- delay:
hours: 0
minutes: 0
seconds: 5
- choose:
- conditions:
- condition: template
value_template: |
{{ is_state('person.bogdan', 'home') and
is_state('person.burcu', 'home') and
is_state('person.deva', 'home') and
is_state('person.oscar', 'home') and
is_state('person.bogdan', 'not_home', trigger.from_state) and
is_state('person.burcu', 'not_home', trigger.from_state) and
is_state('person.deva', 'not_home', trigger.from_state) and
is_state('person.oscar', 'not_home', trigger.from_state) }}
sequence:
- data:
entity_id: media_player.google_mini
message: >-
Välkommen hem allihopa!
language: sv
action: tts.google_translate_say
- conditions:
- condition: template
value_template: |
{{ trigger.to_state.state == 'home' }}
sequence:
- data:
entity_id: media_player.google_mini
message: >
{% set arriving = [] %}
{% if is_state('person.bogdan', 'home') and trigger.entity_id ==
'person.bogdan' %}
{% set arriving = arriving + ['Bågdan'] %}
{% endif %}
{% if is_state('person.burcu', 'home') and trigger.entity_id ==
'person.burcu' %}
{% set arriving = arriving + ['Burgio'] %}
{% endif %}
{% if is_state('person.deva', 'home') and trigger.entity_id ==
'person.deva' %}
{% set arriving = arriving + ['Deh-va'] %}
{% endif %}
{% if is_state('person.oscar', 'home') and trigger.entity_id ==
'person.oscar' %}
{% set arriving = arriving + ['Oscar'] %}
{% endif %}
{# Handling the greeting message for multiple arrivals #}
{%- if arriving|length == 1 -%}
"Välkommen hem {{ arriving[0] }}!"
{%- elif arriving|length > 1 -%}
"Välkommen hem, {{ arriving|join(', ', ' och ') }}!"
{%- endif %}
language: sv
action: tts.google_translate_say
mode: single