Skip to content

Chapter 3 · How Programming Works

Your First Logic

  • Lesson
  • 11 min

This is where it all comes together. You will build a real, working piece of logic from start to finish, test it without touching any hardware, and then solve a small challenge that teaches you something more important than the answer.

By the end of this lesson you will be able to:

  • Build a working switch program from an input to an output
  • Test a program in simulation with no Miniserver connected
  • Judge a good solution from a bad one

The situation

A room has a button and a light. The customer wants the button to control the light.

Later they want something slightly cleverer: press the button, and the light comes on by itself for ten seconds, then goes off. You are going to build both, and you are going to build them the clean way.

Build a simple switch

Start with the simplest complete program. The Switch block holds a state, and its inputs let you toggle it, switch it on, or switch it off.

  1. Create a programming page named Living Room, and set its Default Room to Living Room.
  2. Insert the Switch block onto the page and Rename everything to your choice
  3. Connect digital inputs to the block’s Tg, On and Off inputs. Tg toggles the state, On switches it on, and Off switches it off.
  4. In the properties of each digital input, set the display type to Switch, so the input behaves correctly in simulation.
  5. Connect a digital output, a relay, to the block’s O output.
  6. Start the simulation and test each input in turn. Check that the output responds each time.

Test it in simulation

In the properties of a digital input you can choose how it behaves in simulation: a push button, a switch, or a frequency. If no physical button is wired, LiveView with manual value change also lets you set the input yourself and watch the output react.

Build a piece of logic, simulate it, and watch it behave before it ever touches a real building.

The challenge

Now the small challenge that teaches the real lesson.

Pressing a button on input I1 should switch on the relay output Q1 for ten seconds, then switch it off automatically. The customer also wants to trigger the same function from the app.

Before reading on, think about how you would build it. There are many ways. Only one is best.

The best solution

The clean solution uses a single block: the Push Button block. When its trigger input receives a pulse, it keeps its output on for the time set in its Don parameter, then switches it off.

  1. Insert a Push Button block, and give it a name that says what it does.
  2. Connect the digital input I1 to the block’s trigger input.
  3. Connect the relay Q1 to the block’s output.
  4. Set the block’s Don parameter of the Push Button to 10 seconds.
  5. Assign the block to its room, so it appears in the right place in the app.
  6. Start the simulation, press the input, and check that the relay stays on for 10 seconds.

Because it is one block with the timing set by a parameter, the control in the app matches the function exactly, with nothing extra to explain.

Why that solution is the best one

The same behaviour could be built from several blocks with extra wiring. It would even work. But it would be harder to read, harder to fix, and it would often show up wrongly in the app.

A good solution has four qualities worth carrying into everything you build. It works as specified. Its logic is simple and clear. Its block settings are correct. And it is named for its function and assigned to a room.

A bad solution might still work, but with confusing logic, missing settings, no room assignment, and a view in the app that does not match what the logic really does.

Information

In LOXONE, working is not the same as good. The best solution is the clear one: one block where one block will do, timing set by a parameter, named for its function, assigned to its room. Clarity is what makes a project easy to fix a year later.

Takeaway

Your first program is an input, a block and an output, tested in simulation before it meets any hardware. When a task has many possible solutions, choose the clearest: one block where one will do, timing set by a parameter, named for its function and assigned to its room. In LOXONE, clear beats clever.

Apply What You've Learned

Quick self-check — ungraded. Just to be sure everything sticks.
Task

Build a switch, then solve the challenge

  1. Build the simple switch: a Switch block with inputs on Tg, On and Off, and a relay on O. Simulate and test it.
  2. Build the challenge: pressing I1 turns Q1 on for ten seconds, using a single Push Button block with Don set to 10 seconds.
  3. Name the block for its function and assign it to a room.
  4. Simulate it and confirm the ten second behaviour.