Markdown source

# CM3-home - OpenHAB getting started 

During the development and test phases of the [CM3-Home]((, the **[Tanzolab Group](** wrote many practical articles about the different interfaces used on the board, reporting links, experiences and suggestions acknowledged meanwhile. In this article they are collected in order to achieve a "real world" tutorials archive about using CM3-Home with [OpenHAB](

* [CM3-Home features](
* [CM3-Home schematic (c) Acme Systems srl](
* [Report on Raspberry CM3 e CM3L modules](
* [Other Home Automation Software and board similar to CM3-Home](

##OpenHABian Installation
For a comprehensive tutorial about OpneHABian installation please follow the instructions on the [official web site](

[Basic installation download on RPI and compatible boards](

*ATTENTION* all the installation procedures are really long lasting, please be patient.

Once installed OpenHABian following the instructions, you need to proceed with customizations and add-ons installation.

Many operations are eased using the OpenHABian environment equivalent to raspi-config.
<pre class="terminal">
sudo openhabian-config

The CM3-Home serial ports must be prepared to be used in OpenHAB, freeing them from standard use:

* 30 | System Setting
	* 35 | Serial Port 
		* [*] 1  (RPi) Disable serial console 
        * [*] 2  (RPi3) Disable Bluetooth module
		* [*] 3  Add common serial ports to openHAB JVM 
use menu items according to your needs

* 30 | System Setting
	* to change password, host name, WiFi, etc.
* 01 | Update
* 02 | Upgrade System
* 20 | Install optional add-ons
	* Mosquitto
	* Grafana
	* knxd

In order to verify the configuration you can use the karaf console. Let's take the knx binding as an example.

<pre class="terminal">
[12:44:08] openhabian@RasPIguiott:~$ ssh -p 8101 openhab@localhost
Password authentication

                          __  _____    ____      
  ____  ____  ___  ____  / / / /   |  / __ )     
 / __ \/ __ \/ _ \/ __ \/ /_/ / /| | / __  | 
/ /_/ / /_/ /  __/ / / / __  / ___ |/ /_/ /      
\____/ .___/\___/_/ /_/_/ /_/_/  |_/_____/     
    /_/                        2.1.0
                               - release build -   

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab> config:list "("
Pid:            org.openhab.knx
BundleLocation: mvn:org.openhab.binding/org.openhab.binding.knx/1.10.0
   localIp = localhost = org.openhab.knx
   type = ROUTER

In case of problems it can be useful to increase debug level to check for possible configuration errors:

<pre class="terminal">
openhab> log:set debug

or enable the trace

<pre class="terminal">
log:set TRACE org.openhab.binding.knx
log:set TRACE

It is advisable to disable them when the debug is over:

<pre class="terminal">
log:set DEFAULT org.openhab.binding.knx
log:set DEFAULT

All the useful information can be read in:

<pre class="terminal">

Or with the console command 

or in the browser:

The configuration is dynamically loaded as soon as the cfg file is saved (/etc/openhab2/services/knx.cfg in the example). 
It could happen that the previous configurations are cached even at service restart. In that case clean up the cache before restarting the service:

<pre class="terminal">
openhab> config:delete org.openhab.knx

openhabian@RasPIguiott:~$ sudo systemctl restart openhab2

There are some little differences between CM3-Home and Raspberry PI 3 because of the greater hardware equipment. A comprehensive guide to all the peripherals and how to use them, can be found at [CM3-Home main page](

To use all of the available hardware you have to:

* Assign the serial debug port (UART1) to GPIO32-GPIO33 instead of GPIO14-GPIO15
* [Assign the RGB LED GPIOs ](
* Change the audio PWM GPIOs
* Assign the 1-wire line
* Assign the IR reciver port to GPIO 20
* If needed, assign the J3 socket to SPI display
* Set up the I2C port
* Avoid to wait for HDMI device attached at boot (save more than 10sec at startup)

To do that, the following instructions must be added to the /boot/config.txt file:

<pre class="terminal">
#Serial port to GPIO 32 and 33

#CM3-Home led definition

#Enable PWM on GPIO 40 and 41 for the audio out

# Enable the 1-wire bus

#Enable the IR Linux driver

#dtoverlay=ads7846,cs=0,penirq=34,speed=10000, swapxy=0, pmax=255, xohms=60, xmin=200, xmax=3900, ymin=200, ymax=3900

#I2C on Grove socket

#Avoid waiting for HDMI device attached at boot (save more than 10sec at startup)

Take a look also at [Create a Raspbian Stretch microSD]( article.

To assign system functions to RGB LED you must create an overlay [Using this tutorial](

the already prepared overlays are available:

* [dts](./cm3-home-leds.dts)
* [dtbo](cm3-home-leds.dtbo)

To redirect the system console to the debug port you must edit also the file /boot/cmdline.txt adding the related instructions:

<pre class="terminal">
dwc_otg.lpm_enable=0 enable_uart=1 dtoverlay=pi3-disable-bt console=serial1,115200 root=PARTUUID=75a5cf8a-02 rootfstype=ext4 elevator=deadline rootwait

##Integration with directly attachable hardware interfaces examples

* [KNX integration via TPUART (TP-Bus)](
The open source [knxd]( service is used for this purpose. The demon has a permanent handshake with TPUART, it starts with discovery and proced with a periodic heartbeat. The KNX circuitry and TPUART itself are powered up by the external bus. In order to guarantee the correct operation, the KNX bus must be connected and powered before starting the CM3-Home.
* Two possible utilizations for the available RS485 interfaces
	* [Modbus](
	* [DMX-512](
* In the case below, the opto-isolated inputs and the relays are driven through the OpenHAB GPIO binding. This binding has be written for the OpenHAB 1, the OpenHAB 2 compatibility could create some problems, please follow the [official documentations](
    * [GPIO](
    * [GPIO example](
* [Execute command line operations](
* [DALI (Light-bus)](
* As an example for the serial port, a simple connection with an Arduino board has been used as an example.
	* [Serial binding configuration](
	* [GSM/GPRS communication](
	* Please verify that the openhab user is included in dialout group.

<pre class="terminal">
sudo usermod -a -G dialout openhab openhabian
* [1-wire connection example using a temperature sensor](
* [Using the CM3-Home internal IR receiver with an IR remote control](
* [Notes on LIRC, another way to use a standard remote control with IR receiver](
* [Using the audio out](
* [SPI display on J3](
* [Using the internal YARM D21 module](
* [Using the CM3-Home FULL analog input](

##Integration with services available through WiFi or LAN

* [Using MQTT with OpenHAB](
* [SONOFF TH16 integration tests](
* [SONOFF code examples](
* [Telegram integration](
* [IKEA Tradfri lamps integration](
* [Weather binding configuration example](
* [Widgets management in OpenHab](
* [How to realize dinamyc charts with OpenHAB items](
* [Controlling appliances through IR communication using Broadlink RM mini 3](
* [Measuring environment parameters with Netatmo sensors](
* [Manage the internet router](
* [Amazon Dash Buttons integration](

##Automatic configurations backup
[How to setup backup procedures](

##Setting-up WiFi module as an Access Point

For the details follow the [Andrea Montefusco presentation](

After hostapd service has been installed, the automatic startup of the service must be disabled and managed through /etc/rc.local so that each service will be launched only when the device is ready.  The dhcpcd service as well must be disabled. So, add the following instructions to rc.local:

<pre class="terminal">
# WiFi module AP mode, bridge configuration with eth0 and uap0(wlan)

echo 37 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio37/direction                                   
echo 1 > /sys/class/gpio/gpio37/value

sleep 1

ifup eth0
ifconfig eth0 up


rfkill list

ifup wlan0
ifconfig wlan0 up


brctl addbr br0
brctl addif br0 eth0

ifconfig br0 up

sleep 1

ifup br0

sleep 1

route add -net gw

iw dev wlan0 interface add uap0 type __ap
ifup uap0

hostapd /etc/hostapd/hostapd.conf &

exit 0

Add the following instructions to /etc/dhcpcd.conf configuration file if a static IP is needed:

<pre class="terminal">
interface eth0
static ip_address=
static routers=
static domain_name_servers=

<a name="cloud"></a>
## Mobile App

To use all the CM3-Home OpenHAB features on mobile devices even when not in the same domestic network, it can be used the open cloud service offered by [OpenHAB]( and the corresponding app available for both  [iOS]( and [Android](

After installing the openHAB Cloud Connector  

<img src="./OHcloud.png" class="img-responsive center-block" width="40%"/>

the following files will be available:

<pre class="terminal">

The files content is needed to setup the cloud service. A complete tutorial about installation and configuration is available on [Youtube](

The same functions available on local UI can be used also on mobile device once connected with the cloud service.

<img src="./AppOH.png" class="img-responsive center-block" width="25%"/>

## Display
How to use an external, dedicated [panel display]( to interact with CM3-Home through HABpanel UI.


how to launch the HABpanel at startup.

In the display user home directory configuration file:
<pre class="terminal">


<pre class="terminal">
chromium-browser --kiosk

with the CM3-Home IP address.

To disable screen saver and cursor in the browser, in file

<pre class="terminal">

un-comment the Xserver line es add the needed parameters:

<pre class="terminal">
xserver-command=X -s 0 -dpms -nocursor

[To disable the low battery icon](

add the instruction avoid_warnings=1 at /boot/config.txt