Presence Detection Seems Too Hard

Exactly, super cool idea but if I have to do something… is it really automation? :wink:
Not that I don’t admire how it works and gives me some cool ideas but I have bent over backwards to do something ‘automatically’ that I could just push a button or flip a switch to do. Humans are dumb, we get tired, excited or rushed and forget stuff,not to mention sometimes actually trying to ‘fool’ the automation system
Pretend scenario:
Daughter sneaks out with boyfriend late, leave audio jack plugged in, parents think she is home :laughing:

Haha no good :grin:

Real example:
When I moved in to my house, I took some time to update and tune up the security system. It had a bunch of dead batteries in sensors and missing keyfobs and things.

In doing that, I found a fun thing. For the door labelled “SONS BEDROOM”, someone (the son, presumably) had peeled the magnetic sensor off the door, and stuck it right to the reed switch next to the door. Suddenly, he could open that door without the alarm binging or going off! And his parents would never know.

So, yeah, people do things to avoid “automation” if they can.

Your life is MUCH harder if you assume you can’t trust your residents.

Willie, did you (or anyone else for that matter) get a chance to test the code on a Wemos D1 Mino Pro in your car? I assume someone must have one floating around. I’m still waiting for mine to turn up (from aliexpress, so a good week away still), so can’t test (with antenna) to see how well it functions. I’ll write a detailed instructable on how to setup once the better parts arrive.

Hi chimera,

Yes the code on the ESP works like a charm. 10 points for that. I can see via the flickering blue light what happens. I too ordered some ESP D1 Mini Pro’s from Banggood, but having shipping problems so it may be another two weeks before they arrive.

On the OH side it didn’t go to well. It is likely my fault/ignorance. I first tried to add the code to my config, that didn’t work as expected. I of course did substantial editing to replace your car make with my car make. (Maybe it will just be easier for me to buy a Ford Ranger :smile: )

I then removed the code again and tried to set it up as separate sitemap and that didn’t work either. I use MQTTv2 so I also tried to set it up in that manner but also no luck.

When I say it doesn’t work, I mean that the status doesn’t change it just shows a “-” line. I did see if I “flicked the switch” in Paper UI, the “-” changed to “Home”. But after a few days now of going in and out of the yard it hasn’t changed.

Unfortunatly I have assignments due next week, so I’m a bit hectic now. Will be able to give it my full attention after the 29th :grin:

I also still want to implement the Presence Detection as mentioned by Rich in the post using Apple Watches and my son’s Dexcom to depict people being home as opposed to a certain car being home. Those are two different use cases I have.

Chat soonest.

My wife has a Dexcom too (G6). You might also be interested in NightScout openHAB Integration (you can set up Nightscout as a follower to CLARITY so you don’t have to use xDrip or Spike to populate it I think). And I can confirm, at least with the G4 (I haven’t tested this in a long time) that the receiver shows up really well using reelyActive and other BT scanners (there is a not yet accepted BT binding that would probably work too) as Dexcom didn’t bother to spoof the BT address for privacy.

I should see how it works with the G6. I can probably inspect the broadcasts and see they are coming from a G6 sensor and don’t even need to worry about the fact that a new sensor needs to be inserted every 10 days (longer if you are using xDrip) potentially changing the broadcast source address.

As for the Apple Watch, you will be able to see that an Apple watch is present, but not that a specific watch is present. Apple is pretty good about privacy in this respect so the watch spoofs it’s BT address, changing it every few minutes. There might be something in the message that can uniquely identify the watch though, I haven’t looked. My wife quit her iPhone and Apple Watch when she decided to move to xDrip and Nightscout and I prefer Android.

NOTE: While Dexcom does offer an API to get the readings from CLARITY, they delay the data by 30 minutes making it almost useless for driving home automation. You can see my experiments there at OAuth2 using just OH Rules and myopenhab.org.

Thanks for the info Rich. Will dissect it next week in more detail. Yea been following the NightScout and OpenAPS for a while. very interesting stuff. Thanks for your links as well. There are certainly some possibilities to look into. Last night as an example, he went really low, and neither my wife or my phones alerted us. (One was flat and one was on silent for some reason, silly little Apple switch). Would have been nice if the house could have turned on every single light known to man. :slight_smile:

I was thinking of giving the Apple Watches static IP addresses and following them on Wifi rather than BT, but will see what works best. Thanks for all your comments and participation in the community. You have helped people more times that you will know :slight_smile:

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.