OpenHAB Configuration

Configurations


A brief description on the OpenHAB customization tools

CM3-Home Dashboard

Links on useful documentation, configuration pages and different GUIs are available at:

cm3-home.local:8080

How to edit customization files

The most recent and easy tool to manage OpenHAB configuration is Visual Studio Code. An explaination here about how to install and configure it to work with OpenHABian.

Install Visual Studio Code

Add OpenHAB extension

configure Visual Studio Code in this way

{
"openhab.host": "cm3home.local",
"openhab.port": 8080,
"openhab.lspEnabled": true,
"openhab.username": "openhabian",
"openhab.password": "openhabian",
"openhab.karafCommand": "ssh openhab@%openhabhost% -p 8101",
"files.autoSave": "off",
"openhab.username": "openhabian",
}

Mount the samba exported OpenHAB configuration folder. On MacOSX, for example:

⌘k
smb://cm3home.local
  • user: openhabian
  • password: openhabian

and add the folder to Visual Studio Code workspace.

Remind the shortcut keys available, first of all

⇧⌘P, F1 Show Command Palette

The workspace is now ready to edit all the configuration files

Widgets management in OpenHab


As an example will be described here the design of an habpanel for the Weather Binding.

On the contrary to the widget described in openhab_weather, in this example we don’t use the standard frame type widget. The HTML will be coded directly inside the widget itself, created as a custom widget. Because this web page is published by the OpenHAB internal web server, it is visible also through the cloud services. Using a frame widget that publishes an external web page instead, this one can be viewed only inside the same network.

The stilesheets and the icons come from the same openhab_weather widget folder using the relative path.

≤link rel="stylesheet" type="text/css" href="../static/weather-data/layouts/example.css" /≥
≤img src="../static/weather-data/images/{{IconSet}}/{{itemValue('Condition_ID1') | lowercase }}.png"/≥

Changing the IconSet=’directory’ with the desired icon set name, we can change the icon style for the whole widget.

It’s possible to change the language of the captions by changing the weather.cfg file. Verify the language supported by the provider used.

location.roma.language=IT

location.roma.language=EN

The language chosen affects only the binding items with the data taken from the provider. OpenHAB supports only English and German language for the rest of the text. For other languages we have to use other conversion systems like, for example, this one:

Define the conversion array:

≤div ng-init="daysnames={'Sunday': 'Domenica', 'Monday': 'Lunedì', 'Tuesday': 'Martedì', 'Wednesday': 'Mercoledì', 'Thursday': 'Giovedì', 'Friday': 'Venerdì', 'Saturday': 'Sabato'}; 

Then use the English name as the array index:

{{daysnames[(itemValue('ObservationTime1') | date:'EEEE')]}}

In order to have an automatic update of the displayed text when the values change, the system uses AngularJS. The text management and formatting must be applied using this language specific syntax.

To select automatically the icon corresponding to the weather condition we can use the Condition item modifying the name with some AngularJS code:

≤img src="../static/weather-data/images/{{IconSet}}/{{itemValue('Condition0').replace(' ','-') | lowercase }}.png"/≥

This works only if the chosen language is English. It’s better to use the CommonID item, it’s unique and matches the icons names:

≤img src="../static/weather-data/images/{{IconSet}}/{{itemValue('Condition_ID0')}}.png"/≥

And use instead the Condition item for the captions, it matches the chosen language:

≤p≥{{itemValue('Condition0')}}≤/p≥

To show other parameters we can use a mix of AngularJS and CSS:

≤td class="col-xs-4" style="color:red"≥{{'%.0f' | sprintf:itemValue('Temp_Max0')}} °C≤/td≥

CM3-home – OpenHABian set-up


Some advices on how to have an up and running installation of OpenHABian operating system on 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

Take a look also at this article  on how to create the SD card.

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.

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.

[12:44:08] openhabian@RasPIguiott:~$ ssh -p 8101 openhab@localhost
Password authentication
Password: 

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

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

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

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

openhab> log:set debug tuwien.auto.calimero

or enable the trace

log:set TRACE org.openhab.binding.knx
log:set TRACE tuwien.auto.calimero

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

log:set DEFAULT org.openhab.binding.knx
log:set DEFAULT tuwien.auto.calimero

All the useful information can be read in:

/var/log/openhab2/event
/var/log/openhab2/openhab.log

Or with the console command

log:tail

or in the browser:
cm3home.local:9001/

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:

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.

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:

dtoverlay=pi3-disable-bt

#Serial port to GPIO 32 and 33
force_turbo=1
dtoverlay=uart1,txd1_pin=32,rxd1_pin=33

#CM3-Home led definition
dtoverlay=cm3-home-leds

#Enable PWM on GPIO 40 and 41 for the audio out
dtoverlay=pwm-2chan,pin=40,func=4,pin2=41,func2=4

# Enable the 1-wire bus
dtoverlay=w1-gpio,gpiopin=16

#Enable the IR Linux driver
dtoverlay=lirc-rpi,gpio_in_pin=20

dtparam=spi=on
dtoverlay=rpi-display,speed=32000000,rotate=270
#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
#(https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/overlays/README#L783)
dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=400000
dtoverlay=i2c1-bcm2708,sda1_pin=44,scl1_pin=45,pin_func=6

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

To assign system functions to RGB LED you must create an overlay using the RGB led tutorial

To redirect the system console to the debug port you have to also edit the file /boot/cmdline.txt modifying ONLY the instruction related to the console, KEEPING INALTERED ALL THE REST.

Change:

console=serial0,115200 console=tty1

With:

enable_uart=1 console=serial1,115200

A dashboard with links to configuration panels and references is availbale at cm3-home.local:8080

Paper UI is the starting point for every installation and configuration.


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

the following files will be available:

/var/lib/openhab2/uuid
/var/lib/openhab2/openhabcloud/secret

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.

Links

Share