Build a Home Assistant automation for a finished 3D print
Send a watch notification when a 3D print finishes, then switch off an extractor fan after a delay.

This walkthrough builds a Home Assistant automation that sends a notification to my Apple Watch when my 3D printer finishes, then turns off the extractor fan in the printing cupboard 15 minutes later.
Our Home Assistant introduction covers integrations and the main automation terms.
What you need
A working Home Assistant installation
All of your sensors and services added as integrations
The correct system time and timezone configured in Settings > System > General
Create and download a configuration backup before making changes:
Settings > System > Backups >Create Backup, Download that backup once created.
Choose an event and an action
Choose an event that should trigger a useful action, then decide which conditions must be true. Here are some examples:
Turn on the heating when the average room temperature drops below 18 degrees and someone is home.
At 7pm the evening before recycling collection, remind the people who are home to put the bins out.
When someone rings the doorbell, show the camera feed on the TV or a dashboard.
The same structure applies to each example: a trigger starts the automation, conditions decide whether it should continue, and actions carry out the work.
Contact us if you want help adapting an automation to your devices.
Create the automation
For this example, the printer is connected through OctoPrint. Its reported state will provide the trigger.
There are 2 main ways to begin creating your automation:
Settings > Automations and Scenes > Create Automation.
Settings > Devices and services > [your target device] > Create automation with device.
We will use option 2. My 3D printer is connected through OctoPrint, which reports its print state and job percentage to Home Assistant.

Choose the trigger
Select a starting point for your automation.
I opted for a state change in OctoPrint Current State.

Define the from and to values for the state change trigger.
My 3D printer state changes from Printing to Operational when the print is complete. You can require the new state to persist for a chosen period before triggering. That can help filter out brief state changes.

If you need to monitor two entity states, for example a second 3D printer sharing the same automation, you can add another trigger. If you start to do this, be mindful of actions taken based on only one of multiple triggers.
Add a condition
Add any conditions required for the automation to continue.
In this example, I only want the actions started by my automation to take place if I am home, so I create a condition Time and Location > Zone. I set my user as the entity and Home as the location. My user is linked to my watch and phone for location tracking. Home is a geofence location; you can set these up in Settings > Areas, Labels & Zones.

If you are running an up to date version of Home Assistant, you can test these conditions for pass or fail from inside the automation builder:

Define the actions
Add the notification first, then a 15-minute delay, then the action that turns off the extractor fan.
Create a notification action using Add Action > Notification > Send a notification via [device name]. It's also possible to send a notification to a group of named devices.
Define the message content and the title of the notification.
Add a 15 minute delay using a building block.
Home Assistant carries out actions in order. After the Apple Watch alert, add a delay using Add Building Block > Wait for time to pass and set it to 15 minutes.
Add our final action, turn off the extractor fan.
After the delay, turn off the extractor fan. Mine is connected to a mains socket through a mylocalbytes Tasmota plug. To change its power state to off, Add Action > Device > find device by name > set Action to Turn off [device name]:

Here is what our complete automation looks like in YAML format:
alias: Notify - OctoPrint Complete
description: ""
trigger:
- platform: state
entity_id:
- sensor.octoprint_current_state
from: Printing
to: Operational
condition:
- condition: zone
entity_id: person.tom
zone: zone.home
action:
- service: notify.mobile_app_tci13m
data:
message: 3D Print Complete
title: OctoPrint
- delay:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
- type: turn_off
device_id: b6e12e0ce3c9985e6f00c72756b40aed
entity_id: 64b67cf94fb67dc6297eec11699dde8b
domain: switch
mode: single
Test and debug the automation
Use the menu in the top right of the automation editor to run the automation manually or view its trace history. Traces visualise the stages of your automation and collect the log history.
Run the automation manually, then test it when the printer finishes a real job. Use the trace to check the trigger, condition and each action if it does not behave as expected.
