Homelab the Right Way

Home › Posts

New book: Automations That Just Work (Home Assistant without the surprises)

Book 6 in the Homelab the Right Way series is out: reliable Home Assistant, from Zigbee coordinator placement to automations you can read a year later and a monthly update hour with a way back. Here is the motion-light automation from Chapter 4, done properly, and the one Zigbee change that fixes most dropped sensors.

· 4 min read · home assistantzigbeez-waveautomationsebookhomelab

New book: Automations That Just Work (Home Assistant without the surprises)

Book 6 in the series is out today: Automations That Just Work: Reliable Home Assistant with Zigbee, Z-Wave, Dashboards and Updates That Don't Break Things. It is 56 pages and 23 diagrams on the second six months of a Home Assistant install, the part where the magic has worn off and the family has stopped trusting the house.

The free sample is the whole of Chapter 4, the automations chapter. Here is a taste of what is in it, plus the Zigbee fix from Chapter 2 that most people need first.

The trap: a motion light that turns off while you are still there

The usual motion light has a motion trigger, a "turn on", a fixed two-minute delay, and a "turn off". It works most nights. Then someone stands still in the hallway reading a label and the light goes out on them.

The reason is the automation's mode. The default, single, means that when motion fires again while the first run is still waiting out its delay, the second trigger is silently dropped (there is a warning in the log, which nobody reads). The countdown that started on the first motion keeps running, and the light goes off two minutes after the first movement, not the last.

The fix: restart and a wait, not a delay

Two changes. Set the mode to restart, so fresh motion cancels the running countdown and starts over. And wait for the sensor to be off for two minutes instead of sleeping for two minutes:

alias: Hallway light on motion
description: On with motion after dark; off 2 min after motion stops
mode: restart
triggers:
  - trigger: state
    entity_id: binary_sensor.hallway_motion
    to: "on"
conditions:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
actions:
  - action: light.turn_on
    target:
      entity_id: light.hallway_ceiling
    data:
      brightness_pct: 60
  - wait_for_trigger:
      - trigger: state
        entity_id: binary_sensor.hallway_motion
        to: "off"
        for: "00:02:00"
  - action: light.turn_off
    target:
      entity_id: light.hallway_ceiling

Every new motion restarts the run, so the light only goes off two minutes after the last movement ends. The for: on the wait also absorbs a sensor that flaps on and off within a second.

Three more rules from the chapter that keep automations readable:

  • Every state trigger gets a to:. Without it, the automation fires on any change, including attribute updates like brightness or last_seen, and runs twenty times an hour.
  • Flappy sensors get for: on the trigger. A door that reports open, closed, open within a second fires three times without it and zero times with for: "00:00:05".
  • When an automation "didn't work", read its trace (Settings, Automations & Scenes, the automation, three-dot menu, Traces) before changing anything. It shows which trigger fired, what every condition evaluated to, and what each action did. Guessing is slower than reading.

The Zigbee fix that comes first

Most "the bedroom sensor dropped again" problems are not the sensor. They are the coordinator stick plugged straight into a USB 3.0 port on the server, inside a metal case, next to the access point. USB 3.0 ports and cables radiate noise in the 2.4 GHz band, which is exactly where Zigbee lives.

The fix is a USB 2.0 extension cable, one to two metres long, with the stick on the end of it, a metre away from any SSD, hub or access point. If the machine has a USB 2.0 port, use that. This single change fixes more Zigbee networks than any setting. The chapter goes on to the channel choice (Zigbee 15, 20 or 25, between Wi-Fi channels 1, 6 and 11, chosen before pairing anything), why battery sensors never route and a mains plug in each room is the mesh, and pairing devices in the room they will live in.

What the book covers

  1. A home that works when the internet doesn't: the five-minute WAN unplug test, one naming scheme, areas and labels
  2. Zigbee that stays up: coordinator choice and placement, channels, ZHA or Zigbee2MQTT, routers, a working Zigbee2MQTT configuration
  3. Z-Wave without the mystery: 800-series controllers, Z-Wave JS UI, S2 inclusion, node statistics instead of nightly heals
  4. Automations that mean something: triggers, conditions, modes, the motion light, traces (the free sample chapter)
  5. Helpers, templates and blueprints: house mode and guest mode, template sensors with defaults, a motion-light blueprint
  6. Dashboards people actually use: phone, wall tablet and admin; Sections and tiles; conditional cards
  7. Notifications that don't cry wolf: tags, actionable alerts, one daily battery report, quiet hours, the alert integration
  8. Updates without breaking things: the monthly routine, backup plus Proxmox snapshot, one layer at a time, three ways back

Plus the Weekend Reliability Checklist and a cheat sheet. PDF and EPUB, with the full automations chapter free below.

Checklist

  • Motion lights on mode: restart with a wait_for_trigger, not a fixed delay
  • Every state trigger has a to:; flappy sensors have for:
  • Coordinator on a USB 2.0 extension cable, away from the case and the access point
  • Zigbee on channel 15, 20 or 25, set before pairing
  • A mains-powered router in each room between the coordinator and the far sensors

More articles