Mobile Alerts and openHAB 2

regex
httpbinding
mobilealerts
Tags: #<Tag:0x00007f51dad183e0> #<Tag:0x00007f51dad197e0> #<Tag:0x00007f51dad1ff00>

(Mark) #22

Hi Stefan,

I also have:

MA10100 Temperature sensor
MA10001 Temperature probe
MA10421 Temperature/Humidity station

I have them all in Openhab and charted with Grafana using either web page caching or API call and then using Regex to extract the relevant data. With the API you also get the low battery information and loss of connection.

I wish they did a barometer but they dont so now I am building one from RPi and sensor :slight_smile:

edit… Update I did build my barometer and it works great. Stepper motors drive the dials for pressure and rate of change. No need to tap this barometer to see which way its going :slight_smile: It sends data via MQTT to Openhab and then on to Influx and Grafana. In the meantime Mobile Alerts updated the app to accomodate a barometer. I have not yet seen it for sale.


(Stefan Müller) #23

Hey Mark,

sounds nice.

I haven’t checked the battery messages by now.
My last state of information was that the rest API only works on pro devices and not for the non pros?

Would you mind of sharing your sensor ids with me for testing purposes?


(Renderender) #24
Hi folks,

i've read and reread all post, but i don't get into it...
I have multiple MA-Sensors. I got one Sensor working - the first in the list by using


`sensorCache.url=http://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=xxx
sensorCache.updateInterval=60000`

But i don’t get the way to implement all the other sensors from the list…
Can anyone provide me a step by step tutorial for getting all Temp/Hum sensors to work?
(actually i don’t now where to put all the above listet codeings…)

THX

(Mark) #25

Hi, Sorry forgot about your question re sharing. What are the risks if any?

Also, I recently notified mobile alerts of an issue over the Christmas period. Non pro devices were not showing latest data in the App from 2 to 8am. Also, the sensor overview web page was unavailbale during this time. Later in the day the App caught up with the data. So, the data wasn’t lost but delayed. Annoying that the app and website both showed the last bit of the data in the history as the current data with the current time… even though it wasn’t.

Mobile alerts aknowledged there was an issue and have now said they have fixed it…

Maybe only I noticed it but in your charts you might see an unusually stable period in the early hours or even time slipped data.

ps Got my barometer built: Bosch sensor + MQTT for openhab input + stepper motor dials for fun display. RPi to the rescue again :slight_smile:


(Mark) #26

I wish I had the time but…

In a nutshell…cache the sensor page (and or use API call if you have pro devices) and the use transform file and regex to extract the data. I identify each sensor with its id. That way when I want to add a new sensor I just copy paste the regex and only need change the sensor id part for new sensors…


(Marc Durbach) #27

Hi, first of all I want to thank everybody for the good information in this thread.
I tried the examples but have encountered a problem.
I create an item that should display the status of 2 garage door contacts, the channels are defined like this

Group gGaragenDiiren
	"GaragenDiiren"
	(C_Garage)
String	garagenDiirAnnette
	"GaragenDiir Annette [%s]"
	(gGaragenDiiren)
	{ http="<[mobileAlerts:60000:JS(getGaragendiirAnnette.js)]" }
String garagenDiirMarc
	"GaragenDiir Marc [%s]"
	(gGaragenDiiren)
	{ http="<[mobileAlerts:60000:JS(getGaragendiirMarc.js)]" }

the problem is that i only get one item displayed, and where the second should be, I see de complete HTML code of the page.

The transformation is done like this

(function(i) {
	    var re = new RegExp('xxxxxxxxxx[\\s\\S]*?Contact Sensor[\\s\\S]*?<h4>([a-zA-Z]+)');
	    var out = i.match(re)[1];
	    return out;
})(input)

they are both identical, only the ID in the regex does change

Any ideas concerning this problem ? I also would like to find where the syntax of the channel line is documented, as I do not understand why it starts with a < tag


(Mark) #28

For testing that the regex works as expected I extracted the source code from sensor web page and then used one of the free regex test sites to test my expression. You may need to remove on the \ from double \ in your expression to work with the rest site.


(Mark) #29

Hi,

For those that are interested

I now have all Mobile Alert sensors as items in Opemhab and charted via Influx and Grafana. What was missing was some indication when a sensor had stopped working.

I could have used API call for the ‘Pro’ devices but wanted something that would work for ALL my devices. So, I used web caching (need HTTP binding for this) to extract each sensor time stamp and a rule to check the time since a sensor was last seen. It took quite a bit of work determining the best method to do the task and then more wok in getting the types correct.

Details are below:

Time stamp Item…
String HeatPumpReturnTemperatureTimestamp "Heat Pump return sensor time stamp [%s]" { http="<[sensorCache:60000:JS(getTimestamp.js)]" }

JS transform with REGEX to extract the time stamp…

(function(i) {
    var re = new RegExp('Sensor_ID_goes_here[\\s\\S]*?Timestamp[\\s\\S]*?<h4>([0-9]+/[0-9]+/[0-9]+ [0-9]+:[0-9]+:[0-9]+ [A|P]M)</h4>');
    var out = i.match(re)[1];
    return out;
})(input)

Rule to check when a sensor was last seen…

import java.text.SimpleDateFormat

rule "Heat pump return temperature time stamp check"
when
    Item HeatPumpReturnTemperatureTimestamp received update
then
    val String timestamp_str = HeatPumpReturnTemperatureTimestamp.state.toString //from http cache and REGEX transform

    val SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a")
    val DateTime timestamp = new DateTime(formatter.parse(timestamp_str))          
    val Number elapsedtime = (now.millis - timestamp.millis)/60000

    if (elapsedtime > 30) { // 30mins since last seen
        sendNotification('your email address','Heat pump return sensor not seen for  ' + elapsedtime + 'minutes')
        logInfo("Mobile Alerts" , "Time now = " + now)
        logInfo("Mobile Alerts" , "Heat pump return sensor time stamp = " + timestamp)
        logWarn("Mobile Alerts" , "Heat pump return sensor not seen for " + elapsedtime + " minutes")
    }
end

(Ansgar Honerkamp) #30

Hey Mark,
I tried to go your way. But it didn´t work.

My item:
Number MobileAlerts_Outside_Temperature “Temperatur Balkon [%.1f °C]” (mobilealerts) {http="<[mobileAlerts:60000:JS(getTemperatureout.js)]" }

My getTemperatureout.js
(function(i) {
var re = new RegExp(‘Sensor-ID[\s\S]?Temperature[\s\S]?

([0-9]+.[0-9]+) C’);
var out = i.match(re)[1];
return parseFloat(out);
})(input)

My addons.cfg:
transformation = javascript,map

My http.cfg:
mobileAlerts.url=http://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=XXXXXXXXX
mobileAlerts.updateInterval=60000

at HABpanel it only shows NULL

at Basic UI it only shows - °C

at paper UI - Transfomations I installed Javasript Transformation und Map Transformation.

with https://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=XXXXXXXXX all is shown correctly.

where did I made a mistake or what could missed?

Greetings, Ansgar


(Mark) #31

I see one problem so far

For checking regex on websites [\s\S] works but for Openhab it should be [\\s\\S]

Its easier to read if you enclose your posted in code in code fences. Button on far right after the smilie.

Any errors in the log?

Cheers Mark


(Ansgar Honerkamp) #32
(function(i) {
    var re = new RegExp('02512688AC27[\\s\\S]*?Temperature[\\s\\S]*?<h4>([0-9]+.[0-9]+) C');
    var out = i.match(re)[1];
    return parseFloat(out);
})(input)

Message at openhab.log:

org.openhab.core.transform.TransformationException: An error occurred while executing script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) ~[210:org.openhab.core.compat1x:2.4.0]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [246:org.openhab.binding.http:1.13.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [210:org.openhab.core.compat1x:2.4.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [210:org.openhab.core.compat1x:2.4.0]
2019-03-12 19:12:52.924 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation ‘JS(getTemperatureout.js)’ threw an exception. [response=


(Mark) #33

did you test the regex on the sensor web page? eg regex101. Goto sensor web page , view source and copy the code. Paste into regex101. The regex expression will need the double backslash changing to one backslash. You can play around with the regex and you should see it match something.


(Ansgar Honerkamp) #34

sorry, I not really expert.
Where can I test this?
where do i find regex101?


(Mark) #35

I am not an expert either. I just learnt enough to get the job done.

This will test if your regex is working as expected and returning a number.

Or post the html and I can try for you


(Mark) #36

I see a possible problem. The regex should have an OR condition | to allow for + and - temperatures :

<h4>([0-9]+.[0-9]+|-[0-9]+.[0-9]+) C'

Was the outside temperature minus C when you tested?


(Ansgar Honerkamp) #37

PROBLEM SOLVED!
now I use https: and not http: at http.cfg an I find the correct names at the *.js files.


(Ansgar Honerkamp) #38

Hey Mark,
I use the sensor: TEMPERATURSENSOR MIT WASSERDICHTER KABELSONDE (MA10101)
I tried to get the info “Trocken” or “Nass” with js-file.

Did everyone test it and can help?


(Ansgar Honerkamp) #39

Hello to everyone,
I found the solution for the sensor MA10101:

The item:

string		MobileAlerts_Indoor_Water	 				"Wassersensor Küche [%s]"										<water> 				(mobilealerts) 				{http="<[mobileAlerts:60000:JS(gettrockenin.js)]"}

Javascript:
(function(i) {
    var re = new RegExp('SENSOR-ID[\\s\\S]*?Wassersensor[\\s\\S]*?<h4>([a-zA-Z]+)');
    var out = i.match(re)[1];
    return out;
})(input)

Rule:
    rule "Wasser"
when
	Item MobileAlerts_Indoor_Water changed from Trocken to Feucht
then
	sendTelegram("BOT-Name", "Wasser!")
end