Alexa "I'm Home"... well sort of

This started from a need to control my Schlage Encode WiFi lock which is not supported by HA. I have Alexa integrated and it does support the lock, works quite well actually. Problem is Alexa has no way to track presence so I could not tell it to lock up if nobody was home just in case we forgot.

So how did I trick Alexa… with a binary sensor.

I have “People” in the configuration menu configured with device trackers for both my wife and I. I used the “person.name” entities it creates to create the sensor.

binary_sensor:
  - platform: template
    sensors:
      people_home:
        value_template: >-
          {{ is_state('person.faith', 'home')
             or is_state('person.vinny', 'home') }}

This creates an entity called “binary_sensor.people_home”. Problem is Alexa will not recognize this as it is so another change. From the configuration menu all the way at the bottom using “Customizations” you need to change the “binary_sensor.people_home” device class to “window”… I know sounds crazy but you can now present it to Alexa and it knows what a window is… “Closed or Open” = “Home or Not Home”

From there Alexa now knows if we are or are not home. Because I only created one sensor with both people it needs us both to be home or gone for a state change, but that was all I needed. You can create individual sensors if you need to. From there I was able to write an Alexa routine to lock up for me in case we forgot but I’m sure there are a lot of other possibilities this can be used for.

1 Like

Do you want when you’re come home Alexa will greet you?

If so, I created 2 input_booleans:

kay_home_manual:
  name: "Kay"
  initial: on

peter_home_manual:
  name: "Peter"
  initial: on

Then 2 automations. When device_trackers are on then turn on the input_boolean.
(When 1 device_tracker become offline I’m still at home. Otherwise all are off.

#   _____ _____ __ __    __    _____ _____ _____      _    _____ _____ _____ _____ _____ _____
#  |  |  |  _  |  |  |  |  |  |   __|   __|_   _|    / |  |  _  | __  | __  |     |  |  |   __|
#  |    -|     |_   _|  |  |__|   __|   __| | |     / /   |     |    -|    -|-   -|  |  |   __|
#  |__|__|__|__| |_|    |_____|_____|__|    |_|    |_/    |__|__|__|__|__|__|_____|\___/|_____|
###########################################################################################
# SYSTEM WHEN AUTOMATION TRACKER NOT WORK WE CAN MANUAL TURN ON OFF OF KAY IS AT HOME OR NOT
###########################################################################################
###########################################################################################
- id: "arrive_left_kay_manual"
  alias: "System - Kay Left or Arrive Locative or GeoFency Manual"
  trigger:
    - platform: state
      entity_id:
        - device_tracker.e7b5aad4_fc4c_4ee8_98fd_2337da788a0f
        - device_tracker.kay_iphone_geofency

  action:
    - service: "{{ 'input_boolean.turn_on' if trigger.to_state.state == 'home' else 'input_boolean.turn_off' }}"
      entity_id: input_boolean.kay_home_manual

Here it create a group that will be used in the automation later on to greets 1 of 2 or both persons:

#   _____ _____ _____ _____ _____ _____    _____ _____ _____ _____ _____ _____    _____ _____ _____ _____ _____
#  |     | __  |   __|  _  |_   _|   __|  |  _  | __  | __  |     |  |  |   __|  |   __| __  |     |  |  |  _  |
#  |   --|    -|   __|     | | | |   __|  |     |    -|    -|-   -|  |  |   __|  |  |  |    -|  |  |  |  |   __|
#  |_____|__|__|_____|__|__| |_| |_____|  |__|__|__|__|__|__|_____|\___/|_____|  |_____|__|__|_____|_____|__|
###########################################################################################
# CREATE A GROUP.ARRIVING for "Notify - Greets People Home" automation
###########################################################################################
###########################################################################################
- id: "create_arrive_group"
  alias: "System - Create group.arriving for Greetings People Engine"
  trigger:
    - platform: state
      entity_id:
        - input_boolean.kay_home_manual
        - input_boolean.peter_home_manual
      from: "off"
      to: "on"

  action:
    - service: group.set
      data:
        object_id: "arriving"
        add_entities: "{{ trigger.to_state.entity_id }}"

- id: "arrive_left_peter_manual"
  alias: "System - Peter Left or Arrive Locative or GeoFency Manual"
  trigger:
    - platform: state
      entity_id:
        device_tracker.peter_iphone_ios_app
        # - device_tracker.1717fe36_3c70_4599_963c_b70b6ee95eba
        # - device_tracker.peter_iphone_geofency

  action:
    - service: "{{ 'input_boolean.turn_on' if trigger.to_state.state == 'home' else 'input_boolean.turn_off' }}"
      entity_id: input_boolean.peter_home_manual

    - choose:
        - conditions:
            - condition: state
              entity_id: input_boolean.kay_home_manual
              state: "on"
          sequence:
            - service: script.none

This will use group to see if 1 person or 2 persons went home… and Alexa will greet us in person or both

#   _____ _____ _____ _____ _____ _____    _____ _____ _____ _____ _____ _____
#  |  _  |   __| __  |   __|     |   | |  |  _  | __  | __  |     |  |  |   __|
#  |   __|   __|    -|__   |  |  | | | |  |     |    -|    -|-   -|  |  |   __|
#  |__|  |_____|__|__|_____|_____|_|___|  |__|__|__|__|__|__|_____|\___/|_____|
###########################################################################################
# NOTIFY and GREETS PERSON WHO WENT HOME
###########################################################################################
- id: "notify_me_when_person_arrived"
  alias: "Notification - Greets People Home"
  trigger:
    - platform: state
      entity_id:
        - input_boolean.peter_home_manual
        - input_boolean.kay_home_manual
      from: "off"
      to: "on"

  action:
    - wait_template: "{{ is_state('binary_sensor.fibaro_door_window_sensor_2_access_control_window_door_is_open_2', 'on') }}" # Frontdoor Sensor
    # wait 10 seconds when the frontdoor went open
    - delay: "00:00:10"

      ###########################################################################################
      # GROUP.ARRIVING is created in create_arrive_group.yaml
      ###########################################################################################
    - service: "{{ 'script.engine_say' if states.media_player.peter_s_2nd_echo_dot.state is defined else 'script.none' }}"
      data:
        personarriving: >-
          {% set person = expand('group.arriving')|map(attribute='name')|join(' and ') %}
          {% set peoplecount = expand('group.arriving') | count %}
          {% if peoplecount == 1 %}
            {% set is_are = ' is ' %}
          {% else %}
            {% set is_are = ' are ' %}
          {% endif %}

          {%- macro greeting_sentence(person, is_are) -%}
          {{ [
            "Welcome back home " ~ person,
            "You had me at hello " ~ person,
            "Guess who is home? " ~ person ~ is_are ,
            "The wifi just got a little more crowded.  Welcome Home " ~ person,
            "Welcome Home " ~ person + ".  We have missed you. Or at least Molly did.",
            "Our home is now complete, Rest your head and relax your feet! Welcome Back " ~ person,
            "Life is like a song, you’re back where you belong. Welcome home " ~ person,
            "Hey there " ~ person + " Welcome Home!",
            "Knock Knock. Who is There? "   ~ person  ~ is_are ,
            "The front door just told me that " ~ person  ~ is_are +" home.",
            "I know a secret! "  ~ person  ~ is_are +" home!",
            "Hey "  ~ person +". Your arrival has been recorded by the Smartest house on the block.",
            "Take note Molly! "  ~ person  ~ is_are +" home.",
            "I am sensing a disturbance in the force. "  ~ person +" must be home!",
            "And the house becomes a home. Welcome back " ~ person,
            "Just a quick announcement. " ~ person +" has arrived!",
            "Hey " ~ person + "! High Five! Glad you are finally home.",
            "Pardon the interruption but " ~ person ~ is_are +" home!",
            "My systems are picking up the presence of additional humans. " ~ person  ~ is_are +" being identified as home.",
            "Welcome home "~person + "! It is nice to see you again!",
            "It looks like "~person ~ is_are + " finally home! I will get the house ready for you. ",
            person  ~ is_are + " now in the house.",
            person + " can not hide from the system. Welcome home.",
            person ~ "! You are home!",
            person  ~ is_are + " now here.  Hash tag Welcome Home.",
            person  ~ is_are + " now here.  Hash tag Home.",
            person  ~ is_are + " now here.  Hash tag Smart Home."
          ] | random }}
          {%- endmacro -%}
          {{greeting_sentence(person, is_are)}}

    - service: group.set
      data:
        object_id: "arriving"
        entities: []
2 Likes

That’s pretty good… :grinning: