Best Presence detection

@tpmcleod24 I’m not sure how rikoshak’s script works because I’ve never use it, but it seems that you are executing the wrong file. The python script that you are trying to execute is in your “/opt/sensorReporter” folder, and the file called sensorReporter that is located at the “/opt/sensorReporter/config” folder is a bash file, so you should simply launch it with “sudo ./sensorReporter sensorRepoter.ini”. But this last sentense wont’ work because there is no .ini file in the “/opt/sensorRepoter/config” folder, the .ini file must be located at “/opt/sensorReporter”. I hope that you are understanding what I’m trying to tell you :wink:

Let’s see what Rich has to say!

I had an idea but not sure how it can be done. A few people mentioned using iBeacons to improve the accuracy of owntracks. Looking into this I found a way to build some ibeacons using cheap HM-10 Bluetooth modules and I thought that was quite good.

But I then realized this really requires the phone to be on and with you all the time and was thinking of another idea.

My question is can iBeacons report back to the openhab server the presence detection of a Bluetooth keyfob (rather than a phone)? I might be conceptually talking about creating a bluetooth mesh network, I don’t know exactly though. Would this only be possible using a HM-17 (BLE 4.1) or using a HM-10 connected to an ESP8266 that would send messages back via MQTT be an alternative option?

I figure if I have 3 quite cheap iBeacons in each room I should confidently be able to know which room someone was in and build rules accordingly.

This might be what I’m looking for. It is called Happy Bubbles, Only looks recent as in the last couple of weeks.

They have some server software to configure BLE devices and the detectors seem to bu built with an ESP or a NodeMCU and a PTR5518.

The iBeacons do not report to anything. They periodically broadcast a BLE “advertisement” that identifies the specific beacon. Some other device, like a phone or a Happy Bubble, receives the advertisement and does something with the information. In the case of OwnTracks, the phone receives beacon advertisements and the software publishes beacon information to MQTT.

So you could have fixed beacons and someone with a phone will receive the advertisements from those beacons as they pass and then relay the beacon info to some other system like openHAB via MQTT. You could also have several statically located beacon receivers, like Happy Bubbles, in various locations and have them receive advertisements from a beacon (for example, in a keyfob or a phone configured as a beacon). Yet another possibility is to have mobile beacons and mobile beacon receivers. I have an iBeacon in my car and my phone will notify openHAB (via OwnTracks) any time I’m in my car wherever the car may be at the time.

I wonder if it would be possible to adapt what is done in FIND with triangulation of the signal, only using BT. The advantage there is that one could move the detector of the signals off of the phone and on to stationary BT sensors reporting on the signal strength from the user’s phones or other BT device.

To put another way, install BT sensors which detect and report on the signal strength of BT devices as they move through the home. Then apply FIND’s triangulation algorithm using those signal strengths reported from the BT sensors. This would not require anything to run on the phone and therefore would work cross platform. Of course it requires setting up the BT sensors across the home.

1 Like

Im using whis code instaled on Tomato router to track users via WIFI.
It works on any phone, android Nexus 5 in my case.

#!/bin/sh
OHIPPORT="192.168.0.212:8081"
function fcomp() {
    awk -v n1=$1 -v n2=$2 'BEGIN{ if (n1<n2) exit 0; exit 1}'
}

RET=`brctl showmacs br0|grep $1`
if [ "$RET" = "" ]
then
echo 'FAIL'
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
else
ATIME=`echo $RET | awk '{print $4}'`
echo $ATIME
if fcomp $ATIME 200; then
echo "OK"
curl --header "Content-Type: text/plain" --request PUT --data "ON" http://$OHIPPORT/rest/items/$2/state
else
echo "EXP"
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
fi
fi


Phone must periodicaly contact to the internet (eg. mail/whatsup check), this is normal in out times.

Execution:

maccheck.sh mirek 00:00:00:00:00

where:
mirek - is the name of switch that represents person in openhab (need to be declared in items)
00:00:00:00:00 - is the mac address of phone

Add this script to cron to be run in every minute:

cru a " * * * * * maccheck.sh mirek 00:00:00:00:00"

1 Like

Silly question @ksiezykmirek, but where in the Tomato interface should I place this code?

You will have to login via ssh to tomato router, use Putty or similar terminal software.

Hmm, I know how to do that, but not the custom scripting. I’ll have to go away and have a look for a guide.

I’m assuming:

cru a " * * * * * maccheck.sh **name** 00:00:00:00:00"

is saved is a crontabs file somewhere

And,

#!/bin/sh
OHIPPORT="192.168.0.212:8081"
function fcomp() {
    awk -v n1=$1 -v n2=$2 'BEGIN{ if (n1<n2) exit 0; exit 1}'
}

RET=`brctl showmacs br0|grep $1`
if [ "$RET" = "" ]
then
echo 'FAIL'
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
else
ATIME=`echo $RET | awk '{print $4}'`
echo $ATIME
if fcomp $ATIME 200; then
echo "OK"
curl --header "Content-Type: text/plain" --request PUT --data "ON" http://$OHIPPORT/rest/items/$2/state
else
echo "EXP"
curl --header "Content-Type: text/plain" --request PUT --data "OFF" http://$OHIPPORT/rest/items/$2/state
fi
fi

is saved as maccheck.sh in somewhere like /tmp/home

But how does the cron job know where the .sh file to run is located?

And then i’m still unsure where maccheck.sh **name** 00:00:00:00:00 gets called; from the init section of the router?

Will see what I can find online.

Cheers.

In your case it will be:
cru a " * * * * * /tmp/home/maccheck.sh name 00:00:00:00:00"

Be sure that:
Chmod 755 /tmp/hone/maccheck.sh

I have found problem in this linę:

Grep is case sensitive, do the -i parameter need to be add before $1. Otherwise macs has to have all small cases.

Next update:
CRU (cron) list is lost on reboot, so in need to be addet to init script like this:

cru a mirek “* * * * " "/jffs/maccheck.sh xx:xx:xx:xx:xx:xx mirek"
cru a ania "
* * * *” “/jffs/maccheck.sh yy:yy:yy:yy:yy:yy ania”

Great idea, it’s working well for me. Just sharing a few notes from issues I ran into getting it set up on my router.

My version of Tomato doesn’t have bash, and /bin/sh is symlinked to busybox ash. This causes an issue with the “function fcomp()” line (syntax error on the function), so just trim it to “fcomp()” and that will work.

Second issue I had was with your execution. Originally you listed maccheck.sh [switch name] [MAC address] as the syntax, but it’s actually expecting maccheck.sh [MAC address] [switch name]. Not a big deal, just might be confusing if someone is reading along at home.

Thanks again for the great idea!

Very true words about basic security.
Allow me to chip in on the lighter side:
there is a great (dutch) TV commercial of an insurance company that shows a guy giving a lecture on home automation. And just as he enthusiastically is telling how he can control his home from his phone, burglars show up at his house. At that moment the guy is showing the crowd how he can open his garagedoor and put a spotlight on his prized vintage car… anyway, you get the picture.

You are very right saying in the end it is just about how much risc you are willing to accept. Though I am basically in favor of even being able to switch on my toaster via my phone, I still rely on just a traditional lock on my doors. No WiFi, RFID or what have ya there

1 Like

I feel like I should put this script i worked on a while back here. Uses a simple scan to detect and keep your presence but uses bluetooth authentication if you’ve been away. This fixes an issue with spamming authentication as that screws up both the server and the phone and eventually at least one will need a restart.

1 Like

This thread hasn’t seen a lot of activity… but since I think it’s still a resource for new openHAB users looking to set up presence detection, I want to point out a new method of detection for iPhone users. Bear in mind that you’ll need to modify the example rules a bit if you want presence switches, but it shouldn’t be too complicated.

3 Likes

I am working on a JSR223 lib for presence detection that is (when finished) intended to use a varity of technologies to detect Presence. Right now i am in an early state, where I have done a lot of thinking and written som pseudo code.

My intention is to provide a Python library that can use some or all of these technolgies:

  • Wifi (connected, RSSI, Roaming between AP)
  • Bluetooth Proximity
  • Presence service (like OwnTracks)
  • Sensors (Door contacts, PIR Sensors, Cameras etc.)

The idea is that each person can be configured to use a different/individual technology to identify Presence.
My idea with the unpersonalized sensors is to use those as an indicator that there is somebody there. The personalized “sensors” like Wifi, Owntracks will be used to calculate a probability of whom it may be.

I am also considering a mechanishm where a specific series of events can be used; For instance

  1. Pir Sensor in hallway is activated
  2. Frontdoor is opened
  3. Bluetooth in car is seen by Bluetooth scanner
  4. Time is between 6:30 - 7:30 in the morning

At my place this means (>90%): Wife is leaving for work.

That was just some initial thoughts. i have started a POC to see what needs to be done. :slight_smile:

5 Likes

Do you plan your python library to be able to work distributed over multiple nodes?
Does Bluetooth Proximity include BTLE devices?

Yes, For me this is exactly the same as Wifi, it can have multiple nodes (Access Points).
The problem is that it shouldn’t be too complex to setup, then it is useless in my opinion.

You should think of this library as a library that works with data that is already in openHAB (via items and/or things/channels).

It would be great to include the Wasp in the Box algorithm into this library as well. That would round out the features nicely.

1 Like