5 Must Have Automations in Home Assistant


Getting started with home assistant is an exciting journey, there are many things that can be achieved with this open source automation platform. Lets look at 5 examples, you can find the code below and the linked Youtube video too:

To import this code in your home assistant you can either, copy & paste it in the automations.yaml file. Or you can go to automations, add new automation, 3 dots in the top right hand corner, switch to YAML, paste in the code and switch back to UI

Fridge is Open

This automation requires a Fridge, which hopefully most of us have 🙂

A door sensor and then some device that we can use to receive notifications, in my example I’m using my iPhone. For this to work you need to have home assistant app installed on the device.

Change the entity_id with the one in your system.

Feel free to customise the duration I have it set to 5 minutes. You can also personalise the message and title, try to experiment by changing some of the code.

alias: Fridge is Open
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fridge_door
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - service: notify.mobile_app_giordano_s_iphone_12
    data:
      message: The Fridge has been open for 5  minutes
      title: Keep me cool
mode: single

Welcome Home Automation

It is quite nice to be welcomed by the home, this is a simple version of the code required. It looks at a person that I have defined and we are looking for a state change from not_home to home. This code was automatically generated by the UI. I logically would put from first and to after, feel free to swap the code around. In the action section I’m using a tts (text to speech) service which I get thanks to my subscription to Nabu Casa (home assistant cloud). Switch the entity_id of the relevant speaker that you want to broadcast this message from.

alias: Welcome back home
description: ""
trigger:
  - platform: state
    entity_id:
      - person.gio
    to: home
    from: not_home
condition: []
action:
  - service: tts.cloud_say
    data:
      entity_id: media_player.leo_homepod
      message: Welcome Home
mode: single

Proximity to Home

This automation requires two steps, one proximity sensor that you need to create in the configuration.yaml and then the automation that uses that sensor.

With this automation you can track the distance between your device / person from a specific location. This can be useful to trigger some routines to turn on the heating or cooling as you get closer to home.

Configuration.yaml

The example below is tracking the proximity to my home zone and is using a certain device tracker linked to my iPhone and a tolerance number and unit of measurement.

proximity:
  home:
    devices:
      - device_tracker.giordano_s_iphone_12
    tolerance: 50
    unit_of_measurement: mi

Automation.yaml

I’m now looking at when the value of the distance goes under a certain value, for example 100 and that the direction of travel is towards, so you are getting closer to the zone and not further away.

The action is going to either / pre-heat or cool the home.

alias: Coming home - pre heating
description: ""
trigger:
  - platform: numeric_state
    entity_id: proximity.home
    below: 100
condition:
  - condition: state
    entity_id: proximity.home
    attribute: dir_of_travel
    state: towards
    for:
      hours: 0
      minutes: 1
      seconds: 0
action:
  - service: climate.set_temperature
    data:
      temperature: 18
    target:
      entity_id: climate.nest
mode: single

Turn OFF All Lights

This is as it says tries to turn off all lights that are on at a set time.

alias: Turn Off ALL the Lights
description: ""
trigger:
  - platform: time
    at: "02:00:00"
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - all
mode: single

Police are coming

This is a nice alarm feature to scare anyone that is inside your home with a loud message in a speaker.

alias: Police are on the way
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.kitchen_motion_2
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 10
  - platform: state
    entity_id:
      - binary_sensor.patio_doors
    from: "off"
    to: "on"
condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: armed_away
action:
  - service: tts.cloud_say
    data:
      entity_id: media_player.leo_homepod
      message: >-
        The police are on the way! The police are on the way! The police are on
        the way!  The police are on the way! The police are on the way!
mode: single

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts