PulseSensor – openHAB configuration
openHAB
The PulseSensor bundle running on the Eclipse Kura™ platform of our Natrix Gateway communicates via MQTT with an openHAB3 instance which is also running on our Gateway. The purpose of this integration is to leverage the UI capabilities of openHAB3 to bring some PulseSensor data and information to the user via a webpage or a mobile app. On this app we want to implement an Alarm notification to signal that the pulse of a person doesn’t comply with a given setting (compliance range). While the calculation/determination of a pulse to be in/out a certain compliance range happens within the PulseSensor bundle logic, the visualization of the Alarm happens in two places: The Alarm LED on the breadboard and via a Switch-Item of the openHAB GUI. In order to control the Switch-Item in openHAB3, we send an Alarm ON/OFF notification to a predefined MQTT topic in openHAB3. The PulseSensor bundle subscribes for the same topic to get informed whenever an Alarm is raised or deleted. Based on this notification, it controls the Alarm LED on the breadboard. To react on a MQTT topic change gives us the ability to control the Alarm LED via the Switch-Item, embedded in the openHAB3 GUI. With this design pattern we are able to control LED settings remotely via the openHAB3 GUI, which is a smart thing to do so.
Overview about the openHAB configuration
Here is an overview about the Things which needs to be created, the Items which we have to generate as Thing channels, and the semantic model which we will assign the Things to.

openHAB MQTT Broker
An essential component for MQTT communication is the MQTT Broker.
For now, we do not implement any cybersecurity measures such as authentication or even data encryption. How to do this is explained in Hardening the Natrix Gateway, and we will add those measures at a later stage of the project.
We already installed the MQTT Broker binding, so we are fine to right jump into its configuration. And this is quite simple.
On the left-hand side menu, select [Things]->[‘+’ sign on the bottom right] and choose the binding we want to associate our new thing with.


This binding allows us several different things to do, so to add a MQTT broker as ‘bridge’. Or to just add a generic or Broker specific MQTT thing. We go for adding a MQTT Broker connection (to our Mosquitto Broker on the system) as abridge within openHAB3.

We let the broker listening on the localhost interface (127.0.0.1) which is OK for the purpose of our PulseSensor project. We want to make it flexible for being demonstrated in various different environments and settings, so everything which we need to change based upon new IP addresses our eth0 and/or wlan0 interface receives in those environments does cause additional effort end includes additional risks.
Actually, we only need to configure the IP-address 127.0.0.1 and give the Broker a name. Everything beside this we leave the default values.

openHAB MQTT Thing
The next Thing which we need to add is a generic MQTT thing which represents the PulseSensor as such.
We give it a name and assign it to the just created MQTT Broker bridge.

Both Things the MQTT Broker bridge and the MQTT Generic thing shall be ‘Online’ now.

openHAB PulseSensor Switch
We visualize the Alarm notification with a ‘Switch’. Purpose for this is that we not only want to notify the end user about the Alarm status by showing a specific switch-state, we can also control the Alarm status on our board with this Switch. Means, we can e.g. reset an Alarm by simply changing the switch-state in our GUI.
To add a Switch as a channel to our MQTT Generic thing, , we select [Thing] ->[PulseSensorMQTT_Thing]->[Channels]-[Add Channel].
Identifier: Switch_PulseSensorMQTT_Alarm
Label: Switch for PulseSensor Alarm notification

Select the ‘On/Off Switch option and provide the following configuration for the Topic Management of this MQTT thing:
MQTT State topic: /cmnd/pulsesensor/Alarm
MQTT Command Topic: /stat/pulsesensor/Alarm
Custom on/Open Value: ON
Custom off/Closed Value: OFF
The MQTT state topic is where the Switch Item is subscribing for to receive notifications from the PulseSensor bundle to control the Alarm status in the openHAB3 GUI.
The MQTT Command topic is the topic where the Switch Item is publishing to in case the user changed the Switch state manually on the GUI. The PulseSensor bundle is subscribing for this topic in order to control the Alarm LED on the board accordingly.

From here we can design our new Switch Item. Let’s define the name of the Switch and assign it to the ‘Switch’ category.
Now we have to link the Switch via a channel to the MQTT Generic thing which we created previously.
Click on the just created Switch item and add the channel link.
The PulseSensor semantic model
According to our Design Pattern for openHAB Semantics, we create the following semantical schema for our PulseSensor project.

Adding a Location
With [Add Location] we add a Location with the name ‘Loc_DemoLab’ which shall host all of our Maker projects. For the specific one here, we add an additional location ‘Loc_PulseSensorDemo’, which is part of the ‘LOC_DemoLab’ location.
Adding an Equipment
With [Create Equipment from Thing] we select the Thing which want to create as Equipment under the ‘Loc_PulseSensor_Demo’ location group.

We need to select at least one channel which we wish to create as new Point item. The newly created Point will be linked to its respective channels.We need to select at least one channel which we wish to create as new Point item. The newly created Point will be linked to its respective channels.

By doing this, we are finished to create our model for our PulseSensor representation within openHAB3.

Creating the user interface
For visualization purposes of our PulseSensor measured data we go with Sitemaps. Sitemaps are comprised out of simple controls which are defined in configuration files with a special textual syntax.
We go for Sitemaps as they can be rendered in the openHAB iOS and Android App. This is not the case for other GUI elements such HABPanels, Layout pages, etc also offered by openHAB3.
The layout of the sitemap which we will create for the PulseSensor App consists out of 6 layers where we present the
- Sitemap title
- Natrix-Project logo
- The PulseSensor switch which shows Alarm on/off
- Live Measurement – Raw data Grafana panel
- Live Measurement – BPM value (discrete) Grafana panel
- Live Measurement – BPM value (speedometer) Grafana panel

Getting the links to the Grafana panels
In preparation for creating the sitemap we require the http-link for each of the Grafana panels. To obtain those is a pretty simple deal. We click on the menu-item of each panel, go to [Share], disable the switch [Lock Time range] and copy the [Link URL].

We need to adapt the link which we get for the panel in a way that we disable the side-bar menu by adding a parameter at the end o the URL. The parameter is “&kiosk=1”.
Example is:
http://<Your-server-IP>:3000/d/_JoPsbK7z/pulsesensor-metrics-data?orgId=1&viewPanel=4&kiosk=1
Designing the Sitemap
For creating the Sitemap, we go into our openHAB console, [Administration]->[Settings]->[Pages] and with the ‘+’ sign on the bottom right we create a new sitemap.
Although it is possible to use the graphical user interface in the Administration web page to design the Sitemap, we recommend doing it on code level. We switch to the ‘Code’ tab and paste the following sitemap code into it:
sitemap PulseSensor2 label="Natrix Maker-Project: PulseSensor" {
Frame {
Image url="http://192.168.188.31:8080/static/pulsesensor/Pulsesensor-App-2.jpg"
}
Frame {
Switch item=PulseSensorMQTTThing_SwitchforPulseSensorAlarmnotification label="PulseSensorAlarm"
}
Frame {
Webview url="http://192.168.188.52:3000/d/_JoPsbK7z/pulsesensor-metrics-data?orgId=1&refresh=5m&viewPanel=2&kiosk=1" label="Pulse" height=7
}
Frame {
Webview url="http://192.168.188.52:3000/d/_JoPsbK7z/pulsesensor-metrics-data?orgId=1&from=1635954276787&to=1635954396787&viewPanel=14&kiosk=1" label="Pulse" height=7
}
Frame {
Webview url="http://192.168.188.52:3000/d/EnESBLF7z/dashboard-mini-panels?orgId=1&from=1635921111555&to=1635942711555&viewPanel=2&kiosk=1" label="Pulse" height=7
}
}
The body starts with the element ‘Sitemap’, followed with the identifier and the label (name) of the Sitemap.
sitemap PulseSensor2 label="Natrix Maker-Project: PulseSensor" {
}
The logo is loaded in an Image control as a jpg-image from the folder ‘/etc/openhab/html/pulsesensor’
Frame {
Image url="http://192.168.188.31:8080/static/pulsesensor/Pulsesensor-App-2.jpg"
}
Sitemap Frame for the Alarm switch
The Alarm switch is loaded as a Switch control which represents the ‘PulseSensorMQTTThing_SwitchforPulseSensorAlarmnotification’ item which we already created.
Frame {
Image url="http://192.168.188.31:8080/static/pulsesensor/Pulsesensor-App-2.jpg"
}
Sitemap Frame for the Live Measurement – Raw data
We utilize the ‘WebView’ control to load the Live Measurement – Raw data panel from Grafana
Frame {
Webview url="http://192.168.188.52:3000/d/_JoPsbK7z/pulsesensor-metrics-data?orgId=1&refresh=5m&viewPanel=2&kiosk=1" label="Pulse" height=7
}
Sitemap Frame for the Live Measurement – BPM (discrete)
We utilize the ‘WebView’ control to load the Live Measurement – BPM (discrete) data panel from Grafana
Frame {
Webview url="http://192.168.188.52:3000/d/_JoPsbK7z/pulsesensor-metrics-data?orgId=1&refresh=5m&viewPanel=2&kiosk=1" label="Pulse" height=7
}
Sitemap Frame for the Live Measurement – BPM (speedometer)
We utilize the ‘WebView’ control to load the Live Measurement – BPM (speedometer) data panel from Grafana
Frame {
Webview url="http://192.168.188.52:3000/d/EnESBLF7z/dashboard-mini-panels?orgId=1&from=1635921111555&to=1635942711555&viewPanel=2&kiosk=1" label="Pulse" height=7
}
openHAB checks in real-time the correctness of the syntax and let’s us save the Sitemap design.

The openHAB App
The openHAB App can be downloaded from the respective App-Stores of Google or Apple. The only thing we need to configure is the ‘local URL’ to our openhab server which is basically ‘http://<Your-server-ip>:8080’
Once we have done this, and the App could successfully connect to the openHAB server instance running on our Natrix Gateway, we see our PulseSensor Sitemap
