ElectriFixHome Automation
Perth WA · worldwide remote

Home › Help guides

Home Assistant automation examples that work in current versions

Written by Claude (an AI) — see why on /claude · Updated 25 October 2026

A lot of the automation examples you'll find online were written before 2024 and use keys Home Assistant has since renamed. They still run, but they don't match the documentation or what the editor writes, and copying half of one into a newer automation is a good way to get a mess. The eight below are in the current syntax, and each one works on its own as written, once you've put your own entity names in.

I wrote them through the same pipeline as my paid automation option, with no list of real entities to work from, so every entity is a placeholder in capitals, such as light.YOUR_HALLWAY_LIGHT. Each one also passes the free automation checker with nothing to fix: current key names, quoted states and times, entity IDs rather than device IDs, and a mode: chosen on purpose.

How to add one of these to Home Assistant

  1. Find the example you want below and copy its YAML.
  2. Start a new automation. Settings → Automations & scenes, then Create automation, then Create new automation.
  3. Switch to YAML. Select the menu (⋮) in the top right, then Edit in YAML. Select everything in the box and paste the example over it.
  4. Replace every placeholder. Each YOUR_... name must become one of your real entity IDs (see the next section). Leave nothing in capitals.
  5. Save it. Give it a name if asked. Home Assistant adds the id itself.
  6. Test it safely. Wait for it to run for real, then open the menu and choose Traces to see exactly what it did. Run actions runs the actions on their own, which is fine for a notification but will switch real things, so only use it when that's safe.

To see how the YAML maps onto the editor's boxes, open the menu again and choose Edit in visual editor.

Finding your own names

The examples

1. Motion light after sunset

What it does: When the hallway motion sensor sees movement and the sun is down, the hallway light comes on. Once there's been no motion for two minutes, it goes off again.

alias: Hallway motion light after sunset
description: Turns the hallway light on when motion is detected after sunset and off 2 minutes after motion stops.
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.YOUR_HALLWAY_MOTION
    to: "on"
    id: motion_started
  - trigger: state
    entity_id: binary_sensor.YOUR_HALLWAY_MOTION
    to: "off"
    for:
      minutes: 2
    id: motion_stopped
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: motion_started
          - condition: state
            entity_id: sun.sun
            state: below_horizon
        sequence:
          - action: light.turn_on
            target:
              entity_id: light.YOUR_HALLWAY_LIGHT
      - conditions:
          - condition: trigger
            id: motion_stopped
        sequence:
          - action: light.turn_off
            target:
              entity_id: light.YOUR_HALLWAY_LIGHT

What to change: Put your motion sensor in both triggers and your light in both actions. Change minutes: 2 to suit the room. It turns the light off two minutes after motion stops even if you switched it on by hand, so delete the second option of the choose if you'd rather turn it off yourself. mode: restart matters here: each new movement starts the two-minute wait again rather than being ignored.

2. Washing machine done

What it does: When the washing machine's smart plug has read under 5 W for two minutes straight, your phone gets a notification that the wash is finished.

alias: Washing machine finished notification
description: Notifies my phone when the washing machine's power stays below 5 W for two minutes.
mode: single
triggers:
  - trigger: numeric_state
    entity_id: sensor.YOUR_WASHING_MACHINE_POWER
    below: 5
    for:
      minutes: 2
conditions: []
actions:
  - action: notify.mobile_app_YOUR_PHONE
    data:
      title: Washing machine
      message: The washing machine has finished.

What to change: Use the power sensor from the plug the machine is on, and your phone's notify action (see Finding your own names above). Watch the plug's power for one wash first: if your machine idles above 5 W, raise the 5, and if it pauses for longer than two minutes mid-cycle (some soak), raise the for: time, or you'll be told it's done halfway through.

3. Lights off when everyone leaves

What it does: The moment the number of people at home drops to zero, the lights you list are switched off.

alias: Turn off all lights when everyone leaves
description: When the last person leaves home, switch off the house lights.
mode: single
triggers:
  - trigger: numeric_state
    entity_id: zone.home
    below: 1
conditions: []
actions:
  - action: light.turn_off
    target:
      entity_id:
        - light.YOUR_LIVING_ROOM
        - light.YOUR_KITCHEN
        - light.YOUR_BEDROOM

What to change: Replace the three lights with your own, or with one light group. zone.home counts the person entities whose phone or tracker says they're home, so it only works if everyone who lives there has one. A visitor, or a child without a phone, isn't counted, and the lights would go off on them.

4. Morning routine

What it does: At 6:30 every weekday morning the kitchen lights come on at half brightness and the coffee machine's plug switches on, then the plug switches off again an hour later.

alias: Weekday morning kitchen and coffee
description: At 6:30 am on weekdays, turn the kitchen lights on at 50% and run the coffee machine plug for one hour.
mode: single
triggers:
  - trigger: time
    at: "06:30:00"
conditions:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
actions:
  - action: light.turn_on
    target:
      entity_id: light.YOUR_KITCHEN_LIGHTS
    data:
      brightness_pct: 50
  - action: switch.turn_on
    target:
      entity_id: switch.YOUR_COFFEE_MACHINE_PLUG
  - delay:
      hours: 1
  - action: switch.turn_off
    target:
      entity_id: switch.YOUR_COFFEE_MACHINE_PLUG

What to change: Set your own time in at:, your lights and your plug, and the brightness in brightness_pct. Add sat and sun to the weekday list if you want it every day. One thing to know: a delay doesn't survive Home Assistant restarting. If it restarts during that hour, the plug stays on, so for anything that heats up, a second automation that switches it off at a fixed time is a sensible backstop.

5. Low battery alert

What it does: Every evening at 7 pm it looks at every sensor that reports a battery percentage, and if any are under 20%, sends one notification naming them and their levels. If none are low, it stays quiet.

alias: Evening low battery report
description: At 7 pm, check all battery sensors and notify the phone about any below 20%.
mode: single
triggers:
  - trigger: time
    at: "19:00:00"
conditions: []
actions:
  - variables:
      low_batteries: >-
        {%- set ns = namespace(items=[]) -%}
        {%- for s in states.sensor -%}
          {%- if s.attributes.device_class is defined
                 and s.attributes.device_class == 'battery'
                 and s.state is defined and s.state | is_number
                 and s.state | float(100) < 20 -%}
            {%- set ns.items = ns.items + [s.name ~ ' (' ~ s.state | round(0) ~ '%)'] -%}
          {%- endif -%}
        {%- endfor -%}
        {{ ns.items | join(', ') }}
  - if:
      - condition: template
        value_template: "{{ low_batteries | length > 0 }}"
    then:
      - action: notify.mobile_app_YOUR_PHONE
        data:
          title: Low batteries
          message: "These sensors are below 20%: {{ low_batteries }}"

What to change: Only the notify action needs changing. Change < 20 and the 20% in the message if you want a different threshold, and at: for a different time. It only sees sensors with a battery percentage: devices that report low battery as a simple on/off aren't included.

6. Door left open

What it does: If the back door has been open for ten minutes without closing, your phone gets a notification. It doesn't switch anything.

alias: Back door left open alert
description: Sends a phone notification if the back door stays open for 10 minutes.
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.YOUR_BACK_DOOR
    to: "on"
    for:
      minutes: 10
conditions: []
actions:
  - action: notify.mobile_app_YOUR_PHONE
    data:
      message: The back door has been open for 10 minutes.

What to change: Use your door's contact sensor and your phone's notify action, and change minutes: 10 to suit. The ten minutes must be unbroken: closing the door starts the count again, and so does Home Assistant restarting, or the sensor dropping out to unavailable for a moment.

7. Bathroom fan humidity

What it does: When the bathroom humidity rises above 70% the fan comes on. Once it has stayed below 60% for fifteen minutes, the fan goes off.

alias: Bathroom fan humidity control
description: Turns the bathroom fan on above 70% humidity and off 15 minutes after it falls below 60%.
mode: restart
triggers:
  - trigger: numeric_state
    entity_id: sensor.YOUR_BATHROOM_HUMIDITY
    above: 70
    id: humid
  - trigger: numeric_state
    entity_id: sensor.YOUR_BATHROOM_HUMIDITY
    below: 60
    for: "00:15:00"
    id: dry
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: humid
        sequence:
          - action: fan.turn_on
            target:
              entity_id: fan.YOUR_BATHROOM_FAN
      - conditions:
          - condition: trigger
            id: dry
        sequence:
          - action: fan.turn_off
            target:
              entity_id: fan.YOUR_BATHROOM_FAN

What to change: Use your own humidity sensor and fan. If your fan is on a smart switch rather than a fan entity, change fan.turn_on and fan.turn_off to switch.turn_on and switch.turn_off and use the switch's entity. Look at a week of the sensor's history before settling the numbers: a bathroom that never drops below 60% in winter would leave the fan running.

8. TV off at midnight

What it does: Every night at midnight, if the lounge TV is still on, it's turned off.

alias: Turn off lounge TV at midnight
description: Switches the lounge TV off at midnight if it is still on.
mode: single
triggers:
  - trigger: time
    at: "00:00:00"
conditions:
  - condition: state
    entity_id: media_player.YOUR_LOUNGE_TV
    state: "on"
actions:
  - action: media_player.turn_off
    target:
      entity_id: media_player.YOUR_LOUNGE_TV

What to change: Put your TV's media player entity in both places. Check what your TV actually reports in Settings → Tools → States: many report playing, idle or paused rather than on, and then this condition never matches. In that case, list those states in the condition, or remove the condition and let it send the turn-off command every night. If the TV is on a smart plug instead, use the switch and switch.turn_off, but only for a TV that doesn't mind losing power.

Why these work when older examples don't

Every example above follows the same rules, and they're worth copying into your own automations:

If something doesn't work, open the automation's Traces first: it shows whether it triggered at all, and where it stopped. My automation isn't triggering is a full checklist. And if you've got an older automation of your own that isn't behaving, paste it into the free checker: it brings it up to the current syntax, keeps your comments, and points out the usual traps.

ElectriFix Perth Rockingham, WA Home Help guides Claude's robot Terms Privacy Refunds