Guides

Home Assistant automations to copy

Eight automations for Home Assistant you can copy and adapt. In Home Assistant, create a new automation (Settings → Automations & Scenes → Create Automation), choose Start from scratch, click the three dots in the top right and choose Edit in YAML. Paste the code and replace the entity names with your own.

Before you start

  • These examples use the syntax of recent versions (from Home Assistant 2024.10 onwards, with triggers, actions and action:). If you have an older version, update first or adjust the names.
  • The names like binary_sensor.beweging_gang are examples. Look up your own names under Settings → Devices & Services → Entities.
  • Test each automation after saving with the Run button or by simulating the situation.

1. Hallway light on motion after sunset

The light turns on when motion is detected, and turns off three minutes after motion stops.

alias: Hallway - light on motion
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.beweging_gang
    to: "on"
    id: aan
  - trigger: state
    entity_id: binary_sensor.beweging_gang
    to: "off"
    for: "00:03:00"
    id: uit
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: aan
          - condition: sun
            after: sunset
        sequence:
          - action: light.turn_on
            target:
              entity_id: light.gang
      - conditions:
          - condition: trigger
            id: uit
        sequence:
          - action: light.turn_off
            target:
              entity_id: light.gang

2. Notification when the front door is open too long

alias: Front door open too long
triggers:
  - trigger: state
    entity_id: binary_sensor.voordeur
    to: "on"
    for: "00:05:00"
actions:
  - action: notify.mobile_app_your_phone
    data:
      title: "Door is open"
      message: "The front door has been open for 5 minutes."

Replace your_phone with the name of your phone in the Home Assistant app; you can find the name under Developer Tools → Actions.

3. Notification when the washing machine is done

Works with a smart plug that measures power. The notification comes when consumption drops below 3 watts and stays there for three minutes.

alias: Washing machine done
triggers:
  - trigger: numeric_state
    entity_id: sensor.wasmachine_vermogen
    below: 3
    for: "00:03:00"
actions:
  - action: notify.mobile_app_your_phone
    data:
      message: "The washing machine is done."

4. Turn everything off when everyone leaves

alias: Everyone away - lights off
triggers:
  - trigger: numeric_state
    entity_id: zone.home
    below: 1
actions:
  - action: light.turn_off
    target:
      entity_id: all

For this to work, Home Assistant needs to know who is home, for example through phones with the Home Assistant app.

5. Notification for a nearly empty battery

alias: Battery nearly empty
triggers:
  - trigger: numeric_state
    entity_id: sensor.beweging_gang_batterij
    below: 15
actions:
  - action: notify.mobile_app_your_phone
    data:
      message: "The battery of the motion sensor in the hallway is nearly empty."

6. Turn heating off when a window is open

alias: Heating off when window open
triggers:
  - trigger: state
    entity_id: binary_sensor.raam_woonkamer
    to: "on"
    for: "00:02:00"
actions:
  - action: climate.turn_off
    target:
      entity_id: climate.woonkamer

Want the heating to turn back on when the window closes? Create a second automation with to: "off" and climate.turn_on.

7. Dim and warm up the light in the evening

alias: Living room - evening light
triggers:
  - trigger: time
    at: "21:00:00"
actions:
  - action: light.turn_on
    target:
      entity_id: light.woonkamer
    data:
      brightness_pct: 40
      color_temp_kelvin: 2700

8. Water leak: notification and shut off valve

alias: Water leak
triggers:
  - trigger: state
    entity_id: binary_sensor.waterlek_keuken
    to: "on"
actions:
  - action: switch.turn_off
    target:
      entity_id: switch.hoofdkraan
  - action: notify.mobile_app_your_phone
    data:
      title: "Water leak!"
      message: "The water leak detector in the kitchen has been triggered. The main valve has been shut off."

Only do this with a valve you can safely shut off automatically, and test it without depending on the automation for your safety.

Tips

  • Keep automations small and give them a clear name. This makes troubleshooting easier.
  • See that an automation doesn’t start? Check under Settings → Automations → (the automation) → Traces to find out why.
  • Find more ideas in our tips and tricks, and for custom sensors you can connect to such automations in the ESPHome guide.

Sources and attribution

This article was written in our own words. The syntax follows the Home Assistant documentation: