Implementing house mode in your Home Assistant

One of the first things I did when starting up with Home Assistant was to create a solution for different house modes.

Basically I wanted to be able to put the house in different modes, and these modes should be a huge part of how we automate our house. For example how should our automations work when leaving the house or being away, and what about at night when we are sleeping?

I also chose to limit the amount of modes, so it wouldn’t be difficult to understand each. We ended up with four modes:

  • Home-mode
    This mode is used when at least one person is at home.
  • Away-mode
    This mode is set when nobody is at home.
  • Night-mode
    This mode is used when we go to bed, but we are at home.
  • Guest-mode
    This mode is used when we have guests in our home.

The thought is that when the last person leaves the house the house mode should switch directly to Away-mode, and when the house is in Away-mode and a person enters, it should switch directly to Home-mode. We have kids, so of course I also wanted to be able to overwrite the “automatically switch to away-mode” when the grown ups leave the house… you know, so the babysitter shouldn’t sit in the dark 😉

So how did I accomplish the house mode functionality?

Prerequisites

To get the full picture of this blog post, I recommend you to read the following blog posts before starting:

1. Creating helpers

Helpers are a bit like variabels in programming language, or even better, like data saved in a database. In this case I use them to store the current state of the house mode and if it should disable the auto away-mode. The state of each helper will be remember between restarts of Home Assistant.

I started by creating two helpers through the GUI in Home Assistant:

  • House Mode
    Helper Type: Dropdown
    Icon: mdi:home-circle-outline (but you can set the icon as you want)
    Options: Home, Away, Night & Guest

    Afterwards I clicked on the created helper and set the Entity ID to: input_select.housemode

  • Disable Auto Away-mode
    Helper Type: Toggle
    Icon: mdi:cloud-off-outline

    Afterwards I clicked on the created helper and set the Entity ID to: input_boolean.housemode_disable_auto_away_mode

You don’t need to change the Entity ID for the two helpers. I do it so it’s easy in Visual Studio Code to access the helpers, because they are related to the functionality (housemode).

2. Creating buttons in Lovelace

In my Lovelace view I always focus on making it easy to use with touch on our phones or on our tablets. Therefore I added 4 buttons in a grid with 2 columns. This way it’s easy to select each house mode from our devices. My idea was to make it look like this:

There are two ways of creating the buttons in Lovelace depending on your requirements of the look and feel.

2.1 The Standard Way

You can do it through 100 % standard Home Assistant components. In this case you create a Grid Card with 2 columns and add 4 buttons. These buttons I created with these properties:

Home

  • Name: Home
  • Icon: mdi:home
  • Tap Action: Call Service
  • Service: input_select.select_option
  • Target: Entity input_select.housemode
  • Option: Home

Night

  • Name: Night
  • Icon: mdi:weather-night
  • Tap Action: Call Service
  • Service: input_select.select_option
  • Target: Entity input_select.housemode
  • Option: Night

Away

  • Name: Away
  • Icon: mdi:home-export-outline
  • Tap Action: Call Service
  • Service: input_select.select_option
  • Target: Entity input_select.housemode
  • Option: Away

Guest

  • Name: Guest
  • Icon: mdi:party-popper
  • Tap Action: Call Service
  • Service: input_select.select_option
  • Target: Entity input_select.housemode
  • Option: Guest

It will work without problems, but I would have liked to be able to see which button is the current state. That is not possible with this method.

2.2 Using a custom”Button Card”

I have HACS installed (which I would recommend everyone to have). Through HACS I found and installed a custom button card. This card gives much more control of the button card, including the possibility of showing the state.

The GitHub repository for this button card is located here: GitHub – custom-cards/button-card

For each state I created a button – like mentioned in 2.1 – but based on this new custom card. There is no GUI setup of this card, so it needs to be done by YAML for each button. Below is an example on how I did it for the Home button.

This way the button will have the Active-state color as all other buttons/entities have in Lovelace. This solution is what I ended up with, because showing the state was and still is important for me.

3. Creating house mode automations

The main purpose of the house mode functionality is to automate different flows based on the state. I also wanted the house mode to update the state automatically based on specific scenarios, for example the last person leaving the house, or the first person coming home.

I therefore setup the following simple scenarios:

  • Home-mode
    When the first person in a group of persons comes home, I want the house mode to be set to Home.
  • Away-mode
    When the last person in a group of persons leaves home, I want the house mode to be set to Away.
  • Night-mode
    We set this manually when we go to sleep at night.
  • Guest-mode
    We set this manually when we have guests visiting us.

We use the Companion App (iOS Home Assistant app) and have it installed on our phones. We also granted permission to track our whereabouts and report back to Home Assistant. I therefore added our mobile phones to a group, so I could have a state on the group if someone is at home or if we’re “not at home”. Below you can see the YAML code for my group.

File: src/groups/phones.yaml:

Afterwards I created two automations – one for setting the house mode automatically to Home and one for setting the house mode automatically to Away. I don’t do anything else in these two automations.

I instead want separate the automations that triggers on state changes to the house mode, because I then will then use the same automation regardless if the state is changed based on the automatically update or the manual update. This removes double code/configuration in YAML.

Part of file: src/automations/housemode-home.yaml:

Part of file: src/automations/housemode-away.yaml:

Notice that I in the automation for setting the state to Away automatically also have a condition to check if that trigger is actually disabled based on the state of input_boolean.housemode_disable_auto_awaymode.

Afterwards I created two automations for when the house mode state is set for either Home or Away. When going into Home mode, I want the entrance light to turn on, and when going into Away mode I want all lights turn off.

Part of file: src/automations/housemode-home.yaml:

Part of file: src/automations/housemode-away.yaml:

Of course I also created automations to trigger when the state is set for Night and Guest mode, but above YAML configuration is shown as examples.

4. Using the house mode in other automations

In all other automations that you build, you can chose to use a specific state of the house mode as a condition too. This could for example be to disable motion triggers if the house mode is in Night mode.

You can do it by adding the following condition to your automation:

Examples of usage

Here are some examples on what we use the house mode functionality to do:

  • When we are leaving our home our vacuum robots starts a cleaning job (but only once a day).
  • When we arrive home and our vacuum robots are doing a cleaning job, they are send home to their base.
  • When in Night state we have perimeter protection in our house, activating voice on a Sonos speaker and sending us a notification on the mobile app if it registers any breach.
  • When in Away state we have perimeter protection in our house, sending us a notification on the mobile app if it registers any breach.
  • Selected lights are turned on when we are on Guest mode. It’s LED lights around the house we normally don’t use in our every day.

I hope this guide / walk-through is useable for you. We use the house mode in almost everything we do, and we are so happy about the functionality surrounding it.

13 thoughts on “Implementing house mode in your Home Assistant

    1. Hi Taylor,

      I just have a simple automation that triggers at a specific time in the morning, setting the housemode to Home, if one of us is home.

  1. Hi,
    I’m new to Home Assistant, migrating from a Vera Plus. I used the House Modes in Vera, and I’ve been searching for something like this. I’ve got as far as creating the button cards, but I’m already getting stuck with the groups. I tried going into helpers to create a group with for my users/iPhones, but I don’t see anything in there that will work. Additionally, I tried inserting your group code into my configuration.yaml file, and it’s throwing errors at me. I’m not getting how the !include works, because every attempt, I get a invalid config error.

    Any advice?

    1. Hi Tim,

      1. Create a file called /config/groups.yaml and add the phone’s code as per the instructions above.
      2. Go to /config/configurations.yaml file, and add the following line:
      group: !include groups.yaml

      Alternatively, skip step 1 and add the phone’s code directly into the configurations.yaml
      3. Go to Developer Tools and check the configuration.
      4. RESTART

      It should work. Mine did.

  2. Hi Kef and Taylor, what I used to do with hubitat and am now in the process of implementing with HA for the transition from night to home is: in the morning (anytime after 5am), as soon as someone turns on a light in the main living space, a condition checks time and home status and if status is night and time is after 5 am, the automation will switch mode to home. This permits us to sleep in… If no one touched a switch, it will automatically change to home at 2 hours past sunrise (same time some lights turn off)

  3. Hi Kef,

    Great article – thank you for taking the time to post this. I need a little help with the “custom: button-card” as there are not firing/updating the input_select.housemode status. Any suggestions as to what I’m doing wrong?

    Kindest Regards
    John

    1. Hi John,

      I have no suggestion. You need to share some code and knowledge around the solution you are doing.

      If you follow my guide 100% it would work, so I would recommend you trying to this at first and then build on top of my solution.

      Best regards,
      Kristian

    1. Sorry, did not read well enough:
      House Mode
      Helper Type: Dropdown
      Icon: mdi:home-circle-outline (but you can set the icon as you want)
      Options: Home, Away, Night & Guest

Leave a Reply to Mike Cancel reply

Your email address will not be published. Required fields are marked *