Presence Detection Seems Too Hard

Right on Will!
Thanks Rich!

I forgot about WiFi on the watches. That should work pretty well. Good luck on the assignments! If you have any ideas for the diabetic stuff I’m more than willing to help out. I do think that this sort of thing is one of the hidden killer apps for home automation.

1 Like

Hi, sounds like you need to do more diagnosis from the OpenHAB/Moquitto side. From the CLI on your RPi (or whatever O/S you run OH / mosquitto on) can you run the following (or alter it to suit the topic if you changed it, the # is a wildcard)

mosquitto_sub -t openhab/vehicle/# -v

Watch the MQTT messages come in from the Wemos. From another CLI, tail your OpenHAB logs as the rules will output what’s happening also, eg:

tail -f /var/log/openhab2/openhab.log

(once everything is working ok, you can remove the logInfo() entries from the rules file if necessary)

1 Like

Someone told, to change the smartphone ip from dhcp to static. I did that and i changed the network thing from hostname “smartphone” to my new static ip. I did this in the router settings, smartphone is still in dhcp mode, but gets always the same ip from the router now.

But it still has the same behaviour.

In my router (fritzbox) i can see the phone online all the day. But with my openhab-network-binding it isn´t online some time later. The phone is still in the house, i think it switches to a deeper standby.

It is a android smartphone and wifi is set to “always on”, but that doesn´t help.

I can´t use the fritzbox binding, because i already use it for a second fritzbox and i only can configure it to work with one device.

So why told someone that static ip on the smartphone helped in this way?

(i´m on oh 2.5 latest snapshot)

1 Like

Did you also configure the Network binding Thing to use arping? arping is able to wake up the phone and will get a result from the phone (if it is present) even when the phone goes into a deep sleep and stops responding to pings.

arping is installed and network.cfg is configured.

But i made some tests and i saw, that i only can start arping with sudo.

Here is information about the arping-file:
arping

Do i have to change something? Or should i edit my sudoers file? There i already have some commands to execute without higher privilegs.

EDIT:

Arping is already inside my sudoers-file…

From the docs:

On Linux and MacOS elevated access permissions may be needed, for instance by making the executable a suid executable ( chmod u+s /usr/sbin/arping ). Just test the executable on the command line; if sudo is required, grant elevated permissions.

Isn´t this, what my sudoers file already does?

Or do i have to change the owner (or the group?) to the openhab-user?

I did this chmod already, but when i´m logged in on my linux shell with the user “debian”, i have to use sudo.

I can´t log in to the shell with root or openhab-user, this two users are only for executing programs i think?

My user for working on the shell is the user “debian”.

No, your sudoers file gives the openhab user permission to run the command using sudo. The command in the docs (chmod u+s /usr/sbin/arping) will elevate that one command to run as root without the need to run sudo.

Show the result of running ls -l /usr/sbin/arping.

Show the error when you run arping as user debian.

Here you are:
Screenshot_1

Screenshot_2

Without sudo it is in english: command not found

it’s really really hard to read screen grabs on my phone. Please paste the text into the post.

If it says command not found, use the full path to the command when you run it. /usr/sbin/arping

I am kinda basic when it comes to deeper programming, so i found a really simple solution.

Connect openhab to IFTTT,

Create a dummy switch for each person you want to detect presence for.

Create a trigger in ifftt for if you enter a certer GEO fence, send a command to openhab switch to turn on.
Create another trigger for when you leave the GEO fence to turn off switch

create a rule like so

  rule "Matt Home"
  when
        Item matt_home received command ON
  then
        insert your logic here
  end

rule "Matt Away"
  when
        Item matt_home received command OFF
  then
        insert your logic here
  end

Im sure this is frowned upon, but it works every time. I have advanced logic to tell me when my wife is nearly home, or if she is home and I am returning to let her know. See below:

  rule "Matt Coming Home"
  when
        Item matt_home received command ON
  then
        if (DummyAlarmOnSwitch_Switch.state == OFF) {

              if (SonosPlay1KitchenSpeakers_Control.state == PLAY) {
                    sendCommand(SonosPlay1KitchenSpeakers_Control,PAUSE)
                    KitchenEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')
                    BasementEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')
                    BedroomEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')
                    Thread::sleep(5700)
                    sendCommand(SonosPlay1KitchenSpeakers_Control,PLAY)

              } else { 

                          KitchenEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')
                          BasementEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')
                          BedroomEcho_Speak.sendCommand('A quick heads up. Matt is nearly home. He should arrive in about 5 minutes.')

              }
              
        } 
  end

  rule "Kayla Coming Home"
  when
        Item kayla_home received command ON
  then
        if (DummyAlarmOnSwitch_Switch.state == OFF) {

              if (SonosPlay1KitchenSpeakers_Control.state == PLAY) {
                    sendCommand(SonosPlay1KitchenSpeakers_Control,PAUSE)
                    KitchenEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')
                    BasementEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')
                    BedroomEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')
                    Thread::sleep(5700)
                    sendCommand(SonosPlay1KitchenSpeakers_Control,PLAY)

              } else { 

                          KitchenEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')
                          BasementEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')
                          BedroomEcho_Speak.sendCommand('A quick heads up. Kayla is nearly home. She should arrive in about 5 minutes.')

              }
              
        } 
  end

Without sudo and only the word “arping” it says command not found.

With sudo and only the word “arping” it tells me how to use arping (help text) with shortcuts and so on… So with sudo it is working.

Without sudo but with the whole path it shows the help text also, so this is working too.

This is currently disabled.

Most of us find IFTTT’s geolocation detection to be too slow for our use cases.

It’s not frowned upon, it just doesn’t work well enough for most of us.

A few comments on the Rule in case you want to improve it.

  • Don’t sleep for so long. It ties up a Rules thread and you only get five of them. A Rule should not run longer than a few hundred milliseconds. Use a Timer instead.

  • Put your Echo_Speak Items into a Group:String and you can send the command to the Group and it will be forwarded to all members of the Group.

  • You can combine the two Rules into one very easily.

  • always use the Item.sendCommand instead of the Action, why is explained in the docs.

  • fail fast, it leads to easier to read code

rule "Someone is coming home"
when
    Item matt_home received command ON or
    Item kayla_home received command ON
then
    if(DummyAlarmnSwitch_Switch.state != OFF) return;

    val person = triggeringItem.name.split("_").get(0)
    val pronoun = if(person == "matt") "he" else "she"
    val message = "A quick heads up. " +  person + " is nearly home. " + pronoun + " should arrive in about 5 minues."
    if(SonosPlay1KitchenSpeakers_Control.state == PLAY){
        SonosPlay1KitchenSpeakers_Control.sendCommand(PAUSE)
        createTimer(now.plusMillis(5700), [ | SonosPlay1KitchenSpeakers_Control.sendCommand(PLAY)
    }
    AllEcho_Speak.sendCommand(message)
end

The Python version of the above Rule would be something like (just typing this, likely contains typos):

from core.rules import rule
from core.triggers import when
from core.actions import ScriptExecution
from org.joda.time import DateTime

@rule("Someone came home")
@when("Item matt_home received command ON")
@when("Item kayla_home received command ON")
def comming_home(event):
    if items["DummyAlarmSwitch"] != OFF: return

    person = event.itemName.split('_')[0]
    message = "A quick heads up. {} is nearly home. {} should arrive in about 5 minutes.".format(person, "he" if person == "matt" else "she")

    if items["SonosPlayKitchenSpeakers_Control"] == PLAY:
        events.sendCommand("SonosPlayKitchenSpeakers_Control", "PAUSE")
        ScriptExecution.createTimer(DateTime.now().plusMillis(5700), lambda: events.sendCommand("SonosPlayKitchenSpeakers_Control", "PLAY")

    events.sendCommand("AllEcho_Speak", message)

Thanks Rich,

Appreciate the time you took to explain this to me :grinning:. I am always looking to improve my coding skill. You say ifttt connection is disabled? It’s working for me still?

Also, with groups is there a way to do that in paper UI?

I think he wanted to say. In the latest snapshots it is disabled?

My last answer was just before your last message, @rlkoshak

The key date is July 26, 2019. If you already had your items exposed to IFTTT before that date, then they would continue to receive commands from IFTTT. That’s why your IFTTT rules still work.

After that date, item updates to myopenhab.org were disabled, because updates were overloading our database. So if you look at myopenhab.org today, you’ll see that the status of your items hasn’t changed since July 26. And any devices that you’ve exposed since then will not show up at all.

Unfortunately, some folks tried to fix their cloud issues by deleting their items from myopenhab.org, only to find that the items wouldn’t be re-added. They’ll have to wait for the fix to get those items back. @digitaldan has been working on a solution, but there’s no ETA at this time (as far as I’m aware).

If you already had Items exposed to IFTTT I think the service is still working. But if not then you are prevented from exposing new Items to myopenhab.org and therefore to IFTTT for the time being.

It’s disabled at the myopenhab.org servers. People needlessly sharing all of their Items when they aren’t even using IFTTT is the root cause of all the performance and down time problems we experience on myopenhab.org. The maintainers have turned that off until they can find a fix.

Forget about sudo. Sudo is irrelevant for this. This is the only line that matters. The command isn’t in your path (which doesn’t matter) but you can successfully run it when you provide the full path. So now openHAB can run it too since you should have the full path to the command configured in the Network binding config.

Maybe it’s silly but limiting the number of elements in the cloud could not be a solution

Read this post for an explanation of the traffic generated by constant item updates:

Since item updates were disabled, I’m not aware of myopenhab crashing even one time (someone correct me if I’m wrong about that). So while there could be other contributing factors, it certainly feels like this short-term fix has done the job while a long-term solution is worked out.