Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Home Center automatically check your presence at home


Tony270570

Question

The objective of this functionality is to determine that your are at home based on your phone connexion to your wifi network and use that information on your Home Center for example to switch off your alarm automatically when you are in and switch it On when you are out...

Most of phones are impossible to be easily found as soon as they are on sleeping mode; therefore a simple ping won’t work.

I’ve done this workaround with the help of a raspberry and fing which is a free powerful network tool that can be run on most of platforms.

The plus of this solution is that it's working on HC lite because there is no LUA or virtual device necessary, works with iPhones with recent IOS version even when wifi looks to be off when device is sleeping and no extra application to be installed, tasker on android is not needed for this purpose , and it's complient with all phones that i had the chance to test: iPhones, Androids, windows phone; it's absolutly transparent, no need to wake up your device, just do nothing

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" /> .. !

prerequisite: You must have a server running permanently ( a raspberry or a nas server ...)

Step 1

In the HC create a variable in this example “Presence”with two values “Present” and “Absent”.

If you decide to change the name don’t forget to amend the file named "test_presence.sh" that we are going to talk about on step 7.

Step 2

Install Fing in your server, the command will differ depending on your unix distribution.

In my case a debian on my RPI I used the following:

Please login or register to see this code.

Test that is ok and try:

Sudo Fing

If all is all right you can jump to step 4 else go to next step.

Step 3

If fing don’t execute it’s probably because some libraries are missing or obsolete in this case try the following command:

Please login or register to see this code.

Step 4

In /etc edit the file rc.local add the following command and save :

Please login or register to see this code.

If necessary adapt the network mask in my case 192.168.1.0 is the first IP address fing will start scanning (it will scan your entire network starting by this IP)

Step 5

In /var/www create a new directory called “ping” in order to have this result:

Please login or register to see this code.

Step 6

In /home create a new directory and name it as you want (in my case tony) we will use it on step 7 & 8

Step 7

Create a file "test_presence.sh" and copy the code find below. IPDUSERVEUR must be set with your phone address.

Change user/mot with your HC user/pass and IP with your HC ip address.

Copy that file on the directory that you have created in step 6

Step 8

Create a file « exec_presence »and copy the code find below, change the directory name with the name craeated in step 6 :

/home/XXXXX (/home/tony in my case)

Copy the script « exec_presence » into /etc/init.d. Make sure grants are ok on that file:

Please login or register to see this code.

and execute following command (might change depending on your unix) :

Please login or register to see this code.

(it will allow the scipt to be automatically execute at after the boot)

On your browser try 192.168.X.X/ping/lan.html (where 192.168.X.X is the ip of your server where ping is running). You should see a page with all your network connections.

Check the variable on your HC is correctly reflecting your presence.

For the very first run (only after the server boot) your phone should be in wake up mode to be correctly identified, after it becomes transparent. You can disconnect/reconnect your phone from your network, put it on sleeping mode and check all is all right.

creat a file named "exec_presence" and copy following code:

Please login or register to see this code.

creat a file named "test_presence.sh" and copy following code:

In this loop the sleep is set to 10 it's ok for test purpose but you could be set to 30 for normal run.

Please login or register to see this code.

Have fun.

Link to comment
Share on other sites

Recommended Posts

  • 0

Looks very nice! and much more usefull than the standard gps track option.

i'm going to try this out as soon as i have time for it

Link to comment
Share on other sites

  • 0

Nice concept, I know what to do this evening

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" />

Link to comment
Share on other sites

  • 0

This is very interesting indeed. Unfortunately, it isn't easy to install software on my nas, at least not software that's not available as standard package.

I wonder though, why Fing is so good at detecting devices. I've seen posts in the past about detecting home presence, it seems to be one of the hardest thing to define and test. I currently have my NAS ping my phones, and then use arp to determine if they are around. Even when ping fails, arp can see if a MAC address is still active on the wireless lan. It's not failsafe, but a little better than just ping. I wonder how my setup compares to Fing.

Also, the way you set global variables doesn't work in 4.020 Beta. I struggled with that, and ended up with

Please login or register to see this code.

$1 is the phone name, which is passed to the shell script containing the above line.

So that works. You can test with -v instead of -s to see the repsonse headers and such, for troubleshooting.

Next issue: my HC2 doesn't respond to global variable changes this way it seems. I have a scene that reacts to the global variables set by my NAS, but nothing happens when the value changes. Is that a know beta bug that I missed?

I used to have my NAS touch or rm a file, depending on the arp result, and then have a scene/virtual device button combo to check for the presence of the files, to determine what devices were around. Now I changed that to having NAS set global vars. Much cleaner that way. Shame that you can't set global vars with non-admin user though...

Anyway, great post, good to see something worth reading around here

Please login or register to see this image.

/emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi Hans!

    What a pity you can't install it, it's really reliable, till now never had any false result.

    I start thinking about fing, as i use it on my ipad and find it really usefull, having an iphone no way to Ping it, as it close all ports when the device get sleeping.

    It can detects me in 1 minute when i getting home, i didn't spend much time reading the doc but i think that it's possible to change the frequence.

    Thank's for your help about setting vars on 4.xx, i'm still in 3.590, and yes the way hc2 in v4 reacts with variables is quite strange, as it's ok with the version i run.

    @Sve and sjek13 thank you and keep me informed

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0

    started today installing this, but i run a windows server.

    i installed fing but on the windows server i can't find /ect and /home folders

    i found this on fing websitte:

    on Windows they are placed in your application data folder: %APPDATA%\Overlook\Fing\conf.

    but there i can't find the rc.local file

    do you have any idea how this works on windows?

    thanks

    Link to comment
    Share on other sites

    • 0

    If you used a fixed routing table, it is as simple as sending a TCP-package with a timeout. If the request times out, the device is not on the network, if the response is a denied response, the device is on the network. This will work just as well as what Fing does (Fing also occationally misses some when trying to detect the different devices.

    I use a simple virtual device just to prove the concept (I don't use it as I don't lug my phone around everywhere anyway). The VD pulls the IPs from my server where the routing table is also stored and then sends a "test" package to the devices that I have marked as presence devices in the routing table (A MySQL table which leeches data from the network using a separate script). If the devices respond - even with a 403 or similar, I know that it is because they are present on the network, but have closed the port I test. This works almost flawlessly - only niggle is the way that iPhones close down their wifi connection to preserve battery life - but that will be the same no matter how you try to do this. If the device doesn't respond then it is because it isn't there. So just check the error code of the response. If the code is 408 or 404, the device isn't present - anything else, and it must mean that the device is there, but it just doesn't want to talk to you.

    However, to work around the issue with the iDevices not being on the network constantly, I have rewritten my script to log the last time of presence for any of my devices - then based on that, it can turn down the heat, activate my presence simulator, activate the alarm etc. All of this however is something I run on a separate server, rather than in a virtual device/scene on the Fibaro as it is becoming increasingly unreliable.

    Link to comment
    Share on other sites

    • 0

    hey,

    i have updated this to be used for Mac OS X plus launchd

    1. Update: I have a DHCP server running, so my IP addresses change. Thus I'm not looking for the iPhone's IP address but for its MAC address. The code for this looks like this:

    Please login or register to see this code.

    As can be seen I have also changed this code from a neverending loop. My script is being called every 60 seconds from a launchdaemon

    Update: because of the update below, the script is now called every 300 sec (5 min)

    2. Next I have opened a second launchdaemon (using lingon and LaunchControl on OS X) to call the fing command. The plist file looks like this:

    Please login or register to see this code.

    Here I also made some small change: -r 1 instead of 10 (I have the LaunchDaemon run every 60 seconds anyway, so I don't have to have fing run 10 times.

    Update: it seems as if -r 1 (so: one round only) is too little. in this case a sleeping phone is not detected. so i increased it to -r 5

    So far it has been working fine.

    Thanks to Tony for all the great work.

    My next project is to look for all of our phones in the house and arm the alarm automatically once everyone is out of the house.

    Link to comment
    Share on other sites

    • 0

    I have got it working, except the hc2 presence stuff. I'm using HC2 4.023 BETA and according to HansS the URl has changed in this version, but i have no clue how to change the script.

    HansS, can I have the complete test_presence.sh script you have changed ?

    Link to comment
    Share on other sites

    • 0

    I'm not actually using the script as posted here. I did change the script I was using because this post gave me some ideas how to simplify it. I think the main difference in URI is that you have to include the variable name when using beta. Also, if the password contains any special characters, you have to urlencode it. You can change the curl options to display output so you can see what's going on.

    Link to comment
    Share on other sites

    • 0
    Guest Grupawrc

    HI HansS, i have done like you descibe , but the variable doesnt change in HC2. Do you have any idea what can be wrong. I have error

    {"type":"ERROR","reason":"name","message":"No variable name in uri"}Present

    Link to comment
    Share on other sites

    • 0

    This Approach sounds very interesting, since we can't ping iPhones if they are in "standby" mode. I tryed fing for several days but it doesn't work steadily - even if the iPhone lies next to my accesspoint

    Please login or register to see this image.

    /emoticons/default_icon_cry.gif" alt=":cry:" />

    Still searching another way to detect my presence at home. Hopping the new sense.se mother API will get us the ability to interact with the HC2

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" />

    Link to comment
    Share on other sites

    • 0

    Grupawrc,

    The API call has changed. So put the same data, but change the URI to also include the variable name. So not this:

    Please login or register to see this code.

    But this:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
    Guest Grupawrc

    HansS, thank you for help. Now its ok with working with the fibaro, but the script dosen't start automatickly....do you have any idea whats wrong ?

    Link to comment
    Share on other sites

    • 0

    Looking great this way, although i don't have raspberry. Maybe in future will test this some time.

    Love those solutions people make :->

    For now I'm using a ping to android phone's of me and my girlfriend.

    Both Android I have rooted and run wifi adb app that only run and connects when i'm in the house and on my wifi SSID of the router.

    Only you have to keep wifi active, but that's no problem when i'm in own house.

    Tested a few weeks, works for me now, only issue is when you are away and run into your house (while it's raining for example) it's got a delay to see phone. But that's ok for now.

    Link to comment
    Share on other sites

    • 0
    HansS, thank you for help. Now its ok with working with the fibaro, but the script dosen't start automatickly....do you have any idea whats wrong ?

    If I had to guess, I'd say you're setting global variables through curl, and have a scene on Fibaro that reacts on the variable value. If so, that's not going to work. The Fibaro engine doesn't trigger scenes when a global variable is changed by these remote calls.

    What I did was create a virtual device with several buttons (person x home, person x away), and used curl to press the buttons instead of changing variables. What's probably better is to fire off the scene you want by calling the sceneactivation from curl. Maybe you should do both, set global variables, and when you set one, fire off a scene that checks the values and reacts to them.

    As a side note, I started using Estimote beacons for presence detection. Looks like that's a better way to determine if someone's around more accurately. I use Geofency to check for location (gps) and also my beacons. Geofency performs HTTPS calls when I enter or exit a certain area, and when I get close to one of my beacons. These secure calls go to my NAS, which calls an internal page that records the event in a database, and then presses a button on a virtual device (sort of a reverse proxy configuration). Geofency sends data in JSON format (which area or beacon, what device is calling), which is entered in the database. The virtual device does a NAS php page call, which reads the json from the database, and can react to the event.

    I tried Geofancy, which is free, but it seems the notification on success/error doesn't work in that app. Also, Geofency (2 or 3 euros I think) allows you to test each location or beacon configuration, and can show the reply or error.

    So for presence detection, this seems to work much better. I have three beacons, and thought I would also be able to detect indoor location, but with just Geofency that doesn't work very well. Beacons on the first floor are detected intermittently also when moving around the ground floor. So I'm looking at the Indoor Location Services API from Estimote now.

    Link to comment
    Share on other sites

    • 0
    Guest Grupawrc

    HansS, could you sent me the virtual device to import do my hc2 ?

    Link to comment
    Share on other sites

    • 0
    I tried Geofancy, which is free, but it seems the notification on success/error doesn't work in that app. Also, Geofency (2 or 3 euros I think) allows you to test each location or beacon configuration, and can show the reply or error.

    Witch app are you using for GPS- and iBeacon-Location? Geofancy or another one? I'm not able to run a scene from Geofancy... I always get the error code 405

    Please login or register to see this image.

    /emoticons/default_icon_neutral.gif" alt=":-|" /> Basic auth is active...

    Link to comment
    Share on other sites

    • 0
    Guest Grupawrc

    HansS, when I wrote that the script doesnt work I mean that on script which start automaticly on rasberry pi. I have to start it by "hand" do you have anu idea whata can be wrong ?

    Link to comment
    Share on other sites

    • 0

    Hmm, ok. Once again, I have to state that I'm not running the script that was posted by the OP. The way I have automated my 'ping' is using the cron of my NAS. It executes a shell script every minute. The shell script does a ping, then runs arp to check for the MAC, if the MAC is present, it does the curl to press a VD button. So the key to automating this is running the shell script every minute through cron. If your script has to be manually executed, I'd say it's missing the cron part. Again, this is the way I use it, check the OP's original post on how it was intended in this case.

    I use Geofency for the proximity app (not Geofancy, note the slight difference in name). Geofancy is the free app, the one I use is Geofency, which costs a couple of euros/dollars. With the latter, you can setup an web hook, and also test that specific web hook. If something is wrong, you can tell by the output that the app will display.

    Meanwhile, I've bee tweaking my setup. I now have several ways to detect presence, all based on the proximity of my iOS device. So it's the ping/mac one,the gps proximity and the proximity to any of my beacons. Each event sets a global variable for that specific situation (I'm inside my home GPS circle, my phone is pingable and so present, I'm near one of my beacons). I have a scene that monitors each of these global variables. It adds up all the values, and if it's greater than 0, I'm definitely at home. If it's 0, then I'm definitely not.

    So my code looks something like this:

    Please login or register to see this code.

    Hans_Home is the ping check. Geo_Hans_Home is the gps location check, performed by Geofency. THe other three are beacon proximities, also performed by Geofency. Total is the sum of the value of all these. If it's greater than 0, I'm detected in at least one of the methods, so it's sure I'm (well, my iOS device) home. If it's zero, I'm not detectable in any way, so I'm pretty sure I'm not at home (never drain your Iphone battery!

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />)

    Untill now, I've been playing around with events. I just added two scenes using this new detection. They will turn on the Hue lights when someone's home and the light drops below 2 lux in the living room, and they will turn on the Hue lights if someone comes home, the light is low, and no one else is home. Let's see what happens

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" /> [/code]

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...