Presence Detection Seems Too Hard

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.

hi, is there a way we can run our own reciever to reduce the load on the MongoDB, or best to wait for the bigger solution, thanks for your assistance on this

Yep, there’s a way. This discussion has drifted off of the original topic of presence detection, so I’d suggest pursuing further conversation here:

Made an instructable for this. Must admit, I am still testing and tweaking it however, as only recently received Wemos with external antenna. Best effort if you’re interested, would be keen to see others experiences with this (very simple project)

1 Like

Nice article…
But I cant help wondering if a mobilphone couldnt do the same?

Yeah it could, but if you read my other posts earlier in this thread, this supplements existing presence detection methods. So until we have microchips implanted under our skin :slight_smile: I think presence detection is best determined by a combination of multiple devices and then adding smarts around those to calculate whether one or multiple people are home or not, as opposed to getting that information from a single device. Eg: drove away from home but left mobile on bench, or, went out for a walk and took mobile with you, both scenarios would have either mobile presence or vehicle presence alone failing.

1 Like

Agree totally…
Whenever I get the time to test this, I´ll add face detection for present detection. I´m just not convinced thats its working properly yet.

I’ve been testing my vehicle presence detection method for the past week and it has worked flawlessly identifying to OpenHAB whether my car is home or away (driving to or from home) often several times a day, so pretty happy with it so far. At the moment, I have it locking my front door when it detects the vehicle is away (in case I forget) and unlocking when getting home as well as turning on porch lights if it’s night time. Many other use cases for this too.

I had to tweak the settings in code however, so it now takes the average of 4 x RSSI signal samples every 500ms, plus there are other small changes to code to reduce the start up time of Wifi (as need to connect ASAP when the vehicle starts to ensure at least an initial connection) Seems pretty good so far, very interested if others could try and report back!