Photo by Emma Frances Logan / Unsplash

Coming Home to My Personal Symphony: The Magic of Smart Automation

Nov 4, 2023

Smart home technology has revolutionized the way we interact with our living spaces. It's not just about remote control anymore; it's about homes that anticipate our needs and respond to our presence. Today, I'm going to walk you through a sophisticated home automation setup that does just that, using Home Assistant, a powerful open-source home automation platform.

Things needed

To implement the "Ankommen" home automation as described, you would need a collection of smart devices and services that are compatible with Home Assistant. Here’s a list of the required devices and their purposes:

  1. Home Assistant: This is the central control system that runs the Home Assistant software. It can be a dedicated device like Home Assistant Blue, a Raspberry Pi, or any computer capable of running Home Assistant OS.
  2. Door Sensor: A smart door sensor like the Aqara Door and Window Sensor is needed to detect when the door is opened. This sensor should be compatible with Home Assistant.
  3. Occupancy Sensor: A sensor that can detect the presence of people in the home. This could be a motion sensor or a device that counts the number of people's smartphones connected to the Wi-Fi, like the 'sensor.people_home' mentioned in the automation.
  4. Smartphone with Home Assistant Mobile App: Florian's iPhone with the Home Assistant mobile app installed is required to receive notifications and potentially to track presence if the occupancy sensor is based on smartphone connections.
  5. Media Player with Spotify Integration: A media player that is compatible with Home Assistant and can be controlled via the platform. It should also support Spotify Connect, like a Sonos speaker (Sonos Ray is mentioned in the automation).
  6. Spotify Account: A Spotify Premium account is necessary to use Spotify Connect with your media players.
  7. Smart Switch/Device: A smart switch or any smart device that can be turned on or off via Home Assistant. This is the device that is controlled when the occupancy sensor is triggered.
  8. Wi-Fi Network: A reliable Wi-Fi network to connect all the devices and ensure they can communicate with the Home Assistant hub and the internet.
  9. Input Boolean for Guest Mode: This is not a physical device but a virtual switch within Home Assistant that represents the 'guest mode'. It can be toggled on or off manually or through other automations.
  10. Additional Configuration: Depending on the setup, you might need additional smart home integrations or devices to track the state of 'media_player.spotify_florian' and to control the playback on the Sonos Ray.

These devices and services work together to create the "Ankommen" automation, providing a seamless experience as someone arrives home. It's important to ensure that all devices are compatible with Home Assistant and that you have the necessary integrations installed within the Home Assistant platform to communicate with these devices.

Detailed Breakdown of the "Ankommen" Automation

Initial Setup

The "Ankommen" automation is configured within Home Assistant, which is a centralized hub for smart home devices and automations. This particular automation is designed to enhance the homecoming experience by integrating door sensors, occupancy sensors, media players, and notification services.

Triggers Explained

  1. Door Sensor Trigger:
    • Entity ID: binary_sensor.aqara_contact_wohnungstur_contact
    • State Change: From "on" (door closed) to "off" (door opened).
    • Duration: The door must remain open for at least 2 seconds to confirm entry and not just a quick door opening.
  2. Occupancy Sensor Trigger:
    • Entity ID: sensor.people_home
    • State Change: The sensor's count changes to "1", indicating the first person has arrived home.

These triggers are the events that initiate the automation. The door sensor is likely a magnetic contact sensor that detects when the door is opened, while the occupancy sensor keeps track of the number of people in the home.

Conditions for Precision

Before any action is taken, the automation checks if all the following conditions are satisfied:

  1. Guest Mode Check:
    • Entity ID: input_boolean.guestmode
    • State: Must be "off" to ensure that the automation only runs in a non-guest scenario.
  2. Music Source Verification:
    • Entity ID: media_player.spotify_florian
    • Attribute: Checks if the 'source' attribute is set to 'iPhone', which means Florian was listening to Spotify on his iPhone prior to arriving home.
  3. Playback State Confirmation:
    • Entity ID: media_player.spotify_florian
    • State: Must be 'playing', confirming that music is currently being streamed and can be transferred to another device.

These conditions ensure that the automation only proceeds when Florian is not entertaining guests, was listening to music on his iPhone, and the music is currently playing.

Actions in Detail

Depending on which trigger was activated, different actions are carried out:

  1. If Triggered by Occupancy Sensor:
    • Device Control: A specific device identified by its device_id is turned on. This could be a light, a fan, or any other smart device that should activate upon the first person arriving home.
  2. If Triggered by Door Sensor:
    • Notification: Florian's iPhone receives a personalized notification welcoming him home and informing him that his music will now play through the Sonos Ray speaker system.
    • Media Source Selection for Sonos Ray: The Sonos Ray speaker's input source is switched to 'Spotify Connect', preparing it to receive the music stream from Spotify.
    • Media Source Selection for Spotify: The Spotify media player is instructed to use the Sonos Ray as its output device, ensuring that the music Florian was enjoying on his iPhone continues through the home speaker system.
    • Playback: The Sonos Ray is commanded to start playing the music, picking up right where it left off on Florian's iPhone.

The Personalized Experience

The "Ankommen" automation is not just a set of triggered actions; it's a thoughtfully crafted experience that considers the user's context (listening to music on the iPhone) and transitions it into the home environment (playing through the Sonos Ray). It's a smart orchestration that makes coming home feel special and personalized.

Final Thoughts

By meticulously setting up triggers, conditions, and actions, the "Ankommen" automation exemplifies the potential of smart home technology to create environments that adapt to our lifestyles. It's a blend of convenience, comfort, and technology that makes the simple act of coming home a little more delightful.

You can find the automation on my GitHub Repository which holds all my personal homeassistant configuration.