When the lower floor of the house had to undergo major reconstruction, I developed a domotica system to couple push buttons in the wall to the lights. The intention was that all behaviour could be programmed in software, with possibilities to make smart behaviour. Also, I wanted to wire the buttons with thin wires, so that we could have a lot of buttons, without increasing the price and work too much. The house wiring is designed in a way that the whole domotica system can be replaced by an Eltako based system with pulse relays.

Used components

Design principles

The system is build around a Controllino Mega, which is an industry-grade PLC with 100% Arduino compatibility. This PLC has many inputs, which are used for the push buttons in the walls of the house and many outputs, that switch the lights in the house.

Some of the lights are switched by means of the relais built in in the Controllino, others use external relais.

The RS485 port of the Controllino is connected to a Wellpro WP8026ADAM, which adds 16 digital inputs for push buttons.

Since the long wires to the push buttons in the walls of the house may pick up disturbances for which the system may be sensitive, they are all galvanically seperated by optocouplers and a seperate power supply.


The ethernet port of the Controllino is connected to the home network, which allows the Controllino to cooperate with the home automation controller.

The software in the Controllino includes the MySensors Arduino library which handles the protocol between PLC and the home automation controller Domoticz. This implementation does not make use of the MySensors radio network. In MySensors terminology, the Controllino combines a gateway with sensors (the light switches) and actuators (the light relays) on board.

Domoticz is an application installed on a home server, previously on a NAS (Synology), currently on a Raspberry Pi, which logs events, and implements all smart behaviour.

The Controllino system is designed so that it is able to operate without network; this means that the buttons will operate the correct lights. However, smart behaviour like switching a light off after a certain time-out, is handled by Domoticz.

The software in the Controllino makes use of State Machines to organise the timing and multi-tasking. The Automaton library is a Reactive State Machine Framework for Arduino.


Elektrisch-schema-ingang.png Elektrisch-schema-uitgang.png

Prevention of rush-in current

To be written.


Prepared for mounting

Prepared for mounting

Before mounting

Before mounting

Mounted, testing the first connection

Mounted, testing the first connection

Partly connected

Partly connected

Code of the Controllino

The Arduino code handles all the Buttons and Relais, hence the abbreviation 'butenrel'. The system implements a MySensors gataway, hence the foldername 'msgwbutenrel'.

All code is in the folder: msgwbutenrel

Programming the Controllino

Debugging the Controllino is possible by connecting it to a PC with an USB cable, and using the Arduino IDE with the following parameters:

  • baud rate 115200
  • board: Controllino Mega


Using DHCP for IP assignment has the downside that the Arduino code in the ".ino" file is not even reached when the ethernet cable is not plugged in. Hence the system has static IP:

MySensors gateway

The mysensors code is based on https://github.com/mysensors/MySensors/tree/development/examples/GatewayW5100. It implements a gataway, and registers all relais as actuator nodes. The buttons are not known to the MySensors system.

The gateway always has node id 0.

State machine Relais


This node uses one automaton per relais to remember its state, and to make sure that a relais is not switched back on immediately after switching it off. This to prevent excessive rush-in currents which melds the relay contacts together.

The system waits a few ms between switching on different relays. This will prevent simultanous rush-in current for all relays.

Specific relais with a heavy rush-in current may wait extra long before switching on a 2nd time again to prevent the relais contacts to fuse.

Rush-in currents are highest for the 12V power supply modules that are used for the LED lights.

State machine NButton

This node uses one automaton per button for debouncing.

Only the relais states are made visible with the MySensors protocol, not the buttons. The relais can be operated by the MySensors protocol.

State machine Modbus

Atm-Modbus.png Atm-Modbus-Connectors.png

This state machine organises the communication in the Modbus protocol with the Wellpro WP8026ADAM.

Tags: domotica nodes