Got a reply
There was a temporary problem which we fixed, and the site is usable again as usual.
The web page seems to be working again.
but I have noticed for sometime now an increasing unreliability of the service
M
Got a reply
There was a temporary problem which we fixed, and the site is usable again as usual.
The web page seems to be working again.
but I have noticed for sometime now an increasing unreliability of the service
M
Now it works fine
Hey Mark, do I have to use Javascript transformation?
I use it for temperature, etc.
yes, i use js regex transfomation.
I impoved the error handling to stop my log filling up when the internet is not available or the mobile alerts server is having problems.
First step was to move the HTTP updating of items from the items definitions and into a new rule file.
From this
Number MobileAlertsTHSensorTemperature "Bedroom [%.1f °C]" <temperature> (gMobileAlertsInsideTemperature) //{ http="<[sensorCache:300020:JS(getTHSensorTemperature.js)]" }
I just // commented it out for now.
To this:
item
String MobileAlertsHTTPCache "Mobile-Alerts HTTP cache" <text> { http="<[sensorCache:300000:REGEX((.*))]" } // cache checked every 5mins.
rule trigger
Item MobileAlertsHTTPCache received update
items updated in rule
newval = transform("JS", "getTHSensorTemperature.js", MobileAlertsHTTPCache.state.toString)
MobileAlertsTHSensorTemperature.sendCommand(newval)
Now thats done I can apply conditions to the rule before the items are updated.
I check if the cache contains my phone number, as it normally does, before running the items updates eg if server times out etc and I use try + catch to catch exceptions etc when the HTTP binding fails. eg no internet access ( I believe this might be fixed in a new bdining for OH3)
Like this:
val String errorcheck = transform("JS", "checkCache.js", MobileAlertsHTTPCache.state.toString)
if (errorcheck == 'Phone ID 123456789') {
........item update code
}
else {
logError("Error", "Mobile-Alerts HTTP cache has no phone ID")
logError("Error", " Mobile-Alerts cache = " + MobileAlertsHTTPCache.state.toString)
}
Transform for this is:
(function(i) {
var re = new RegExp('(Phone ID 123456789)');
var out = i.match(re)[1];
return out;
})(input)
In the case when there is no internet connection, eg router reboot, I enclose all the rule code with :
try {
........all code
}
catch(Throwable t) {
logError("Error", "Mobile-Alerts HTTP cache rule error = " + T.toString)
}
I do the same for the API method rule and catch the exceptions and check if API return is normal, only this time looking for the string “sucess” message in the returned API
if (errorcheck == '"success": true') {
Transform:
(function(i) {
var re = new RegExp('(\"success\": true)');
var out = i.match(re)[1];
return out;
})(input)
Notes:
I am not sure if parseFloat(out) is really needed as used previously in the transforms for extracting temperatures etc but it will cause a problems when extracting strings with NaN returned. So, its just return out.
Results:
Router reboot test:
API
2020-10-17 09:40:47.927 [ERROR] [eclipse.smarthome.model.script.Error] - Mobile-Alerts API success check failed
I also log the curl output even if there is an error to see what is in there when it errors and will turn this off later.
HTTP binding
2020-10-17 09:38:53.309 [ERROR] [org.openhab.io.net.http.HttpUtil ] - Fatal transport error: java.net.UnknownHostException: measurements.mobile-alerts.eu
2020-10-17 09:38:53.311 [ERROR] [ab.binding.http.internal.HttpBinding] - No response received from 'sensorCache'
Hey Mark,
thank you,
Can you post aour regex?
Hey Mark,
this sounds good and usefull.
I will try it next days,
I already posted a lot of examples. I have about 50 js files but they are mostly very similiar.
What is it you want to extract?
M
Hey Mark,
I want to extract the battery level - battery status.
Then you just need to look for “lowbattery”:true in the API return Should be easy. For the regex you will need to escape \ the quotes "
Personally I find checking timestamps better and it works for all devices not just the pro ones. The low battery status doesn’t seem reliable anyway. I use NiMh rechargeables.
So, I check how long its been since the timestamp was last updated and send a notification if its longer than a few hours since the last time a device was seen. That way I am not running around changing batteries when there is no need to and I can also be made aware of any wifi signal strength issues and as I said it works with API and HTPP caching, so for all devices pro and non pro.
Hey Mark,
I installed openhab 3 on raspberry but I didn´t get Mobile Alerts working.
Did you still try on Openhab 3?
Hi, yes it’s working. If I remember correctly the only change was the exec command is formatted a bit differently… oh and update the whitelist, maybe I played around with the file permissions…775… I got the both Api and http methods working. Timestamp calculations were a pain and I posted about that in the oh3 time conversion thread. Got those working too in the end.
Thanks, but where can I find your changes?
The timestamp changes are here:
Anything else I did I haven’t posted.
Actually, I just looked and there wasn’t much I changed for the API method to work in OH3. Just changing the use of now to now.toInstant().toEpochMilli() in my rules.
The bit about the commandline command I mentioned above doesn’t affect the API method as thats run from the exec addon Thing
Hallo,
Singe wendsday mobile alerts didn‘t Work at Openhab 3. Does anyone also have problems?
Working in OH2.5. I only have OH3 as a test setup but that’s powered off at the moment.
Finally got back to looking at OH3 >>>> update on to to get at mobile alerts sensor data for OH3
as the http binding no longer works for caching the sensor page. It generates a forbidden 403 error in the log!
To fix that the caching needs to be done using curl command. Here is what needs to be changed >>>>
curl https://measurements.mobile-alerts.eu/Home/SensorsOverview?phoneid=xxxxxx -A Mozilla
Thing exec:command:mobilealertsHTTP "MobileAlerts HTTP" [command="/etc/openhab/scripts/Mobile-Alerts_HTTP.sh", interval=300, timeout=30]
String MobileAlertsHTTPCache "Mobile-Alerts HTTP cache" <text> { channel="exec:command:mobilealertsHTTP:output" }
The rules should now work as before.
sorry, I post on:
maybe somone can help
regards
Marco
Did you see my post above?
Try this.