The goal of this example is to show you how to use different Mobile Alerts readings with openHAB 2.
Since I only have the “non-PRO” devices I can’t use the new Mobile Alerts REST Api. But nevertheless it is still possible to integrate also the normal devices via the website “measurements.mobile-alerts.eu”.
In this tutorial I will show you how to read the temperature, humidity and CO2 values of a Technoline WL 2000 device.
Prerequisites:
If not already done, please install the “HTTP Binding” and the “RegEx Transformation” service via the Paper UI.
Step One:
Add the following lines in http.cfg
in the folder services
. Please replace the xxx
with your phoneid from the Mobile Alerts App
mobileAlerts.url=http://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=xxx
mobileAlerts.updateInterval=300000
Because we want to read several parameters out of the returned HTML page I prefer to cache the page and
update it only once every 5 Minutes
The sensor data in the HTML file looks like:
…
<div class="sensor-component">
<h5>Zeitpunkt</h5>
<h4>28.01.2017 19:56:05</h4>
</div>
<div class="sensor-component">
<h5>Temperature Indoor</h5>
<h4>22,5 C</h4>
</div>
<div class="sensor-component">
<h5>Humidity Indoor</h5>
<h4>43%</h4>
</div>
<div class="sensor-component">
<h5>Air Quality</h5>
<h4>950 ppm</h4>
</div>
<div class="sensor-component">
<h5>Temperature Outdoor</h5>
<h4>-0,7 C</h4>
</div>
</div>
</div>
Unfortunatly the temperature data has a “,” instead of a “.” in the float value. We will have to transform that later.
Step Two:
Create a new or edit your existing items file and add the following items:
Number MobileAlerts_AirQuality "Air Quality[%d ppm]" { http="<[mobileAlerts:300000:REGEX(.*?([0-9]+) ppm.*)]" }
String MobileAlerts_Outside_TemperatureString "Outside Temperature [%s]" { http="<[mobileAlerts:300000:REGEX(.*?Temperature Outdoor.*?\\s.*?(-*[0-9]+,[0-9]+) C.*)]" }
Number MobileAlerts_Outside_Temperature "Outside Temperature [%.1f °C]"
String MobileAlerts_Indoor_TemperatureString "Indoor Temperature [%s]" { http="<[mobileAlerts:300000:REGEX(.*?Temperature Indoor.*?\\s.*?(-*[0-9]+,[0-9]+) C.*)]" }
Number MobileAlerts_Indoor_Temperature "Indoor Temperature [%.1f °C]"
Number MobileAlerts_Indoor_Humidity "Indoor Humidity [%d %%]" <humidity> (Raumklima, Wohnzimmer) {http="<[mobileAlerts:300000:REGEX(.*?Humidity Indoor.*?\\s.*?([0-9]+)%.*)]"}
Change in the REGEX the names of your readings to you’re defined names in Mobile Alerts. The items MobileAlerts_AirQuality
and MobileAlerts_Indoor_Humidity
will directly contain values you can work with. For the temperature we first have to save them in a String
item.
Step Three:
To convert the “,” to “.” in the temperature readings and save the values as numbers define two rules as follows:
rule "Convert MobileAlerts_Outside_TemperatureString to Float"
when
Item MobileAlerts_Outside_TemperatureString received update
then
var Number tempFloatOutside
tempFloatOutside=Float::parseFloat(String::format("%s",MobileAlerts_Outside_TemperatureString.state).replace(',','.'))
MobileAlerts_Outside_Temperature.postUpdate(tempFloatOutside)
end
rule "Convert MobileAlerts_Indoor_TemperatureString to Float"
when
Item MobileAlerts_Indoor_TemperatureString received update
then
var Number tempFloatIndoor
tempFloatOutside=Float::parseFloat(String::format("%s",MobileAlerts_Indoor_TemperatureString.state).replace(',','.'))
MobileAlerts_Indoor_Temperature.postUpdate(tempFloatIndoor)
end
That’s it. Now you can work with the four items MobileAlerts_AirQuality
, MobileAlerts_Outside_Temperature
, MobileAlerts_Indoor_Temperature
and MobileAlerts_Indoor_Humidity
as with every other item in openHAB.
Regards,
André