Trigger and action

On this page 7

Trigger and action is the basic building block of home automation: a trigger is the event that starts a rule, and an action is the command the system carries out in response. A motion sensor detecting movement at night is a trigger; turning on the hallway light at 30 percent brightness is the action. Most automation platforms add a third element, the condition, which must be true at the moment of the trigger for the actions to run.

The pattern is often described as when, if, then: when something happens, if the circumstances are right, then do something. Every smart home platform, from Apple Home and Google Home to Home Assistant, Samsung SmartThings and openHAB, expresses its automation rules in some version of this structure, even when the interface hides it behind templates or routines.

How triggers, conditions and actions work together

The three parts play distinct roles in an automation rule. The trigger is evaluated as an event, the condition is evaluated as a state, and the action changes the state of one or more devices. Confusing events with states is the most frequent design error in home automation.

PartQuestion it answersNatureExample
TriggerWhen should the rule startEvent at a momentFront door opens
ConditionShould it run right nowState that is true or falseNobody is at home
ActionWhat should happenCommand or sequenceSend a notification, turn on siren
The three parts of an automation rule

A trigger fires on a transition, for example when a door sensor changes from closed to open. A condition only checks the present situation, for example whether the sun has set. The rule time is the moment of the trigger, so if the condition becomes true later, the rule does not run retroactively.

Types of triggers

Triggers come from sensors, schedules, people and other systems. Choosing the right trigger type decides how reliable and how responsive an automation is.

Trigger typeSourceTypical useMain pitfall
Device state changeSensor, switch, lockLight on when door opensSensor battery or radio failure
Time-basedFixed time or sunrise and sunset offsetBlinds close at sunsetIgnores actual light conditions
PresencePhone location or occupancy sensorHeating on when first person arrivesLocation delays and false departures
ThresholdNumeric value crossing a limitFan on above 70 percent humidityRapid on and off near the limit
ManualSmart button, voice command, appGood-night routineUnclear what the button does
Common trigger types

Numeric thresholds need hysteresis or a delay to avoid flapping. A bathroom fan that starts above 70 percent humidity should stop only below a lower value, such as 60 percent, or after the reading has stayed low for several minutes.

Designing reliable actions

Actions range from a single device command to sequences with delays, scenes, notifications and calls to other services. Reliable action design starts with idempotent commands: setting a light to a specific brightness is safer than toggling it, because toggling produces the wrong result if the light was already on.

  • Use scenes for groups of states: a smart home scene applies many device settings in one action and is easier to maintain.
  • Add waits with timeouts: an action that waits for a door to close should give up after a defined time.
  • Plan for failure: critical actions such as closing a water valve should send a confirmation or an alert if the device does not respond.
  • Avoid loops: an action that changes a device should not trigger the same rule again.

Platforms also differ in how they handle a trigger that fires again while the rule is still running. Typical run modes are single, restart, queued and parallel. A motion light usually needs restart mode, so that each new movement resets the off timer instead of being ignored.

Trigger and action is the core pattern, but home automation platforms offer several related concepts that package it in different ways. Knowing the difference helps to choose the right tool in a given app.

ConceptHas its own triggerWhat it containsTypical use
Automation ruleYesTrigger, conditions, actionsReacting to events automatically
Smart home sceneNoA set of device statesMovie mode, dinner lighting
RoutineYes, often voice or timeSequence of actions and scenesMorning or good-night sequence
Time-based automationYes, time onlyActions at a set timeSchedules for heating or lights
Automation concepts and how they use triggers

Where rules run also matters. A rule that runs on a local hub reacts in well under a second and keeps working without internet, while a cloud rule may add one to several seconds and fails during outages. Safety-related automations should be placed on the local path whenever the platform allows it.

Common mistakes in automation logic

Most failed automations are not caused by hardware but by logic that does not match real life. Testing each rule in different situations, such as at night, with guests present or with a phone left at home, reveals these mismatches early.

MistakeSymptomFix
State used as triggerRule never fires or fires constantlyTrigger on the change, check state as condition
No off rule or timeoutLights stay on all nightAdd a no-motion trigger with a delay
Only phone presenceAlarm arms while someone is homeCombine with occupancy sensors
Overlapping rulesDevices switch back and forthOne rule per device purpose, clear priorities
Mistakes and how to fix them

A final best practice is to keep manual override possible. Every automated light, lock or blind should still respond to a wall switch or app, and a rule should not immediately undo a manual change made by a person in the room.

Understanding it simply

Trigger and action is a simple if this happens, then do that rule for the home. The trigger is the moment something happens, such as a door opening. The action is what the home does next, such as turning on a light.

Many rules also include a check in the middle, like a doorman asking a question before letting someone in: only after dark, or only when nobody is home. With a few such rules, the home starts doing small jobs on its own.

Applied in practice

A family wants the hallway light to help at night without waking anyone. They create a rule with a motion sensor as trigger, a condition that the time is between 23:00 and 06:00, and an action that sets the light to 10 percent warm white. A second trigger, no motion for two minutes, turns the light off.

The rule runs in restart mode on a local hub, so every new movement extends the light time, and it reacts in a fraction of a second even without internet. After a week, the family adds a condition that a manual override from the wall switch pauses the rule for one hour, which ends the frustration of lights switching off during a late conversation.