Something will go wrong. That's not bad luck — it's the normal state of programming. The difference between people who give up and people with working smart homes is mostly how they read the situation. This chapter is that skill: the log, the checker, the debugger, and where to ask.
Every QuickApp writes a log, and flua shows it in the terminal. The lamp
already logs with print(...) — and every line has a shape worth reading:
[04.10.2026][18:30:00][DEBUG ][SunsetLamp5000]: Lamp on
04.10.2026 18:30:00 — when it happened (virtual time — remember
--start from chapter 04).DEBUG — the log level, how loud the line is.SunsetLamp5000 — which QuickApp said it (name + id).Lamp on — the message.There are four levels, in order of loudness:
[TRACE ] quiet details, mostly for your future self
[DEBUG ] the normal level — print(...) writes here
[WARNING] "this is odd, but I'll keep going"
[ERROR ] "something failed"
print("Lamp on") is shorthand for fibaro.debug with the QA's own tag —
and you can pick a level explicitly: fibaro.trace, fibaro.debug,
fibaro.warning, fibaro.error. Most QuickApps live on debug and reach
for warning/error when something genuinely failed. When in doubt, log
more — you can delete lines later; you can't read a log you never wrote.
Errors come in two flavors. You've met both:
At startup (the file never really ran):
Error: hello.lua:4: attempt to perform arithmetic on a nil value (global 'nn')
flua names the file, the line, and the problem — here, arithmetic on
nn, which doesn't exist. The fix lives on exactly that line. (When the
message says bootstrap, it means "while starting your QuickApp".)
At runtime (the QuickApp started, then something broke while it was
doing its job). Same shape — file, line, reason — but the QuickApp may keep
running. Watch for the last [DEBUG] line before the error: that's the
last thing that worked, and usually the best clue.
A minute of disciplined reading beats an hour of guessing: read the line number, look at that line, read the reason, and only then change something.
--checkflua can check your work without running it — syntax, --%% typos, and
APIs the HC3 no longer wants:
flua --check sunset_lamp_ui.lua
ok
Three useful outcomes:
ok — nothing wrong that a static check can see. Good, but it doesn't
run the code; runtime surprises are still possible.end) — named file and line, exit code
1. Exactly what a missing end looks like, before you waste a run:text
lamp.lua: error: syntax: lamp.lua:12: 'end' expected (to close 'function' at line 8) near <eof>
--%%instnat:true):text
lamp.lua: warning: unknown directive --%%instnat
Warnings don't stop anything — a misspelled directive is silently ignored
at runtime, which is precisely why --check exists.
Make flua --check a habit before long runs; it catches the cheap mistakes
for free.
Logging gets you far. When you need to watch the code run line by line,
flua has a debugger, and chapter 01's setup already installed the pieces:
the Lua MobDebug extension and the launch configuration
Flua: Debug Current File (mobdebug). Like all the F5 configurations it
runs your QA in the offline playground (--api local) — the same code you
were already running.
The flow:
F5 (choose the mobdebug
configuration the first time — it starts flua and waits).F10), line by line,
watching n count up, sunsetMin appear, the if decide.The same launch configuration has a sibling, Flua: Debug Current File (UI+mobdebug) — same debugger, plus the viewer on port 8090, so you can debug while clicking the UI.
If no debugger answers, flua shrugs and runs the QA anyway:
Could not connect to localhost:8172: Connection refused
so a stray --debugger never hangs you.
The one trick that beats everything else: when something misbehaves, make it smaller until it works, then add pieces back.
print("fired").fibaro.getValue returns the wrong thing? Print it, and everything
around it:lua
self:debug("sunset hour is", fibaro.getValue(1, "sunsetHour"))
self:debug("auto is", tostring(self.properties.auto))
Programmers call this "the smallest case that fails" — and half the time, the act of shrinking finds the bug before the bug finds you.
When you've read the log, checked the file, and shrunk the problem — and it's still wrong — ask. Two places work well:
flua --check reports
problems with file and line, and the flua repository ships AGENTS.md
plus Copilot instructions — so an agent working inside the project
already knows the house rules. Let the agent run flua --check and the
QA itself: it can read the errors faster than you can copy them.Whatever you ask and wherever — run this first and paste the block:
flua doctor
It prints your setup as one ready-made block (which flua, which Python, whether your HC3 credentials are found and reachable, which editor pieces are in place). It never prints your passwords — only where it found things. "Here is my flua doctor" beats three paragraphs of setup prose, and often the ✗ lines in it are the answer.
A question that gets answered — by a human or an agent — includes three things:
That's it. You now have the whole loop: write, run, read, fix — and a lamp that has been on your real HC3 since last chapter. The rest is practice.