Rules, Timers and Schedules
The most underrated sentence in Tasmota's
documentation is the one that says the
automation lives on the device. A hub
is a single point of failure with a nice
interface; a rule stored in a plug's own
flash keeps working when the hub is
rebooting, the Wi-Fi controller is sulking,
or the internet is down. This chapter
covers the three mechanisms, in the order
you will reach for them. The syntax and
examples follow the official Rules
documentation, cross-checked against the
rule engine's own header comments in
xdrv_10_rules.ino, where the project's
canonical examples live.
Rules: when this, do that
A rule is one line with a strict shape — note the mandatory spaces, which the documentation warns about because everyone trips on them once:
ON <trigger> DO <commands> ENDON
Triggers name the device's own state,
written the way it appears in its JSON,
joined with #, optionally with a
comparison:
on System#Boot do Color 001000 endon
on Energy#Power>100 do Power2 OFF endon
on INA219#Current>0.100 do Backlog Dimmer 10;Color 100000 endon
on Switch1#State=1 do Power1 TOGGLE endon
The trigger vocabulary is wide: system
events (System#Boot, Mqtt#Connected,
Wifi#Connected), time (Time#Minute,
Time#Initialized), buttons and switches,
every relay, every sensor reading, rule
timers expiring, and — with a Tele-
prefix — "only when the telemetry is
published" rather than at every change.
Comparisons include the numeric set
(>, <, >=, <=, =, !=) and
string operators; the matched value is
available inside the action as %value%.
Devices hold three rule sets
(Rule1–Rule3), each roughly a thousand
plus characters, stored compressed in
flash and — a thoughtful detail — disabled
automatically if the device detects it is
boot-looping, so a bad rule cannot brick a
plug in a wall. Variables come in two
flavours: Var1–Var16, which reset at
reboot, and Mem1–Mem16, which persist.
With triggers, variables and Backlog, most
"clever plug" behaviour — staircase timers,
bathroom-fan run-on, pump protection,
motion-follow lighting — is a line or two.
Timers: the clock-driven sixteen
Separately from rules, a device has 16
timers (the constant MAX_TIMERS in the
source is 16), configured from the web
interface's Timers page or by command. Each
can fire at a set time on chosen weekdays,
at sunrise or sunset (the device knows
both once you give it a location), once or
repeating, and run any command. "Porch
light on at sunset, off at 23:30" is two
timers and no rules at all.
Which mechanism when
Timers for clock times; rules for reactions ("when X happens"); Backlog inside either for sequences. Reach for a hub's automation instead when the decision needs information from other devices — "when nobody is home" is a house-level fact, and a plug cannot know it. Local rules and hub rules are complements, not rivals: put the fast, dumb, must-not-fail logic on the device, and the judgement calls on the hub.