03 · QuickApp anatomy

Now the real thing. In this chapter you meet the Sunset Lamp, learn the three ideas every QuickApp is built from, and click its switch in a browser — while the whole thing still runs safely on your computer.

What a QuickApp is

A QuickApp is a small program that lives on your HC3. Most of the time it does nothing. Then something happens — a button is pressed, a timer fires, a sensor reports — and the QuickApp wakes up, runs a few lines of code, and goes back to sleep.

That "something happens" has a name: an event. And the code that runs is an action. That's idea number one:

graph LR
  E["event<br/>(button pressed, timer, sensor…)"] --> A["action<br/>(your code)"]
  A --> S[("state<br/>(properties)")]
  S --> UI["the HC3 shows it: ON"]

The lamp we're about to build is tiny, but it has the full skeleton:

The Sunset Lamp

Create sunset_lamp.lua in your project (or use the repo's copy at examples/sunset_lamp.lua):

--%%name:SunsetLamp
--%%type:com.fibaro.binarySwitch

function QuickApp:onInit()
  self:debug("Sunset lamp ready")
end

function QuickApp:turnOn()
  self:updateProperty("value", true)
  print("Lamp on")
end

function QuickApp:turnOff()
  self:updateProperty("value", false)
  print("Lamp off")
end

Line by line:

How does flua know where the header ends? It doesn't need to — only --%% lines are header lines, everything else is code. (There is an -- --------------- EOH --------------- marker for the rare case where a QuickApp is embedded inside another file as a long string, so its header lines aren't read as the outer file's. Not needed here.)

That's the whole anatomy: onInit (start once), actions (react), properties (remember and show).

Run it — and click the switch

flua can serve the QuickApp's UI to a small viewer page, so you can click the buttons exactly like in the HC3 app. Press F5 with the Flua: Run Current File (UI) configuration (from the menu, or Run → Run Without Debugging and pick it). It starts the lamp and serves the viewer:

🚀 flua 0.1.x (Lua 5.4, Python 3.x), mode offline (sim HC3, real network)
flua: UI viewer on http://127.0.0.1:8090/ — open it in a browser
[04.10.2026][20:11:17][DEBUG  ][SunsetLamp5000]: Sunset lamp ready

(Under the hood that configuration runs flua --ui 8090 sunset_lamp.lua — run it in a terminal if you ever prefer that.)

Now open http://127.0.0.1:8090/ in a browser — flua serves the viewer page itself, from the flua package, with the address already filled in. Press Connect.

✅ You should see a panel titled SunsetLamp, with a red FALSE label and Turn On / Turn Off buttons.

You didn't write a single line about those buttons. flua added them because your QuickApp declared itself a binarySwitch — the HC3 does exactly the same: every switch gets On/Off controls and a state label for free. (That's why --%%type matters.)

Click Turn On.

✅ You should see two things: the label flips to a green TRUE, and your terminal logs Lamp on.

[04.10.2026][20:11:19][DEBUG  ][SunsetLamp5000]: Lamp on

Walk through what just happened, because it's the whole game:

  1. You clicked Turn On in the viewer.
  2. The viewer called your QuickApp's turnOn action.
  3. Your code wrote true into the value property.
  4. The state changed — and the label (the viewer reads the state) flipped.

On your real HC3 it would have been a finger in the Fibaro app, and the lamp would have been a light in your house. Everything else is identical.

Click Turn Off, then on again. Each click is one event, one action, one state change.

When you're done, stop the run with the red square (■) in VS Code's Run toolbar — the lamp runs until you stop it.

What did we just learn?

Next

The lamp switches when you want it to. Next chapter it learns to switch by itself — when the sun goes down. That needs a timer, and a tiny bit of astronomy the HC3 does for us.