Locator app with rest Api

Hi,
I made some changes to the app, one is the new parameter in Rest Api menu that can set the number of retries after stopping sending backhome command to the server, cause some users reported that 4 retries (that was the fixed value) could be insufficient, so now it’s possible to set a value from 1 to 10.
Another change is in the log procedure that now is more detailed and I fixed a bug that in some cases did not report all the connection rows in backhome procedure.
Please, test it and send me a feedback,
Thanks,
Nicola

1 Like

Hi

I think I’ve finally managed to put the correct information into the right places :slight_smile:

So now I’ve seen this in the log ----

So I have to assume that the https://home.myopenhab.org external URL works :slight_smile:

 13-04-2019 19:01:44 - trying connecting local Url: http://192.168.178.42:8080
13-04-2019 19:01:46:/rest/items/Stu_Presence - Error local Url does not reply:  java.net.SocketTimeoutException: timeout
13-04-2019 19:01:46 - trying with Remote
Remote Url: https://home.myopenhab.org
13-04-2019 19:01:47 - connection Ok,/rest/items/Stu_Presence set to: ON
13-04-2019 19:01:46 - trying connecting local Url: http://192.168.178.42:8080
13-04-2019 19:01:48:/rest/items/Stu_Presence - Error local Url does not reply:  java.net.SocketTimeoutException: timeout
13-04-2019 19:01:48 - trying with Remote
Remote Url: https://home.myopenhab.org
13-04-2019 19:01:49 - connection Ok,/rest/items/Stu_Presence set to: ON

Hi Stuart,
yes it seems to work, I didn’t tried it cause I don’t use myopenhab.org
You can check it, if you didn’t yet, putting the switch Stu_Presence in your sitemap.
Moreover, it’s better to put the same switch in persistence, if you use one. It will prevent to assume a wrong value when, for example you have to restart openhab.

Hey Nicola

I’m happy to report that EVERYTHING is working well now.

I don’t use BasicUI, but HabPanel is showing the status of the items.

I’ve added the Item into my presence rules now too.

My aim is to achieve the following.

When everyone has left the property, OH activates the house alarm AND checks that we’ve remembered to lock the doors & close the windows.

(I have tiny microswitches in the door lock striker plates that the lock mechanism/s press against)

If we’ve (read “I’ve”) forgotten to lock the doors fully, OH will send us all an SMS and a OH cloud notification.

Hi Stuart, to do this, you can use Telegram binding instead of send an SMS. I used it to do something similar and works very well!

:slight_smile:

Thanks.

The openHAB2 cloud notifications work, ‘when’ my phone wakes up it’s internet connection.

I’ve noticed that any Push notifications only work when my phone (Samsung S7) feels like being awake enough to connect to the internet.

However, the GSM side tends to be awake most of the time.

I’ve got the SMS I/O with OH2 nailed now :slight_smile:

Building an SMS gateway for openHAB (on Linux)

I have a tiny rule in OH that watches for a state change of the “Return Home” item, waits 10 seconds and turns it to OFF.

(I’ve migrated the rule to NodeRed, just because I can adjust the time delay on the fly)

Yes i agree, that would be a very nice feature and would make it easy to react for example with rules to the current position of the smartphone-user.

In my opinion it should work similar to the AlarmClock-Feature. The App should frequently update a string-Item that contains the coordinates of the GPS-Position (or just the position estimated by the mobile network). Perhaps the string could be compatible for example to the NMEA-2000-format.

Is there anyone currently working on a feature like this?

Best,

flashbanger

Hi, I’m using this app and, after many tests to put the right values inside the settings now it works very well!
I have only an issue: all the members of the family have the app installed on the phone so when we come back home together the scenario Rest Api Back Home in the Rest Api Setting fires many times.
Is there a way to avoid it?
Thanks

Have you tried setting up seperate Items for each member of your family?

Or, can you group the items and run the Rule when the Group switch changes to ON ?

Thank you very much for the reply!
I’m sorry but I saw that I didn’t explain the question in the right way.
I’ll try to explain my problem better. I wrote a rule that opens my gate when I’m near it using the Rest Api Back Home function in the app and it works very well when I or another member of my family comes back alone but, when we come back together with 2 or more phones, the app of each phone starts the rule and, cause my gate accepts only one command for open, close and stop I obtain that the gate opening starts but it stops after few seconds because another phone sends the same command.
It happens only when we come back together and reading the log it was confirmed because more than one phone sends the same command.
Thanks

Oh I see.

So you can’t simply use a group, because you need the next returning person (if not together) to also trigger the rule.

So really, you need a way to limit the amount of triggers per minute ?

I’m not sure how that’s done, but is that the kind of rate limit you’re thinking of?

In my very rough approach, I’d add a variable or state Item that locks out repeat actions for a period of time.

So a rule might trigger and first check the state of a ‘trigger lock’. ???

If you wanted a really dirty solution, you could put the rule to sleep using a thread::sleep(5000) command, but there are thread issues to consider.

@eanderson280

I think you have more options to solve this issue.
One quick and dirty it’s to use the expire binding using an item like this:

Switch wd_comeback {expire=“2m,command=OFF”}

this is a kind of watchdog that you can use to watch if someone fired the rule before.

In the rule you can write something like this:

rule “backhome”
when
Item scenariobackhome received command ON
then
if (wd_comeback==OFF)
{
sendCommand(wd_comeback,ON)
####
#### SEND YOUR COMMAND FOR GATE OPENING
}
end

In this case only the first phone can send the command because it switch ON the wd_comeback and the condition to send the command is not satisfied for another. After 2 minutes (that I think it’s enough), the wd_comeback switch turns automatically OFF.

Another more “scientific” but more impactful option is to use a contact sensor to test the status of the gate instead of the wd_comeback switch.
Hope it helps…

2 Likes

Thanks, I hadn’t worked out how that binding functioned.

this is the contents of the Items file that I got working.

Switch Expire_2_Min "Expires after 2 minutes" { expire="2m,command=OFF" }                                                                                                                                                                             
                                                                                                                                                                                                                                                  
Switch Expire_30_Sec "Expires after 30 seconds" { expire="30s,command=OFF" }

@eanderson280

Do these suggestions make sense and will they help you resolve your issue?

@MDAR @hangloose
Thanks a lot for your suggestions, I will try.
Bye

1 Like

Additional options are documented in Design Pattern: Rule Latching

1 Like

Thank you very much.
It works very well!!!

1 Like

Hello hangloose,
I changed the smartphone reinstalled everything with the same parameters and now the app no longer works.
The new smartphone is a Galaxy S10 Plus.
The old smartphone with the same parameters works without no issues.
Can you help me, please?
Thanks!

Hi Elan,
could you post the log file, please?
Thanks

Sure,
I think that this is the error:
11-06-2020 16:49:50:/rest/items/backhome - Cleartext HTTP traffic not permitted: failed to connect to /xxxxx (port 8080) from /xxxxx
Thanks a lot