Greeting last person comming home

Hi guys,

I need to share this with you. The task was to identify the last person comming home and greet him/her.

Kudos for the set of different greetings go to CCOSTAN

How to find the last person comming home? Somehow this must be possible. And yes. Its not so difficult at the end.

Here the full code, I hope you like it.

- alias: "Eingang - Identify comming home"
  trigger:
    - platform: state
      entity_id: binary_sensor.hausture
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: binary_sensor.eingang_motion
      state: 'off'
      for:
        minutes: 5
    - condition: state
      entity_id: binary_sensor.eingang_someone_known
      state: 'off'
      for:
        minutes: 5
    - condition: state
      entity_id: binary_sensor.eingang_someone_unknown
      state: 'off'
      for:
        minutes: 5
  action:
    - wait_template: "{{ is_state('binary_sensor.hausture', 'off') }}"
      timeout: '00:04:00'
    - delay: '00:02:00'
    - service: notify.alexa_media
      data_template:
        target:
          - media_player.echo_wohnen
        data:
          type: announce
        message: >-
          {% set person = [
            states.person.person1, 
            states.person.person2, 
            states.person.person3, 
            states.person.person4] | 
              sort(reverse=true, attribute='last_changed') |
              selectattr('state','eq','home') | 
              map(attribute='name') | 
              list | first %}
          {% set greeting = [
          "Willkommen zu Hause " ~ person,
          "Ratet mal wer heimgekommen ist ? " ~ person ~ "!",
          person ~ " ist nun im Haus.",
          "Willkommen zu Hause " ~ person ~ ".  Wir haben dich vermisst.",
          "Unser Zuhause ist jetzt komplett. Ruhe dich aus " ~ person ~ "!",
          "Hallo " ~ person ~ " Willkommen zu Hause!",
          "Eine Raum Zeit Verschiebung ich wahrnehme. Heimgekommen "  ~ person ~ " ist!",
          "Und das Haus wird wieder zu einem Zuhause. Willkommen zurück " ~ person ~ ".",
          person ~ " ist nun hier. Hash tag Willkommen zu Hause.",
          "Eine kurze Ankündigung. " ~ person ~ " ist angekommen!",
          "Entschuldigt die Störung, aber " ~ person ~ " is zurück!",
          "Das System hat die Ankunft eines weiteren Humanoiden erkannt. " ~ person ~ " wurde zu Hause identifiziert.",
          "Es sieht so aus als ob " ~ person ~ " nun endlich wieder zu Hause ist! Klasse. "
          ] | random %}
          {{greeting}}

I hopy you like it. Enjoy.

Regards
Ralf

4 Likes

Created a version which does not need dedicated sensors to identify the comming home situation. I hope you like it.

- alias: Eingang - Identify comming home NEU
  id: ffe7c070-444d-4498-bdd6-6da584583b67
  mode: restart
  max: 4
  trigger:
    - platform: state
      entity_id:
        - person.id1
        - person.id2
        - person.id3
        - person.id4
      from: "not_home"
      to: "home"
  action:
    - service: group.set
      data:
        object_id: "arriving"
        add_entities: >-
          {{ trigger.to_state.entity_id }}
    - delay: "00:02:00"
    - service: notify.alexa_media
      data_template:
        target:
          - media_player.echo_wohnzimmer
        data:
          type: announce
        message: >-
          {% set persons = expand('group.arriving') | map(attribute='name') | join(', ') | regex_replace(',([^,]*)$',' und\\1') %}
          {% set peoplecount = expand('group.arriving') | count %}
          {{ [
            "Willkommen zu Hause, " ~ persons,
            "Ratet mal wer heimgekommen ist? " ~ persons ~ "!",
            persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " nun im Haus.",
            "Willkommen zu Hause " ~ persons ~ ". Wir haben " ~ ('dich' if peoplecount == 1 else 'euch') ~ " vermisst.",
            "Unser Zuhause ist jetzt komplett. " ~ ('Ruhe dich aus ' if peoplecount == 1 else 'Ruht euch aus ') ~ persons ~ "!",
            "Hallo " ~ persons ~ ", Willkommen zu Hause!",
            "Eine Raum Zeit Verschiebung ich wahrnehme. Heimgekommen "  ~ persons ~ " " ~ ('ist!' if peoplecount == 1 else 'sind!'),
            "Und das Haus wird wieder ein Zuhause. Willkommen zurück " ~ persons ~ ".",
            persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " nun hier. Hash tag Willkommen zu Hause.",
            "Eine kurze Ankündigung. " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " angekommen!",
            "Entschuldigt die Störung, aber " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " zurück!",
            "Das System hat die Ankunft " ~ ('eines weiteren' if peoplecount == 1 else 'weiterer') ~" Humanoiden erkannt. " ~ persons ~ (' wurde' if peoplecount == 1 else ' wurden') ~ " zu Hause identifiziert.",
            "Es sieht so aus als ob " ~ persons ~ " nun endlich wieder zu Hause " ~ ('ist' if peoplecount == 1 else 'sind') ~ "! Klasse.",
            "Ich verrate euch ein Geheimnis. " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " nun wieder zu Hause!",
            "Möge die Macht mit dir sein, " ~ persons ~ ". Willkommen zu Hause!",
            "E.T. Telefon Zuhause? Nein, " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " schon hier!",
            "Willkommen zurück, wir haben " ~ ('dich' if peoplecount == 1 else 'euch') ~ " erwartet, " ~ persons,
            ('Du kannst' if peoplecount == 1 else 'Ihr könnt') ~ " den Griff loslassen, " ~ persons ~ ". " ~ ('Du bist' if peoplecount == 1 else 'Ihr seid') ~ " zu Hause.",
            "Hasta la vista, Baby. Oh, warte, das ist, wenn du gehst. Willkommen zu Hause, " ~ persons ~ "!",
            "Willkommen im Batcave, " ~ persons ~ "!",
            "Nach Hause telefonieren? Keine Notwendigkeit, " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " schon hier!",
            "Keine Sorge, " ~ persons ~ ", wir haben hier keinen Löwenkönig namens Scar.",
            "Willkommen zurück in der Höhle, " ~ persons ~ ". Der Kessel steht auf dem Feuer.",
            "In einer Galaxie ganz nah, " ~ persons ~ " " ~ ('kehrt' if peoplecount == 1 else 'kehren') ~ " nach Hause zurück.",
            "Es ist kein Zaubertrick, " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " tatsächlich zu Hause!",
            "Ahoy, " ~ ('Matrose! ' if peoplecount == 1 else 'Matrosen! ') ~ persons ~ ", das Heimatland ist in Sicht.",
            "Beam mich hoch, " ~ persons ~ "! Oh, du " ~ ('bist' if peoplecount == 1 else 'seid') ~ " schon da.",
            "Kein Platz wie Zuhause, richtig, " ~ persons ~ "?",
            "Willkommen zurück am Heidbergdamm, " ~ persons ~ ".",
            ('Du hast' if peoplecount == 1 else 'Ihr habt') ~ " das Level abgeschlossen. Willkommen zu Hause, " ~ persons ~ "!",
            "Houston, wir haben kein Problem. " ~ persons ~ " " ~ ('ist' if peoplecount == 1 else 'sind') ~ " sicher gelandet.",
            "Hakuna Matata, " ~ persons ~ "! " ~ ('Fühle dich ' if peoplecount == 1 else 'Fühlt euch ') ~ "wie zu Hause.",
            "Das Glück der Erde liegt auf dem Rücken der Heimat, willkommen zurück " ~ persons ~ "!",
            "Sag Hallo zu " ~ ('meinem Freund ' if peoplecount == 1 else 'meinen Freunden ') ~ persons ~ "!",
            "Wie Alice im Wunderland, zurück im Reich der Wunder, nicht wahr, " ~ persons ~ "?",
            "Lass uns das Abenteuer zu Hause fortsetzen, " ~ persons ~ "!",
            "Gandalf's Weisheit: 'Zuhause ist jetzt hinter dir, das Abenteuer liegt vor dir.' Willkommen, " ~ persons ~ "!",
            ('Wie ein Jedi-Meister kehrt mein Freund ' if peoplecount == 1 else 'Wie Jedi-Meister kehren meine Freunde ') ~ persons ~ " nach vielen Kämpfen nach Hause zurück.",
            "Die Macht ist stark in unserem Zuhause. Willkommen zurück, " ~ persons ~ "!",
            "Wie Frodo und Sam nach Mordor, so " ~ ('kehrst auch du, ' if peoplecount == 1 else 'kehrt auch ihr ') ~ persons ~ ", zurück ins vertraute Land."
          ] | random }}
    - service: group.set
      data:
        object_id: "arriving"
        entities: []